aboutsummaryrefslogtreecommitdiff
path: root/core/math/geometry.h
diff options
context:
space:
mode:
authorAnton Yabchinskiy2015-02-17 15:57:24 +0300
committerAnton Yabchinskiy2015-02-17 15:57:24 +0300
commite024ff89b224f803fe335efa95d3e99bffc3423f (patch)
tree84ca5323c97ef24cfcae202447ac6967783e9248 /core/math/geometry.h
parent6f93e6812edaf6c8c79c28dadbe5f1c4a8ced93e (diff)
parent2bea642583efeb68886e71950384f297f2d7ee12 (diff)
downloadgodot-e024ff89b224f803fe335efa95d3e99bffc3423f.tar.gz
godot-e024ff89b224f803fe335efa95d3e99bffc3423f.tar.zst
godot-e024ff89b224f803fe335efa95d3e99bffc3423f.zip
Diffstat (limited to 'core/math/geometry.h')
-rw-r--r--core/math/geometry.h14
1 files changed, 14 insertions, 0 deletions
diff --git a/core/math/geometry.h b/core/math/geometry.h
index 81530e30c..7e0cc01a2 100644
--- a/core/math/geometry.h
+++ b/core/math/geometry.h
@@ -511,6 +511,20 @@ public:
else
return p_segment[0]+n*d; // inside
}
+
+ 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;
+
+ bool s_ab = (b.x-a.x)*as_y-(b.y-a.y)*as_x > 0;
+
+ if((c.x-a.x)*as_y-(c.y-a.y)*as_x > 0 == s_ab) 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;
+ }
static Vector2 get_closest_point_to_segment_uncapped_2d(const Vector2& p_point, const Vector2 *p_segment) {
Vector2 p=p_point-p_segment[0];