public void LineSegment_GetInitialDirection_ShouldReturnDirection() { LineSegment lineSegment = new LineSegment(Point.MakePointWithInches(1, 1, 1)); Direction direction = new Direction(1, 1, 1); lineSegment.InitialDirection.Should().Be(direction); }
public void RightTriangle_LineSegmentConstructorTest() { // Build right triangle with line segments LineSegment rt_sideOne = new LineSegment(Point.MakePointWithInches(2, 1), Point.MakePointWithInches(4, 1)); LineSegment rt_sideTwo = new LineSegment(Point.MakePointWithInches(2, 1), Point.MakePointWithInches(2, 4)); LineSegment rt_sideThree = new LineSegment(Point.MakePointWithInches(2, 4), Point.MakePointWithInches(4, 1)); List<LineSegment> rt_sides = new List<LineSegment>() { rt_sideOne, rt_sideTwo, rt_sideThree }; RightTriangle rt = new RightTriangle(rt_sides); }
public void LineSegment_GetEndPoints_ShouldListOfEndPoints() { LineSegment lineSegment = new LineSegment(Point.MakePointWithInches(1, 1, 1)); List<Point> pointList = new List<Point>(); pointList.Add(Point.Origin); pointList.Add(Point.MakePointWithInches(1, 1, 1)); lineSegment.EndPoints.Should().Equal(pointList); }
public void RightTriangle_HypotenuseTest() { LineSegment rt_sideOne = new LineSegment(Point.MakePointWithInches(2, 1), Point.MakePointWithInches(4, 1)); LineSegment rt_sideTwo = new LineSegment(Point.MakePointWithInches(2, 1), Point.MakePointWithInches(2, 4)); LineSegment rt_sideThree = new LineSegment(Point.MakePointWithInches(2, 4), Point.MakePointWithInches(4, 1)); List<LineSegment> rt_sides = new List<LineSegment>() { rt_sideOne, rt_sideTwo, rt_sideThree }; RightTriangle rt = new RightTriangle(rt_sides); (rt.Hypotenuse == rt_sideThree).Should().BeTrue(); }
public void RightTriangle_AreaTest() { LineSegment rt_sideOne = new LineSegment(Point.MakePointWithInches(2, 1), Point.MakePointWithInches(4, 1)); LineSegment rt_sideTwo = new LineSegment(Point.MakePointWithInches(2, 1), Point.MakePointWithInches(2, 4)); LineSegment rt_sideThree = new LineSegment(Point.MakePointWithInches(2, 4), Point.MakePointWithInches(4, 1)); List<LineSegment> rt_sides = new List<LineSegment>() { rt_sideOne, rt_sideTwo, rt_sideThree }; RightTriangle rt = new RightTriangle(rt_sides); (rt.Area == new Area(new SquareInch(), 3)).Should().BeTrue(); }
public void LineSegmentList_SortSegments() { LineSegment segment1 = new LineSegment(MakePointWithInches(0, 1, 0), MakePointWithInches(0, 4, 2)); LineSegment segment2 = new LineSegment(MakePointWithInches(0, 1, 0), MakePointWithInches(3, 1, 0)); LineSegment segment3 = new LineSegment(MakePointWithInches(0, 4, 2), MakePointWithInches(3, 4, 2)); LineSegment segment4 = new LineSegment(MakePointWithInches(3, 1, 0), MakePointWithInches(3, 4, 2)); List<LineSegment> lineSegments = new List<LineSegment>() { segment1, segment2, segment3, segment4 }; List<LineSegment> sorted = lineSegments.FixSegmentOrientation(); (sorted[0] == segment1).Should().BeTrue(); (sorted[1] == segment3).Should().BeTrue(); (sorted[2] == new LineSegment(MakePointWithInches(3, 4, 2), MakePointWithInches(3, 1, 0))).Should().BeTrue(); (sorted[3] == new LineSegment(MakePointWithInches(3, 1, 0), MakePointWithInches(0, 1, 0))).Should().BeTrue(); }
public void Polygon_Extrude() { Point basePoint = Point.Origin; Point topLeftPoint = Point.MakePointWithInches(0, 4, 0); Point bottomRightPoint = Point.MakePointWithInches(8, 0, 0); Point topRightPoint = Point.MakePointWithInches(8, 4, 0); Point backbasepoint = Point.MakePointWithInches(0, 0, -4); Point backtopleftpoint = Point.MakePointWithInches(0, 4, -4); Point backbottomrightpoint = Point.MakePointWithInches(8, 0, -4); Point backtoprightpoint = Point.MakePointWithInches(8, 4, -4); LineSegment left = new LineSegment(basePoint, topLeftPoint); LineSegment right = new LineSegment(bottomRightPoint, topRightPoint); LineSegment top = new LineSegment(topLeftPoint, topRightPoint); LineSegment bottom = new LineSegment(basePoint, bottomRightPoint); LineSegment backLeft = new LineSegment(backbasepoint, backtopleftpoint); LineSegment backRight = new LineSegment(backbottomrightpoint, backtoprightpoint); LineSegment backTop = new LineSegment(backtopleftpoint, backtoprightpoint); LineSegment backBottom = new LineSegment(backbasepoint, backbottomrightpoint); LineSegment topleftConnector = new LineSegment(topLeftPoint, backtopleftpoint); LineSegment toprightConnector = new LineSegment(topRightPoint, backtoprightpoint); LineSegment baseConnector = new LineSegment(basePoint, backbasepoint); LineSegment bottomRightConnector = new LineSegment(bottomRightPoint, backbottomrightpoint); Polygon frontRegion = new Polygon(new List<LineSegment> { left, top, bottom, right }); Polygon backRegion = new Polygon(new List<LineSegment> { backLeft, backRight, backTop, backBottom }); Polygon topRegion = new Polygon(new List<LineSegment> { top, backTop, topleftConnector, toprightConnector }); Polygon bottomRegion = new Polygon(new List<LineSegment> { bottom, backBottom, baseConnector, bottomRightConnector }); Polygon leftRegion = new Polygon(new List<LineSegment> { left, backLeft, baseConnector, topleftConnector }); Polygon rightRegion = new Polygon(new List<LineSegment> { right, backRight, toprightConnector, bottomRightConnector }); Polyhedron extrudedResult = frontRegion.Extrude(new Vector(Point.MakePointWithInches(0, 0, -4))); extrudedResult.Polygons.Contains(frontRegion).Should().BeTrue(); extrudedResult.Polygons.Contains(backRegion).Should().BeTrue(); extrudedResult.Polygons.Contains(topRegion).Should().BeTrue(); extrudedResult.Polygons.Contains(bottomRegion).Should().BeTrue(); extrudedResult.Polygons.Contains(leftRegion).Should().BeTrue(); extrudedResult.Polygons.Contains(rightRegion).Should().BeTrue(); }
public void LineSegment_DoesIntersectNotTouchingPlane_ShouldReturnFalse_IfEndPointsAreOnTheSameSideOfThePlane() { LineSegment lineSegment = new LineSegment(Point.MakePointWithInches(1, 1, 1), Point.MakePointWithInches(2, 2, 2)); Plane plane = new Plane(Direction.Right); lineSegment.DoesIntersectNotTouching(plane).Should().BeFalse(); }
public void LineSegment_Overlaps_ShouldThrowException_IfSegmentIsNull() { LineSegment lineSegment1 = new LineSegment(Point.MakePointWithInches(1, 1, 1)); LineSegment lineSegment2 = null; Action overlaps = () => lineSegment1.Overlaps(lineSegment2); overlaps.ShouldThrow<Exception>(); }
public void LineSegment_Overlaps_ShouldReturnFalse_IfSegmentsAreParallelButNoEndPointsAreOnTheInsideOfTheOtherSegment() { LineSegment lineSegment1 = new LineSegment(Point.MakePointWithInches(1, 1, 1)); LineSegment lineSegment2 = new LineSegment(Point.MakePointWithInches(1, 1, 1), Point.MakePointWithInches(2, 2, 2)); lineSegment1.Overlaps(lineSegment2).Should().BeFalse(); }
public void LineSegment_Overlaps_ShouldReturnTrue_IfSegmentsAreEqual() { LineSegment lineSegment1 = new LineSegment(Point.MakePointWithInches(1, 1, 1)); LineSegment lineSegment2 = new LineSegment(Point.MakePointWithInches(1, 1, 1)); lineSegment1.Overlaps(lineSegment2).Should().BeTrue(); }
public void LineSegment_OverlappingSegment_ShouldReturnNull_IfOnlyOneEndPointInCommon() { LineSegment lineSegment1 = new LineSegment(Point.MakePointWithInches(1, 1, 1)); LineSegment lineSegment2 = new LineSegment(Point.MakePointWithInches(1, 1, 1), Point.MakePointWithInches(2, 2, 2)); lineSegment1.OverlappingSegment(lineSegment2).Should().BeNull(); }
public void LineSegment_ConstructorVector_ShouldCreateLineSegmentFromVector() { LineSegment lineSegment = new LineSegment(new Vector(Point.MakePointWithInches(1, 1, 1))); lineSegment.Should().Be(new LineSegment(Point.Origin, Point.MakePointWithInches(1, 1, 1))); }
public void LineSegment_ProjectOntoPlane_ShouldThrowException_IfPlaneIsNull() { LineSegment lineSegment = new LineSegment(Point.MakePointWithInches(1, 1, 1)); Plane plane = null; Action project = () => lineSegment.ProjectOntoPlane(plane); project.ShouldThrow<Exception>(); }
public void LineSegment_ProjectOntoPlane_ShouldReturnVectorProjection_IfVectorLengthIsNotZero() { LineSegment lineSegment = new LineSegment(Point.MakePointWithInches(1, 1, 1)); Plane plane = new Plane(Direction.Right); Vector vector = new Vector(lineSegment.BasePoint, lineSegment.EndPoint); lineSegment.ProjectOntoPlane(plane).Should().Be(new LineSegment(vector.ProjectOntoPlane(plane))); }
public void LineSegment_OverlappingSegment_ShouldReturnNull_IfOnlyInstanceEndPointIsOnPassedSegment() { LineSegment lineSegment1 = new LineSegment(Point.MakePointWithInches(0, 2, 0), Point.MakePointWithInches(1, 1, 1)); LineSegment lineSegment2 = new LineSegment(Point.MakePointWithInches(2, 2, 2)); lineSegment1.OverlappingSegment(lineSegment2).Should().BeNull(); }
public void LineSegment_OverlappingSegment_ShouldReturnIntersection_IfBothInstancePointsAreOnInsideOfPassedSegment() { LineSegment lineSegment1 = new LineSegment(Point.MakePointWithInches(1, 1, 1), Point.MakePointWithInches(2, 2, 2)); LineSegment lineSegment2 = new LineSegment(Point.MakePointWithInches(3, 3, 3)); lineSegment1.OverlappingSegment(lineSegment2).Should().Be(new LineSegment(Point.MakePointWithInches(1, 1, 1), Point.MakePointWithInches(2, 2, 2))); }
public void LineSegment_Reverse_ShouldReturnReversedLineSegment() { LineSegment lineSegment = new LineSegment(Point.MakePointWithInches(1, 1, 1)); lineSegment.Should().Be(new LineSegment(Point.MakePointWithInches(1, 1, 1), Point.MakePointWithInches(0, 0, 0))); }
public void LineSegment_OverlappingSegment_ShouldReturnIntersection_IfPassedTwoEndPointsAreTheSame() { LineSegment lineSegment1 = new LineSegment(Point.MakePointWithInches(3, 3, 3)); LineSegment lineSegment2 = new LineSegment(Point.MakePointWithInches(2, 2, 2)); lineSegment1.OverlappingSegment(lineSegment2).Should().Be(new LineSegment(Point.MakePointWithInches(2, 2, 2))); }
public void LineSegment_Rotate_ShouldRotateAsVector() { LineSegment lineSegment1 = new LineSegment(Point.MakePointWithInches(1, 0, 0)); Rotation rotation = new Rotation(new Angle(45, Angle.Degrees)); LineSegment lineSegment2 = lineSegment1.Rotate(rotation); lineSegment2.Should().Be(new LineSegment(Point.Origin, new Direction(rotation.RotationAngle), new Distance(Distance.Inches, 1))); }
public void LineSegment_OverlappingSegment_ShouldThrowException_IfPassedSegmentIsNull() { LineSegment lineSegment1 = new LineSegment(Point.MakePointWithInches(1, 1, 1)); LineSegment lineSegment2 = null; Action intersection = () => lineSegment1.OverlappingSegment(lineSegment2); intersection.ShouldThrow<Exception>(); }
public void LineSegment_Rotate_ShouldThrowException_IfRotationIsNull() { LineSegment lineSegment = new LineSegment(Point.MakePointWithInches(1, 0, 0)); Rotation rotation = null; Action rotate = () => lineSegment.Rotate(rotation); rotate.ShouldThrow<Exception>(); }
public void LineSegment_Overlaps_ShouldReturnFalse_IfSegmentsAreNotParallel() { LineSegment lineSegment1 = new LineSegment(Point.MakePointWithInches(2, 2, 2)); LineSegment lineSegment2 = new LineSegment(Point.MakePointWithInches(1, 1, 1), Point.MakePointWithInches(0, 2, 0)); lineSegment1.Overlaps(lineSegment2).Should().BeFalse(); }
public void LineSegment_Shift_ShouldShiftAsVector() { LineSegment lineSegment = new LineSegment(Point.MakePointWithInches(1, 1, 1)); Shift shift1 = new Shift(new Vector(Point.MakePointWithInches(0, 1, 0))); Shift shift2 = new Shift(new Vector(Point.MakePointWithInches(2, 0, 3))); Shift shift3 = Shift.Compose(shift1, shift2); lineSegment.Shift(shift3).Should().Be(new LineSegment(Point.MakePointWithInches(2, 1, 3), Point.MakePointWithInches(3, 2, 4))); }
public void LineSegment_Overlaps_ShouldReturnTrue_IfSegmentsAreParallelAndAnyEndpointsAreOnTheInsideOfTheOtherSegment() { LineSegment lineSegment1 = new LineSegment(Point.MakePointWithInches(3, 3, 3)); LineSegment lineSegment2 = new LineSegment(Point.MakePointWithInches(1, 1, 1), Point.MakePointWithInches(2, 2, 2)); lineSegment1.Overlaps(lineSegment2).Should().BeTrue(); }
public void LineSegment_Shift_ShouldThrowException_IfShiftIsNull() { LineSegment lineSegment = new LineSegment(Point.MakePointWithInches(1, 1, 1)); Shift shift = null; Action shiftAction = () => lineSegment.Shift(shift); shiftAction.ShouldThrow<Exception>(); }
public void LineSegment_DoesIntersectNotTouchingPlane_ShouldReturnFalse_IfBothEndPointsAreOnPlane() { LineSegment lineSegment = new LineSegment(Point.MakePointWithInches(1, 0, 0)); Plane plane = new Plane(Direction.Right); lineSegment.DoesIntersectNotTouching(plane).Should().BeFalse(); }
public void LineSegment_Translate_ShouldTranslateAsVector() { LineSegment lineSegment = new LineSegment(Point.MakePointWithInches(1, 1, 1)); Translation translation = new Translation(new Vector(Point.MakePointWithInches(0, 1, 0))); lineSegment.Translate(translation).Should().Be(new LineSegment(Point.MakePointWithInches(0, 1, 0), Point.MakePointWithInches(1, 2, 1))); }
public void LineSegment_DoesIntersectNotTouchingPlane_ShouldReturnTrue_IfEndPointsAreOnOppositeSidesOfThePlane() { LineSegment lineSegment = new LineSegment(Point.MakePointWithInches(1, 1, 1), Point.MakePointWithInches(-1, -1, -1)); Plane plane = new Plane(Direction.Right); lineSegment.DoesIntersectNotTouching(plane).Should().BeTrue(); }
public void LineSegment_Translate_ShouldThrowException_IfTranslateIsNull() { LineSegment lineSegment = new LineSegment(Point.MakePointWithInches(1, 1, 1)); Translation translation = null; Action translate = () => lineSegment.Shift(translation); translate.ShouldThrow<Exception>(); }