public void SplitEllipticalArcReversed() { var sketch = Sketch.Create(); int p1 = sketch.AddPoint(new Pnt2d(-2, 5)); int p2 = sketch.AddPoint(new Pnt2d(2, 1)); int pc = sketch.AddPoint(new Pnt2d(0, 0)); int s1 = sketch.AddSegment(new SketchSegmentEllipticalArc(p1, p2, pc)); (int p3, int[] segs) = SketchUtils.SplitSegment(sketch, sketch.Segments[s1], Maths.PI * 0.25); Assert.AreNotEqual(SketchUtils.SplitSegmentFailed, (p3, segs)); Assert.AreEqual(12, sketch.Points.Count); Assert.AreEqual(4, sketch.Segments.Count); Assert.IsInstanceOf <SketchSegmentEllipticalArc>(sketch.Segments[segs[0]]); Assert.That(sketch.Segments[segs[0]].Points.SequenceEqual(new[] { p1, p3, pc })); Assert.IsInstanceOf <SketchSegmentBezier>(sketch.Segments[segs[1]]); Assert.That(sketch.Segments[segs[1]].Points.SequenceEqual(new[] { p3, p3 + 1, p3 + 2, p3 + 3 })); Assert.IsInstanceOf <SketchSegmentBezier>(sketch.Segments[segs[2]]); Assert.That(sketch.Segments[segs[2]].Points.SequenceEqual(new[] { p3 + 3, p3 + 4, p3 + 5, p3 + 6 })); Assert.IsInstanceOf <SketchSegmentBezier>(sketch.Segments[segs[3]]); Assert.That(sketch.Segments[segs[3]].Points.SequenceEqual(new[] { p3 + 6, p3 + 7, p3 + 8, p2 })); Assert.IsTrue(sketch.Make(Shape.MakeFlags.None)); ModelCompare.CompareShape2D(sketch, Path.Combine(_BasePath, "SplitEllipticalArcReversed")); }
public void SplitCircle() { var sketch = Sketch.Create(); int p1 = sketch.AddPoint(new Pnt2d(0, 0)); int p2 = sketch.AddPoint(new Pnt2d(10, 0)); int s1 = sketch.AddSegment(new SketchSegmentCircle(p1, p2)); (int p3, int[] segs) = SketchUtils.SplitSegment(sketch, sketch.Segments[s1], Maths.PI); Assert.AreNotEqual(SketchUtils.SplitSegmentFailed, (p3, segs)); Assert.AreEqual(4, sketch.Points.Count); Assert.That(new Pnt2d(-10.0, 0).IsEqual(sketch.Points[p3], 0.01)); Assert.AreEqual(2, sketch.Segments.Count); Assert.IsInstanceOf <SketchSegmentArc>(sketch.Segments[segs[0]]); Assert.That(sketch.Segments[segs[0]].Points.SequenceEqual(new[] { p2, p3, p3 + 1 })); Assert.IsInstanceOf <SketchSegmentArc>(sketch.Segments[segs[1]]); Assert.That(sketch.Segments[segs[1]].Points.SequenceEqual(new[] { p3, p2, p3 + 2 })); Assert.IsTrue(sketch.Make(Shape.MakeFlags.None)); ModelCompare.CompareShape2D(sketch, Path.Combine(_BasePath, "SplitCircle")); }
public void SplitBezier2() { var sketch = Sketch.Create(); int p1 = sketch.AddPoint(new Pnt2d(-2, 0)); int p2 = sketch.AddPoint(new Pnt2d(0.5, 5)); int p3 = sketch.AddPoint(new Pnt2d(3, 2)); int s1 = sketch.AddSegment(new SketchSegmentBezier(p1, p2, p3)); (int ps, int[] segs) = SketchUtils.SplitSegment(sketch, sketch.Segments[s1], 0.3); Assert.AreNotEqual(SketchUtils.SplitSegmentFailed, (ps, segs)); Assert.AreEqual(5, sketch.Points.Count); Assert.AreEqual(2, sketch.Segments.Count); Assert.IsInstanceOf <SketchSegmentBezier>(sketch.Segments[segs[0]]); Assert.That(sketch.Segments[segs[0]].Points.SequenceEqual(new[] { p1, ps + 1, ps })); Assert.IsInstanceOf <SketchSegmentBezier>(sketch.Segments[segs[1]]); Assert.That(sketch.Segments[segs[1]].Points.SequenceEqual(new[] { ps, ps + 2, p3 })); Assert.IsTrue(sketch.Make(Shape.MakeFlags.None)); ModelCompare.CompareShape2D(sketch, Path.Combine(_BasePath, "SplitBezier2")); }
public void SplitEllipse() { var sketch = Sketch.Create(); int p1 = sketch.AddPoint(new Pnt2d(2, 1)); int p2 = sketch.AddPoint(new Pnt2d(1.5, 3)); int pc = sketch.AddPoint(new Pnt2d(0, 0)); int s1 = sketch.AddSegment(new SketchSegmentEllipse(pc, p1, p2)); (int p3, int[] segs) = SketchUtils.SplitSegment(sketch, sketch.Segments[s1], Maths.HalfPI); Assert.AreNotEqual(SketchUtils.SplitSegmentFailed, (p3, segs)); Assert.AreEqual(3, sketch.Points.Count); Assert.AreEqual(2, sketch.Segments.Count); Assert.IsInstanceOf <SketchSegmentEllipticalArc>(sketch.Segments[segs[0]]); Assert.That(sketch.Segments[segs[0]].Points.SequenceEqual(new[] { p2, p3, pc })); Assert.IsInstanceOf <SketchSegmentEllipticalArc>(sketch.Segments[segs[1]]); Assert.That(sketch.Segments[segs[1]].Points.SequenceEqual(new[] { p3, p2, pc })); Assert.IsTrue(sketch.Make(Shape.MakeFlags.None)); ModelCompare.CompareShape2D(sketch, Path.Combine(_BasePath, "SplitEllipse")); }
public void SplitEllipticalArc() { var sketch = Sketch.Create(); int p1 = sketch.AddPoint(new Pnt2d(2, 1)); int p2 = sketch.AddPoint(new Pnt2d(-2, 5)); int pc = sketch.AddPoint(new Pnt2d(0, 0)); int s1 = sketch.AddSegment(new SketchSegmentEllipticalArc(p1, p2, pc)); (int p3, int[] segs) = SketchUtils.SplitSegment(sketch, sketch.Segments[s1], Maths.PI * 1.75); Assert.AreNotEqual(SketchUtils.SplitSegmentFailed, (p3, segs)); Assert.AreEqual(6, sketch.Points.Count); Assert.AreEqual(2, sketch.Segments.Count); Assert.IsInstanceOf <SketchSegmentEllipticalArc>(sketch.Segments[segs[0]]); CollectionAssert.AreEqual(new[] { p3, p2, pc }, sketch.Segments[segs[0]].Points); Assert.IsInstanceOf <SketchSegmentBezier>(sketch.Segments[segs[1]]); CollectionAssert.AreEqual(new[] { p1, p3 + 1, p3 + 2, p3 }, sketch.Segments[segs[1]].Points); Assert.IsTrue(sketch.Make(Shape.MakeFlags.None)); ModelCompare.CompareShape2D(sketch, Path.Combine(_BasePath, "SplitEllipticalArc")); }
public void SplitLine() { var sketch = Sketch.Create(); int p1 = sketch.AddPoint(new Pnt2d(0, 0)); int p2 = sketch.AddPoint(new Pnt2d(10, 0)); int s1 = sketch.AddSegment(new SketchSegmentLine(p1, p2)); (int p3, int[] segs) = SketchUtils.SplitSegment(sketch, sketch.Segments[s1], 5.0); Assert.AreNotEqual(SketchUtils.SplitSegmentFailed, (p3, segs)); Assert.AreEqual(3, sketch.Points.Count); Assert.That(new Pnt2d(5.0, 0).IsEqual(sketch.Points[p3], 0.01)); Assert.AreEqual(2, sketch.Segments.Count); Assert.IsInstanceOf <SketchSegmentLine>(sketch.Segments[segs[0]]); CollectionAssert.AreEqual(new[] { p1, p3 }, sketch.Segments[segs[0]].Points); Assert.IsInstanceOf <SketchSegmentLine>(sketch.Segments[segs[1]]); CollectionAssert.AreEqual(new[] { p3, p2 }, sketch.Segments[segs[1]].Points); Assert.IsTrue(sketch.Make(Shape.MakeFlags.None)); ModelCompare.CompareShape2D(sketch, Path.Combine(_BasePath, "SplitLine")); }
public void SplitArcReverse() { var sketch = Sketch.Create(); int p1 = sketch.AddPoint(new Pnt2d(0, 0)); int p2 = sketch.AddPoint(new Pnt2d(-5, 3)); int pr = sketch.AddPoint(new Pnt2d(-2, 3)); int s1 = sketch.AddSegment(new SketchSegmentArc(p1, p2, pr)); (int p3, int[] segs) = SketchUtils.SplitSegment(sketch, sketch.Segments[s1], Maths.PI * 0.25); Assert.AreNotEqual(SketchUtils.SplitSegmentFailed, (p3, segs)); Assert.AreEqual(5, sketch.Points.Count); Assert.AreEqual(2, sketch.Segments.Count); Assert.IsInstanceOf <SketchSegmentArc>(sketch.Segments[segs[0]]); CollectionAssert.AreEqual(new[] { p1, p3, p3 + 1 }, sketch.Segments[segs[0]].Points); Assert.IsInstanceOf <SketchSegmentArc>(sketch.Segments[segs[1]]); CollectionAssert.AreEqual(new[] { p3, p2, p3 + 2 }, sketch.Segments[segs[1]].Points); Assert.IsTrue(sketch.Make(Shape.MakeFlags.None)); ModelCompare.CompareShape2D(sketch, Path.Combine(_BasePath, "SplitArcReverse")); }