public void IntersectWithRectangleWhenTangent(string ls, string rs, string eps) { Line l = Line.Parse(ls); Rect rect = Rect.Parse(rs); Point?expected = eps == "null" ? (Point?)null : Point.Parse(eps); Point?actual = l.ClosestIntersection(rect); PointAssert.Equal(expected, actual, 2); }
public void PointOnCircumference(string es, string vs, string eps) { var ellipse = Ellipse.Parse(es); var direction = Vector.Parse(vs); var expected = Point.Parse(eps); var actual = ellipse.PointOnCircumference(direction); PointAssert.Equal(expected, actual, 2); }
public void FirstIntersectionWithEllipse(string rs, string es, string eps) { var ray = Ray.Parse(rs); var ellipse = Ellipse.Parse(es); var expected = eps == "null" ? (Point?)null : Point.Parse(eps); var actual = ray.FirstIntersectionWith(ellipse); PointAssert.Equal(expected, actual, 2); }
public void PointAtAngle(string es, double angle, string eps) { var ellipse = Ellipse.Parse(es); var expected = Point.Parse(eps); var direction = new Vector(1, 0).Rotate(angle); var actual = ellipse.PointOnCircumference(direction); PointAssert.Equal(expected, actual, 2); Assert.Equal(ellipse.CenterPoint.DistanceTo(actual), ellipse.RadiusInDirection(direction), 3); }
public void FirstIntersectionWithRectFromOutsideRoundtrips(string rs) { var rect = Rect.Parse(rs); var xAxis = new Vector(1, 0); for (var i = -180; i < 180; i++) { var direction = xAxis.Rotate(i); var fromCenter = new Ray(rect.CenterPoint(), direction); var pointOnRect = fromCenter.FirstIntersectionWith(rect).GetValueOrDefault(); var ray = new Ray(pointOnRect + direction, direction.Negated()); var actual = ray.FirstIntersectionWith(rect); PointAssert.Equal(pointOnRect, actual, 2); if (rect.ClosestCornerPoint(pointOnRect) .DistanceTo(pointOnRect) < 0.01) { continue; } Vector wallNormal; if (Math.Abs(pointOnRect.X - rect.Left) < Constants.Tolerance) { wallNormal = new Vector(-1, 0); } else if (Math.Abs(pointOnRect.X - rect.Right) < Constants.Tolerance) { wallNormal = new Vector(1, 0); } else if (Math.Abs(pointOnRect.Y - rect.Bottom) < Constants.Tolerance) { wallNormal = new Vector(0, 1); } else { wallNormal = new Vector(0, -1); } for (var j = -89; j < 89; j++) { var rayDirection = wallNormal.Rotate(j); ray = new Ray(pointOnRect + rayDirection, rayDirection.Negated()); actual = ray.FirstIntersectionWith(rect); if (!NullablePointComparer.TwoDigits.Equals(pointOnRect, actual)) { Debugger.Break(); } PointAssert.Equal(pointOnRect, actual, 2); } } }
public void FirstIntersectionWithEllipseFromInsideRoundtrips(string es) { var ellipse = Ellipse.Parse(es); var xv = new Vector(1, 0); for (var i = -180; i < 180; i++) { var direction = xv.Rotate(i); var expected = ellipse.PointOnCircumference(direction); var ray = new Ray(ellipse.CenterPoint, direction); var actual = ray.FirstIntersectionWith(ellipse); PointAssert.Equal(expected, actual, 2); } }
public void FirstIntersectionWithEllipseFromOutsideRoundtrips(string es) { var ellipse = Ellipse.Parse(es); var xv = new Vector(1, 0); for (var i = -180; i < 180; i++) { var fromCenterDirection = xv.Rotate(i); var pointOnCircumference = ellipse.PointOnCircumference(fromCenterDirection); var ray = new Ray(pointOnCircumference + fromCenterDirection, fromCenterDirection.Negated()); var actual = ray.FirstIntersectionWith(ellipse); PointAssert.Equal(pointOnCircumference, actual, 2); for (var j = -70; j < 70; j++) { var direction = fromCenterDirection.Rotate(j); ray = new Ray(pointOnCircumference + direction, direction.Negated()); actual = ray.FirstIntersectionWith(ellipse); PointAssert.Equal(pointOnCircumference, actual, 2); } } }
public void IntersectWithRectangleStartingInside(string ls, string rs, string eps) { Line l = Line.Parse(ls); Rect rect = Rect.Parse(rs); Point expected = Point.Parse(eps); Point?actual = l.ClosestIntersection(rect); PointAssert.Equal(expected, actual, 2); actual = l.Flip().ClosestIntersection(rect); PointAssert.Equal(expected, actual, 2); Line l2 = l.RotateAroundStartPoint(0.01); actual = l2.ClosestIntersection(rect); PointAssert.Equal(expected, actual, 2); Line l3 = l.RotateAroundStartPoint(-0.01); actual = l3.ClosestIntersection(rect); PointAssert.Equal(expected, actual, 2); }