Skip to content

Commit a6dd51d

Browse files
gregmeessrms80
authored andcommitted
Add additional methods for checking Segment2d
1 parent fea8731 commit a6dd51d

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

curve/GeneralPolygon2d.cs

+13
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,19 @@ public bool Contains(Polygon2d poly) {
189189
}
190190

191191

192+
public bool Contains(Segment2d seg)
193+
{
194+
if (outer.Contains(seg) == false)
195+
return false;
196+
foreach (var h in holes)
197+
{
198+
if (h.Intersects(seg))
199+
return false;
200+
}
201+
return true;
202+
}
203+
204+
192205
public bool Intersects(Polygon2d poly)
193206
{
194207
if (outer.Intersects(poly))

curve/Polygon2d.cs

+18-1
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,7 @@ public bool Contains(Polygon2d o) {
335335

336336
public bool Contains(Segment2d o)
337337
{
338+
// [TODO] Add bbox check
338339
if (Contains(o.P0) == false || Contains(o.P1) == false)
339340
return false;
340341

@@ -359,8 +360,24 @@ public bool Intersects(Polygon2d o) {
359360
return false;
360361
}
361362

363+
public bool Intersects(Segment2d o)
364+
{
365+
// [TODO] Add bbox check
366+
if (Contains(o.P0) == true || Contains(o.P1) == true)
367+
return true;
368+
369+
// [TODO] Add bbox check
370+
foreach (Segment2d seg in SegmentItr())
371+
{
372+
if (seg.Intersects(o))
373+
return true;
374+
}
375+
return false;
376+
}
377+
378+
362379

363-
public List<Vector2d> FindIntersections(Polygon2d o) {
380+
public List<Vector2d> FindIntersections(Polygon2d o) {
364381
List<Vector2d> v = new List<Vector2d>();
365382
if ( ! this.GetBounds().Intersects( o.GetBounds() ) )
366383
return v;

0 commit comments

Comments
 (0)