diff options
| author | hurikhan | 2015-02-15 17:49:34 +0800 |
|---|---|---|
| committer | hurikhan | 2015-02-15 17:49:34 +0800 |
| commit | ee81d4b359ec5dbeaed5725739ba53b7734372cd (patch) | |
| tree | 50bff1e6e336fe66d0f58c00841403ce091d3f1c /core/math/geometry.h | |
| parent | a13e180052d2e17275498a2fa78185cc299ace11 (diff) | |
| parent | 2185c018f6593e6d64b2beb62202d2291e2e008e (diff) | |
| download | godot-ee81d4b359ec5dbeaed5725739ba53b7734372cd.tar.gz godot-ee81d4b359ec5dbeaed5725739ba53b7734372cd.tar.zst godot-ee81d4b359ec5dbeaed5725739ba53b7734372cd.zip | |
Merge remote-tracking branch 'upstream/master' into x11-window-management
Diffstat (limited to 'core/math/geometry.h')
| -rw-r--r-- | core/math/geometry.h | 14 |
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]; |
