Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(633)

Side by Side Diff: experimental/Intersection/TriangleUtilities.cpp

Issue 867213004: remove prototype pathops code (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « experimental/Intersection/TriangleUtilities.h ('k') | experimental/Intersection/as.htm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2012 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include "TriangleUtilities.h"
9
10 // http://www.blackpawn.com/texts/pointinpoly/default.html
11 bool pointInTriangle(const Triangle& triangle, const _Point& pt) {
12 // Compute vectors
13 _Vector v0 = triangle[2] - triangle[0];
14 _Vector v1 = triangle[1] - triangle[0];
15 _Vector v2 = pt - triangle[0];
16
17 // Compute dot products
18 double dot00 = v0.dot(v0);
19 double dot01 = v0.dot(v1);
20 double dot02 = v0.dot(v2);
21 double dot11 = v1.dot(v1);
22 double dot12 = v1.dot(v2);
23
24 // Compute barycentric coordinates
25 double invDenom = 1 / (dot00 * dot11 - dot01 * dot01);
26 double u = (dot11 * dot02 - dot01 * dot12) * invDenom;
27 double v = (dot00 * dot12 - dot01 * dot02) * invDenom;
28
29 // Check if point is in triangle
30 return (u >= 0) && (v >= 0) && (u + v < 1);
31 }
OLDNEW
« no previous file with comments | « experimental/Intersection/TriangleUtilities.h ('k') | experimental/Intersection/as.htm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698