summaryrefslogtreecommitdiff
path: root/core/math/geometry.h
diff options
context:
space:
mode:
authorJuan Linietsky <reduzio@gmail.com>2018-04-08 18:18:19 -0300
committerGitHub <noreply@github.com>2018-04-08 18:18:19 -0300
commitcef01f1f499d83f13753e437ddd20a8df61ca326 (patch)
tree3dffadea6b2d37aadb5187454a04f3287ef3246f /core/math/geometry.h
parentb88a16c7ac471eac43914d8974d196f6edc8af15 (diff)
parentf2c22791ce1d318954c72dec7a39edf72d728b06 (diff)
Merge pull request #16495 from Chaosus/is_point_in_triangle_fix
Fix is_point_in_triangle function
Diffstat (limited to 'core/math/geometry.h')
-rw-r--r--core/math/geometry.h13
1 files changed, 6 insertions, 7 deletions
diff --git a/core/math/geometry.h b/core/math/geometry.h
index ca4363e129..73a53c53b6 100644
--- a/core/math/geometry.h
+++ b/core/math/geometry.h
@@ -502,16 +502,15 @@ public:
}
static bool is_point_in_triangle(const Vector2 &s, const Vector2 &a, const Vector2 &b, const Vector2 &c) {
- int as_x = s.x - a.x;
- int as_y = s.y - a.y;
+ Vector2 an = a - s;
+ Vector2 bn = b - s;
+ Vector2 cn = c - s;
- bool s_ab = (b.x - a.x) * as_y - (b.y - a.y) * as_x > 0;
+ bool orientation = an.cross(bn) > 0;
- if (((c.x - a.x) * as_y - (c.y - a.y) * as_x > 0) == s_ab) return false;
+ if ((bn.cross(cn) > 0) != orientation) return false;
- if (((c.x - b.x) * (s.y - b.y) - (c.y - b.y) * (s.x - b.x) > 0) != s_ab) return false;
-
- return true;
+ return (cn.cross(an) > 0) == orientation;
}
static bool is_point_in_polygon(const Vector2 &p_point, const Vector<Vector2> &p_polygon);