public void Polygon_SliceAnotherCaseThatDidntWorkBefore() { List<LineSegment> bounds = new List<LineSegment>(); bounds.Add(new LineSegment(Point.Origin, Point.MakePointWithInches(0, 0, 1.5))); bounds.Add(new LineSegment(Point.MakePointWithInches(0, 0, 1.5), Point.MakePointWithInches(240, 0, 1.5))); bounds.Add(new LineSegment(Point.MakePointWithInches(240, 0, 1.5), Point.MakePointWithInches(240, 0, 0))); bounds.Add(new LineSegment(Point.MakePointWithInches(240, 0, 0), Point.Origin)); Polygon testPolygon = new Polygon(bounds); Plane slicingPlane = new Plane(new Direction(new Angle(new Radian(), 5.6548667765)), Point.MakePointWithInches(122.8315595, 169.313137732, 0)); List<Polygon> results = testPolygon.Slice(slicingPlane); //create the expected planes to compare to List<LineSegment> expected1Bounds = new List<LineSegment>(); expected1Bounds.Add(new LineSegment(Point.Origin, Point.MakePointWithInches(240, 0, 0))); expected1Bounds.Add(new LineSegment(Point.MakePointWithInches(240, 0, 0), Point.MakePointWithInches(240, 0, 1.5))); expected1Bounds.Add(new LineSegment(Point.MakePointWithInches(240, 0, 1.5), Point.MakePointWithInches(0, 0, 1.5))); expected1Bounds.Add(new LineSegment(Point.MakePointWithInches(0, 0, 1.5), Point.Origin)); Polygon expected1 = new Polygon(expected1Bounds); //should only return the original plane results.Count.Should().Be(1); (results[0] == testPolygon).Should().BeTrue(); }
public void Polygon_SliceWithLineTest() { //changed to inches because mm were gave results smaller than what we are considering equivalent List<LineSegment> bounds = new List<LineSegment>(); bounds.Add(new LineSegment(Point.Origin, Point.MakePointWithInches(2, 1, 0))); bounds.Add(new LineSegment(Point.MakePointWithInches(2, 1, 0), Point.MakePointWithInches(6, 1, 0))); bounds.Add(new LineSegment(Point.MakePointWithInches(6, 0, 0), Point.Origin)); bounds.Add(new LineSegment(Point.MakePointWithInches(6, 1, 0), Point.MakePointWithInches(6, 0, 0))); Polygon testPolygon = new Polygon(bounds); Line slicingLine = new Line(Point.MakePointWithInches(6, 5, 0), Point.MakePointWithInches(2, 1, 0)); List<Polygon> results = testPolygon.Slice(slicingLine); //create the expected planes to compare to List<LineSegment> expected1Bounds = new List<LineSegment>(); expected1Bounds.Add(new LineSegment(Point.MakePointWithInches(1, 0, 0), Point.MakePointWithInches(2, 1, 0))); expected1Bounds.Add(new LineSegment(Point.MakePointWithInches(2, 1, 0), Point.MakePointWithInches(6, 1, 0))); expected1Bounds.Add(new LineSegment(Point.MakePointWithInches(6, 0, 0), Point.MakePointWithInches(1, 0, 0))); expected1Bounds.Add(new LineSegment(Point.MakePointWithInches(6, 1, 0), Point.MakePointWithInches(6, 0, 0))); Polygon expected1 = new Polygon(expected1Bounds); List<LineSegment> expected2Bounds = new List<LineSegment>(); expected2Bounds.Add(new LineSegment(Point.Origin, Point.MakePointWithInches(1, 0, 0))); expected2Bounds.Add(new LineSegment(Point.MakePointWithInches(1, 0, 0), Point.MakePointWithInches(2, 1, 0))); expected2Bounds.Add(new LineSegment(Point.MakePointWithInches(2, 1, 0), Point.Origin)); Polygon expected2 = new Polygon(expected2Bounds); results.Contains(expected2).Should().BeTrue(); results.Contains(expected1).Should().BeTrue(); //now make sure it handles no intersection well Line notIntersecting = new Line(Point.Origin, Point.MakePointWithInches(1, 1, 0.9)); List<Polygon> results2 = testPolygon.Slice(notIntersecting); //should only return the original plane results2.Count.Should().Be(1); (results2[0] == testPolygon).Should().BeTrue(); }
public void Polygon_SliceACaseThatDidntWorkBefore() { List<LineSegment> bounds = new List<LineSegment>(); bounds.Add(new LineSegment(Point.Origin, Point.MakePointWithInches(0, 3.5, 0))); bounds.Add(new LineSegment(Point.MakePointWithInches(0, 3.5, 0), Point.MakePointWithInches(240, 3.5, 0))); bounds.Add(new LineSegment(Point.MakePointWithInches(240, 3.5, 0), Point.MakePointWithInches(240, 0, 0))); bounds.Add(new LineSegment(Point.MakePointWithInches(240, 0, 0), Point.Origin)); Polygon testPolygon = new Polygon(bounds); Plane slicingPlane = new Plane(new Direction(new Angle(new Radian(), 5.6548667765)), Point.MakePointWithInches(122.8315595, 169.313137732, 0)); List<Polygon> results = testPolygon.Slice(slicingPlane); //create the expected planes to compare to List<LineSegment> expected1Bounds = new List<LineSegment>(); expected1Bounds.Add(new LineSegment(Point.Origin, Point.MakePointWithInches(0, 0.25, 0))); expected1Bounds.Add(new LineSegment(Point.MakePointWithInches(0, 0.25, 0), Point.MakePointWithInches(2.36126321602, 3.5, 0))); expected1Bounds.Add(new LineSegment(Point.MakePointWithInches(2.36126321602, 3.5, 0), Point.MakePointWithInches(240, 3.5, 0))); expected1Bounds.Add(new LineSegment(Point.MakePointWithInches(240, 3.5, 0), Point.MakePointWithInches(240, 0, 0))); expected1Bounds.Add(new LineSegment(Point.MakePointWithInches(240, 0, 0), Point.Origin)); Polygon expected1 = new Polygon(expected1Bounds); List<LineSegment> expected2Bounds = new List<LineSegment>(); expected2Bounds.Add(new LineSegment(Point.MakePointWithInches(0, 0.25, 0), Point.MakePointWithInches(0, 3.5, 0))); expected2Bounds.Add(new LineSegment(Point.MakePointWithInches(0, 3.5, 0), Point.MakePointWithInches(2.36126321602, 3.5, 0))); expected2Bounds.Add(new LineSegment(Point.MakePointWithInches(2.36126321602, 3.5, 0), Point.MakePointWithInches(0, 0.25, 0))); Polygon expected2 = new Polygon(expected2Bounds); results.Contains(expected1).Should().BeTrue(); results.Contains(expected2).Should().BeTrue(); //now make sure it handles no intersection well Line notIntersecting = new Line(Point.Origin, Point.MakePointWithInches(1, 1, 0.9)); List<Polygon> results2 = testPolygon.Slice(notIntersecting); //should only return the original plane results2.Count.Should().Be(1); (results2[0] == testPolygon).Should().BeTrue(); }
public void Polygon_SliceOnLineTest() { List<LineSegment> bounds = new List<LineSegment>(); bounds.Add(new LineSegment(Point.MakePointWithInches(0, 1, 0), Point.MakePointWithInches(0, 3, 0))); bounds.Add(new LineSegment(Point.MakePointWithInches(0, 1, 0), Point.MakePointWithInches(4, 1, 4))); bounds.Add(new LineSegment(Point.MakePointWithInches(0, 3, 0), Point.MakePointWithInches(4, 3, 4))); bounds.Add(new LineSegment(Point.MakePointWithInches(4, 1, 4), Point.MakePointWithInches(4, 3, 4))); Polygon testPolygon = new Polygon(bounds); Line slicingLine = new Line(Point.Origin, Point.MakePointWithInches(1, 1, 1)); List<Polygon> results = testPolygon.Slice(slicingLine); //create the expected planes to compare to List<LineSegment> expected1Bounds = new List<LineSegment>(); expected1Bounds.Add(new LineSegment(Point.MakePointWithInches(0, 1, 0), Point.MakePointWithInches(0, 3, 0))); expected1Bounds.Add(new LineSegment(Point.MakePointWithInches(0, 1, 0), Point.MakePointWithInches(1, 1, 1))); expected1Bounds.Add(new LineSegment(Point.MakePointWithInches(0, 3, 0), Point.MakePointWithInches(3, 3, 3))); expected1Bounds.Add(new LineSegment(Point.MakePointWithInches(1, 1, 1), Point.MakePointWithInches(3, 3, 3))); Polygon expected1 = new Polygon(expected1Bounds); List<LineSegment> expected2Bounds = new List<LineSegment>(); expected2Bounds.Add(new LineSegment(Point.MakePointWithInches(1, 1, 1), Point.MakePointWithInches(3, 3, 3))); expected2Bounds.Add(new LineSegment(Point.MakePointWithInches(1, 1, 1), Point.MakePointWithInches(4, 1, 4))); expected2Bounds.Add(new LineSegment(Point.MakePointWithInches(3, 3, 3), Point.MakePointWithInches(4, 3, 4))); expected2Bounds.Add(new LineSegment(Point.MakePointWithInches(4, 1, 4), Point.MakePointWithInches(4, 3, 4))); Polygon expected2 = new Polygon(expected2Bounds); results.Contains(expected2).Should().BeTrue(); results.Contains(expected1).Should().BeTrue(); //now make sure it handles no intersection well Line notIntersecting = new Line(Point.Origin, Point.MakePointWithInches(1, 1, 0.9)); List<Polygon> results2 = testPolygon.Slice(notIntersecting); //should only return the original plane results2.Count.Should().Be(1); (results2[0] == testPolygon).Should().BeTrue(); }