/// <summary> /// 线圈所在外包矩形 /// </summary> /// <returns></returns> static public Polygon2d BoundingRectangle(this Polygon2d polygon2d) { //【】下方注释方法的时间需要进行测试 //Box2d box2D = polygon2d.MinimalBoundingBox(double epsilon) double wight = 0; double height = 0; Vector2d center = polygon2d.Center(ref wight, ref height); return(Polygon2d.MakeRectangle(center, wight, height)); }
public void TrimSegment2d_SegmentEndsOutside() { // Arrange var square = new GeneralPolygon2d(Polygon2d.MakeRectangle(new Vector2d(-1, 0), new Vector2d(1, 1))); var seg = new Segment2d(new Vector2d(0, -1), new Vector2d(0, 2)); // Act var result = square.TrimSegment2d(seg); // Assert Assert.AreEqual(1, result.Count); AssertExtensions.AreEqual(new Vector2d(0, 0), result[0].P0); AssertExtensions.AreEqual(new Vector2d(0, 1), result[0].P1); }
public void TrimSegment2d_SegmentEndsPartial() { // Arrange var square = new GeneralPolygon2d(Polygon2d.MakeRectangle(new Vector2d(-1, 0), new Vector2d(1, 1))); var seg = new Segment2d(new Vector2d(0, 0.1), new Vector2d(0, 2)); // Act var result = square.TrimSegment2d(seg); // Assert Assert.AreEqual(1, result.Count); Assert.IsTrue(new Vector2d(0, 0.1).EpsilonEqual(result[0].P0, Epsilon)); Assert.IsTrue(new Vector2d(0, 1).EpsilonEqual(result[0].P1, Epsilon)); }
public void TrimSegment2d_SegmentAcrossHole() { // Arrange var square = new GeneralPolygon2d(Polygon2d.MakeRectangle(new Vector2d(0, 0), 4, 4)); var hole = Polygon2d.MakeRectangle(new Vector2d(0, 0), 2, 2); hole.Reverse(); square.AddHole(hole); var seg = new Segment2d(new Vector2d(0, -4), new Vector2d(0, 4)); // Act var result = square.TrimSegment2d(seg); // Assert Assert.AreEqual(2, result.Count); AssertExtensions.AreEqual(new Vector2d(0, -2), result[0].P0); AssertExtensions.AreEqual(new Vector2d(0, -1), result[0].P1); AssertExtensions.AreEqual(new Vector2d(0, 1), result[1].P0); AssertExtensions.AreEqual(new Vector2d(0, 2), result[1].P1); }