public void PointInCircle_OnEdge_False() { Circle c = new Circle(new Vector2(10.0f, 10.0f), 5.0f); Vector2 p = new Vector2(15.0f, 10.0f); var result = PolygonIntersection.IsPointInCircle(p, c, false); Assert.False(result); }
public void PointInPoly_Winding_Pass() { Polygon p = Polygon.CreateRegularNSidedPolygon(new Vector2(0.0f, 0.0f), 5, 10.0f); Vector2 v = new Vector2(5.0f, 5.0f); var result = PolygonIntersection.IsPointInPolygon(v, p, true, true); Assert.True(result); }
public void PointInPoly_Crossing_Fail() { Polygon p = Polygon.CreateRegularNSidedPolygon(new Vector2(0.0f, 0.0f), 4, 10.0f); Vector2 v = new Vector2(15.0f, 15.0f); var result = PolygonIntersection.IsPointInPolygon(v, p, true, false); Assert.False(result); }
public void PointInPoly_OnEdge_False() { Polygon p = Polygon.CreateRegularNSidedPolygon(new Vector2(0.0f, 0.0f), 4, 10.0f); Vector2 v = new Vector2(10.0f, 0.0f); var result = PolygonIntersection.IsPointInPolygon(v, p, false, false); Assert.False(result); }
public void CirclePolyIntersect_SimpleBoolean_Negative() { var c = new Circle(new Vector2(0.0f, 0.0f), 10.0f); var p = Polygon.CreateRegularNSidedPolygon(new Vector2(25.0f, 0.0f), 4, 10.0f); var result = PolygonIntersection.CirclePolygonIntersect(c.Position, c.Radius, p); Assert.False(result); }
public void PointInCircle_Pass() { Circle c = new Circle(new Vector2(10.0f, 10.0f), 5.0f); Vector2 p = new Vector2(11.0f, 12.0f); var result = PolygonIntersection.IsPointInCircle(p, c); Assert.True(result); }
public void CircleCircleIntersect_FullOverload_NegativeOnEdge() { var result = PolygonIntersection.CircleCircleIntersect(new Vector2(5.0f, 5.0f), 10.0f, new Vector2(5.0f, 25.0f), 10.0f, false); Assert.False(result.Intersecting); Assert.Equal(0.0f, result.Depth, 4); Assert.Equal(0.0f, result.Normal0To1.X, 4); Assert.Equal(0.0f, result.Normal0To1.Y, 4); Assert.Equal(0.0f, result.Point.X, 4); Assert.Equal(0.0f, result.Point.Y, 4); }
public void CircleCircleIntersect_FullOverload_Positive() { var result = PolygonIntersection.CircleCircleIntersect(new Vector2(4.0f, 4.0f), 10.0f, new Vector2(4.0f, 20.0f), 10.0f, true); Assert.True(result.Intersecting); Assert.Equal(4.0f, result.Depth, 4); Assert.Equal(0.0f, result.Normal0To1.X, 4); Assert.Equal(1.0f, result.Normal0To1.Y, 4); Assert.Equal(4.0f, result.Point.X, 4); Assert.Equal(10.0f, result.Point.Y, 4); }
public void CircleCircleIntersect_PositiveSimpleOverload() { Circle c0 = new Circle(new System.Numerics.Vector2(0.0f, 0.0f), 20.0f); Circle c1 = new Circle(new System.Numerics.Vector2(30.0f, 0.0f), 20.0f); var result = PolygonIntersection.CircleCircleIntersect(c0, c1); Assert.True(result.Intersecting); Assert.Equal(10.0f, result.Depth, 4); Assert.Equal(1.0f, result.Normal0To1.X, 4); Assert.Equal(0.0f, result.Normal0To1.Y, 4); Assert.Equal(10.0f, result.Point.X, 4); Assert.Equal(0.0f, result.Point.Y, 4); }
public void CirclePolyIntersect_OnEdge_Negative() { var c = new Circle(new Vector2(0.0f, 0.0f), 10.0f); var p = Polygon.CreateRegularNSidedPolygon(new Vector2(25.0f, 0.0f), 4, 10.0f); var result = PolygonIntersection.CirclePolygonIntersect(c.Position, c.Radius, p, false); Assert.False(result.Intersecting); Assert.Equal(0.0f, result.Depth, 4); Assert.Equal(0.0f, result.Normal0To1.X, 4); Assert.Equal(0.0f, result.Normal0To1.Y, 4); Assert.Equal(0.0f, result.Point.X, 4); Assert.Equal(0.0f, result.Point.Y, 4);; }
public void CirclePolyIntersect_OnEdge_Positive() { var c = new Circle(new Vector2(0.0f, 0.0f), 10.0f); var p = Polygon.CreateRegularNSidedPolygon(new Vector2(19.9999f, 0.0f), 4, 10.0f); //issue here again with epsilon i think... var result = PolygonIntersection.CirclePolygonIntersect(c.Position, c.Radius, p, true); Assert.True(result.Intersecting); Assert.Equal(0.0f, result.Depth, 3); Assert.Equal(1.0f, result.Normal0To1.X, 3); Assert.Equal(0.0f, result.Normal0To1.Y, 3); Assert.Equal(0.0f, result.Point.X, 3); Assert.Equal(0.0f, result.Point.Y, 3);; }
public void CirclePolyIntersect_SimpleResult_Positive() { var c = new Circle(new Vector2(0.0f, 0.0f), 10.0f); var p = Polygon.CreateRegularNSidedPolygon(new Vector2(15.0f, 0.0f), 4, 10.0f); var result = PolygonIntersection.CirclePolygonIntersect(c, p); Assert.True(result.Intersecting); Assert.Equal(5.0f, result.Depth, 4); Assert.Equal(1.0f, result.Normal0To1.X, 4); Assert.Equal(0.0f, result.Normal0To1.Y, 4); Assert.Equal(0.0f, result.Point.X, 4); Assert.Equal(0.0f, result.Point.Y, 4);; }
public void PolyPolyIntersect_SimpleBoolean_Negative() { var p0 = new Polygon(new Vector2[] { new Vector2(-50.0f, 50.0f), new Vector2(50.0f, 50.0f), new Vector2(50.0f, -50.0f), new Vector2(-50.0f, -50.0f) }); var p1 = new Polygon(new Vector2[] { new Vector2(0.0f, 60.0f), new Vector2(-50.0f, 120.0f), new Vector2(50.0f, 120.0f) }); var result = PolygonIntersection.PolygonPolygonIntersect(p0, p1); Assert.False(result); }
public void PolyPolyIntersect_SimpleBoolean_Positive() { var p0 = new Polygon(new Vector2[] { new Vector2(-50.0f, 50.0f), new Vector2(50.0f, 50.0f), new Vector2(50.0f, -50.0f), new Vector2(-50.0f, -50.0f) }); var p1 = new Polygon(new Vector2[] { new Vector2(0.0f, 40.0f), new Vector2(-50.0f, 100.0f), new Vector2(50.0f, 100.0f) }); var result = PolygonIntersection.PolygonPolygonIntersect(p0, p1); Assert.True(result); }
public void PolyPolyIntersect_FullOverload_Positive() { var p0 = new Polygon(new Vector2[] { new Vector2(-50.0f, 50.0f), new Vector2(50.0f, 50.0f), new Vector2(50.0f, -50.0f), new Vector2(-50.0f, -50.0f) }); var p1 = new Polygon(new Vector2[] { new Vector2(0.0f, 40.0f), new Vector2(-50.0f, 100.0f), new Vector2(50.0f, 100.0f) }); var result = PolygonIntersection.PolygonPolygonIntersect(p0, p1, true); Assert.True(result.Intersecting); Assert.Equal(10.0f, result.Depth, 4); Assert.Equal(0.0f, result.Normal0To1.X, 4); Assert.Equal(1.0f, result.Normal0To1.Y, 4); Assert.Equal(0.0f, result.Point.X, 4); Assert.Equal(0.0f, result.Point.Y, 4); }
public void PolyPolyIntersect_FullOverload_PositiveOnEdge() { var p0 = new Polygon(new Vector2[] { new Vector2(-50.0f, 50.0f), new Vector2(50.0f, 50.0f), new Vector2(50.0f, -50.0f), new Vector2(-50.0f, -50.0f) }); var p1 = new Polygon(new Vector2[] { new Vector2(0.0f, 49.9999f),//Due to the epsilon impact on fireonedge.. new Vector2(-50.0f, 100.0f), new Vector2(50.0f, 100.0f) }); var result = PolygonIntersection.PolygonPolygonIntersect(p0, p1, true); Assert.True(result.Intersecting); Assert.Equal(0.0f, result.Depth, 3); Assert.Equal(0.0f, result.Normal0To1.X, 3); Assert.Equal(1.0f, result.Normal0To1.Y, 3); Assert.Equal(0.0f, result.Point.X, 3); Assert.Equal(0.0f, result.Point.Y, 3); }
public void PolyPolyIntersect_FullOverload_NegativeOnEdge() { var p0 = new Polygon(new Vector2[] { new Vector2(-50.0f, 50.0f), new Vector2(50.0f, 50.0f), new Vector2(50.0f, -50.0f), new Vector2(-50.0f, -50.0f) }); var p1 = new Polygon(new Vector2[] { new Vector2(0.0f, 50.0f), new Vector2(-50.0f, 100.0f), new Vector2(50.0f, 100.0f) }); var result = PolygonIntersection.PolygonPolygonIntersect(p0, p1, false); Assert.False(result.Intersecting); Assert.Equal(0.0f, result.Depth, 4); Assert.Equal(0.0f, result.Normal0To1.X, 4); Assert.Equal(0.0f, result.Normal0To1.Y, 4); Assert.Equal(0.0f, result.Point.X, 4); Assert.Equal(0.0f, result.Point.Y, 4); }
public void BuildTrimmingAreas( PolygonIntersection intersection, Func <IntersectionParametrisation, Parametrisation> paramSelector ) { if (intersection.Polygon.Count == 0) { return; } var area = new TrimmingArea(); Point?leftSnap = null; var firstParam = paramSelector(intersection.Polygon[0]); if (!intersection.IsLooped && (IsSnappable(firstParam.U) || IsSnappable(firstParam.V)) ) { leftSnap = new Point(Snap(firstParam.U), Snap(firstParam.V)); area.Polygon.Add(leftSnap.Value); } Parametrisation?previous = null; for (var i = 0; i < intersection.Polygon.Count; ++i) { var parametrisation = paramSelector(intersection.Polygon[i]); // skip v traversal if (parametrisation.Boundaries.AllowTraversalV && previous.HasValue && previous.Value.VBoxId != parametrisation.VBoxId) { // subdivide this part Func <double, double, double, double> tFunc = (side, x0, dx) => (side - x0) / dx; var prevUnbU = previous.Value.UnboundedU; var prevUnbV = previous.Value.UnboundedV; var dU = parametrisation.UnboundedU - prevUnbU; var dV = parametrisation.UnboundedV - prevUnbV; var t1 = tFunc(0, prevUnbV, dV); var t2 = tFunc(1, prevUnbV, dV); var t = Math.Max(t1, t2); var subdivideIncreaseU = dU * t; var subdivideIncreaseV = dV * t; var firstSubdividePoint = new Point( previous.Value.U + subdivideIncreaseU, previous.Value.V + subdivideIncreaseV ); var secondSubdividePoint = new Point( firstSubdividePoint.X, 1 - firstSubdividePoint.Y ); area.Polygon.Add(firstSubdividePoint); area.Polygon.Add(secondSubdividePoint); } area.Polygon.Add( new Point(parametrisation.U, parametrisation.V) ); previous = parametrisation; } var lastParam = paramSelector(intersection.Polygon.Last()); if (!intersection.IsLooped && (IsSnappable(lastParam.U) || IsSnappable(lastParam.V)) ) { Point rightSnap = new Point( Snap(lastParam.U), Snap(lastParam.V) ); area.Polygon.Add(rightSnap); if (leftSnap.HasValue) { bool top, bottom, right, left; top = bottom = right = left = false; top |= AlmostEqual(leftSnap.Value.Y, 0.0); top |= AlmostEqual(rightSnap.Y, 0.0); bottom |= AlmostEqual(leftSnap.Value.Y, 1.0); bottom |= AlmostEqual(rightSnap.Y, 1.0); left |= AlmostEqual(leftSnap.Value.X, 0.0); left |= AlmostEqual(rightSnap.X, 0.0); right |= AlmostEqual(leftSnap.Value.X, 1.0); right |= AlmostEqual(rightSnap.X, 1.0); Point?additional = null; if (top && bottom || left && right) { } else { var x = left ? 0.0 : 1.0; var y = top ? 0.0 : 1.0; additional = new Point(x, y); } if (additional.HasValue) { area.Polygon.Add(additional.Value); area.Polygon.Add(leftSnap.Value); } } } _trimmingAreas.Add(area); }
public void CircleCircleIntersect_NegativeSimpleBooleanOverload() { var result = PolygonIntersection.CircleCircleIntersect(new Vector2(0.0f, 0.0f), 20.0f, new Vector2(100.0f, 0.0f), 20.0f); Assert.False(result); }
public void CircleCircleIntersect_PositiveSimpleBooleanOverload() { var result = PolygonIntersection.CircleCircleIntersect(new Vector2(0.0f, 0.0f), 20.0f, new Vector2(30.0f, 0.0f), 20.0f); Assert.True(result); }