Skip to content

Commit 027109b

Browse files
committed
Fixed polygon overlap functions
1 parent cd921a8 commit 027109b

File tree

1 file changed

+37
-5
lines changed

1 file changed

+37
-5
lines changed

olcUTIL_Geometry2D.h

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2926,31 +2926,63 @@ namespace olc::utils::geom2d
29262926
template<typename T1, typename T2>
29272927
inline constexpr bool overlaps(const line<T1>& l, const polygon<T2>& p)
29282928
{
2929-
return contains(l, p);
2929+
for (auto& triangle : p.triangles)
2930+
{
2931+
if (overlaps(l, triangle) == true)
2932+
{
2933+
return true;
2934+
}
2935+
}
2936+
2937+
return false;
29302938
}
29312939

29322940
// overlaps(r,p)
29332941
// Checks if rectangle overlaps with polygon
29342942
template<typename T1, typename T2>
29352943
inline constexpr bool overlaps(const rect<T1>& r, const polygon<T2>& p)
29362944
{
2937-
return contains(r, p);
2945+
for (auto& triangle : p.triangles)
2946+
{
2947+
if (overlaps(r, triangle) == true)
2948+
{
2949+
return true;
2950+
}
2951+
}
2952+
2953+
return false;
29382954
}
29392955

29402956
// overlaps(c,p)
29412957
// Checks if circle overlaps with polygon
29422958
template<typename T1, typename T2>
29432959
inline constexpr bool overlaps(const circle<T1>& c, const polygon<T2>& p)
29442960
{
2945-
return contains(c, p);
2961+
for (auto& triangle : p.triangles)
2962+
{
2963+
if (overlaps(c, triangle) == true)
2964+
{
2965+
return true;
2966+
}
2967+
}
2968+
2969+
return false;
29462970
}
29472971

29482972
// overlaps(t,p)
29492973
// Checks if triangle overlaps with polygon
29502974
template<typename T1, typename T2>
29512975
inline constexpr bool overlaps(const triangle<T1>& t, const polygon<T2>& p)
29522976
{
2953-
return contains(t, p);
2977+
for (auto& triangle : p.triangles)
2978+
{
2979+
if (overlaps(t, triangle) == true)
2980+
{
2981+
return true;
2982+
}
2983+
}
2984+
2985+
return false;
29542986
}
29552987

29562988
// overlaps(t,p)
@@ -2960,7 +2992,7 @@ namespace olc::utils::geom2d
29602992
{
29612993
for (auto& triangle : p1.triangles)
29622994
{
2963-
if (contains(triangle, p2) == false)
2995+
if (overlaps(triangle, p2) == false)
29642996
{
29652997
return false;
29662998
}

0 commit comments

Comments
 (0)