public void WeldPointsWithLineSegment() { var sketch = Sketch.Create(); var sb = new SketchBuilder(sketch); sb.Line(0.0, 0.0, 10.0, 0.0); // 0, 1, s0 sb.Line(5.0, 0.0, 5.0, 5.0); // 2, 3, s1 sb.Line(6.0, 0.0, 5.0, 5.0); // 4, 5, s2 Assert.IsTrue(SketchUtils.WeldPointsWithSegments(sketch, new[] { sketch.Segments[0] }, new[] { 2, 4 })); Assert.AreEqual(6, sketch.Points.Count); Assert.AreEqual(5, sketch.Segments.Count); Assert.AreEqual(6, sketch.Segments[1].StartPoint); Assert.AreEqual(3, sketch.Segments[1].EndPoint); Assert.AreEqual(7, sketch.Segments[2].StartPoint); Assert.AreEqual(5, sketch.Segments[2].EndPoint); Assert.AreEqual(0, sketch.Segments[3].StartPoint); Assert.AreEqual(6, sketch.Segments[3].EndPoint); Assert.AreEqual(6, sketch.Segments[5].StartPoint); Assert.AreEqual(7, sketch.Segments[5].EndPoint); Assert.AreEqual(7, sketch.Segments[6].StartPoint); Assert.AreEqual(1, sketch.Segments[6].EndPoint); Assert.IsTrue(sketch.Points[6].IsEqual(new Pnt2d(5.0, 0.0), 0.01)); Assert.IsTrue(sketch.Points[7].IsEqual(new Pnt2d(6.0, 0.0), 0.01)); }
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")); }
/// <summary> /// 创建草绘 /// </summary> /// <param name="waiLine"></param> /// <param name="leiLine"></param> private void CreateEleSketch() { Tag sketchTag = SketchUtils.CreateShetch(zSetValue); this.WaiLine = CreateRectangle(this.preparationLength, this.preparationWigth, this.zSetValue); this.LeiLine = CreateRectangle(this.preparationLength - 2, this.preparationWigth - 2, this.zSetValue); Line[] centerLine = CreateCenterLine(this.zSetValue); Line[] centerLine2 = CreateCenterLine(0); this.Center = CreateCenter(zSetValue); SetLineObj(254, centerLine); SetLineObj(1, centerLine2); SetLineName("XCenterLine", centerLine2[0]); SetLineName("YCenterLine", centerLine2[1]); SketchUtils.AddShetch(sketchTag, this.WaiLine); SketchUtils.AddShetch(sketchTag, this.LeiLine); SketchUtils.AddShetch(sketchTag, centerLine); SketchUtils.AddShetch(sketchTag, Center); SetSketchConstraint(centerLine); SetSketch(this.WaiLine, centerLine, "0"); SetSketch(this.LeiLine, centerLine, "DatumWidth"); theUFSession.Sket.UpdateSketch(sketchTag); theUFSession.Sket.TerminateSketch(); // SetCenterPoint(); theUFSession.Obj.SetLayer(sketchTag, 254); theUFSession.Obj.SetLayer(Center.Tag, 254); DisplayableObject[] disp = workPart.Datums.ToArray(); for (int i = 0; i < disp.Length; i++) { theUFSession.Obj.SetLayer(disp[i].Tag, 254); } }
//-------------------------------------------------------------------------------------------------- public override void OnPointsChanged(Dictionary <int, Pnt2d> points, Dictionary <int, SketchSegment> segments, Dictionary <int, int> markerCounts = default) { var point = points[PointIndex]; var geomPoint = new Geom_CartesianPoint(point.X, point.Y, 0); geomPoint.Transform(Transform); _Marker.Set(geomPoint); _Marker.SetImage(SketchUtils.IsUnconnectedEndpoint(SketchEditorTool.Sketch, PointIndex) ? Marker.RectImage : Marker.BallImage); }
//-------------------------------------------------------------------------------------------------- public override void Delete() { SelectedConstraints.ForEach(c => Sketch.DeleteConstraint(c)); SelectedSegments.ForEach(s => Sketch.DeleteSegment(s)); SelectedPoints.ForEach(p => SketchUtils.DeletePointTrySubstituteSegments(Sketch, p)); Sketch.SolveConstraints(true); InteractiveContext.Current.UndoHandler.Commit(); Select(null, null); }
public void SplitBezier_IncorrectParameters() { 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)); Assert.AreEqual(SketchUtils.SplitSegmentFailed, SketchUtils.SplitSegment(sketch, sketch.Segments[s1], 0.0)); Assert.AreEqual(SketchUtils.SplitSegmentFailed, SketchUtils.SplitSegment(sketch, sketch.Segments[s1], 1.0)); }
public void SplitEllipticalArc_IncorrectParameters() { 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)); Assert.AreEqual(SketchUtils.SplitSegmentFailed, SketchUtils.SplitSegment(sketch, sketch.Segments[s1], 0.0)); Assert.AreEqual(SketchUtils.SplitSegmentFailed, SketchUtils.SplitSegment(sketch, sketch.Segments[s1], Maths.DoublePI)); }
public SketchEditorPointElement(SketchEditorTool sketchEditorTool, int pointIndex, Pnt2d point, Trsf transform, Pln plane) : base(sketchEditorTool, transform, plane) { PointIndex = pointIndex; var geomPoint = new Geom_CartesianPoint(point.X, point.Y, 0); geomPoint.Transform(Transform); _Marker = new Marker(SketchEditorTool.WorkspaceController, Marker.Styles.Bitmap | Marker.Styles.Topmost | Marker.Styles.Selectable, SketchUtils.IsUnconnectedEndpoint(SketchEditorTool.Sketch, PointIndex) ? Marker.RectImage : Marker.BallImage); _Marker.Set(geomPoint); }
public void SplitCircle_IncorrectParameters() { 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)); // U is on rim point Assert.AreEqual(SketchUtils.SplitSegmentFailed, SketchUtils.SplitSegment(sketch, sketch.Segments[s1], 0.0)); Assert.AreEqual(SketchUtils.SplitSegmentFailed, SketchUtils.SplitSegment(sketch, sketch.Segments[s1], Maths.DoublePI)); Assert.AreEqual(SketchUtils.SplitSegmentFailed, SketchUtils.SplitSegment(sketch, sketch.Segments[s1], -Maths.DoublePI)); }
public void ConvertBezier3ToBezier() { 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(2, 3)); int p4 = sketch.AddPoint(new Pnt2d(3, 2)); var s1 = new SketchSegmentBezier(p1, p2, p3, p4); sketch.AddSegment(s1); Assert.IsFalse(SketchUtils.CanConvertSegment(sketch, s1, typeof(SketchSegmentBezier))); }
public void SplitArc_IncorrectParameters() { 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)); // U is on rim point Assert.AreEqual(SketchUtils.SplitSegmentFailed, SketchUtils.SplitSegment(sketch, sketch.Segments[s1], 0.0)); Assert.AreEqual(SketchUtils.SplitSegmentFailed, SketchUtils.SplitSegment(sketch, sketch.Segments[s1], -0.5)); Assert.AreEqual(SketchUtils.SplitSegmentFailed, SketchUtils.SplitSegment(sketch, sketch.Segments[s1], 2.0)); }
public void SplitEllipse_IncorrectParameters() { 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)); // U is on major x axis Assert.AreEqual(SketchUtils.SplitSegmentFailed, SketchUtils.SplitSegment(sketch, sketch.Segments[s1], 0.0)); Assert.AreEqual(SketchUtils.SplitSegmentFailed, SketchUtils.SplitSegment(sketch, sketch.Segments[s1], Maths.DoublePI)); Assert.AreEqual(SketchUtils.SplitSegmentFailed, SketchUtils.SplitSegment(sketch, sketch.Segments[s1], -Maths.DoublePI)); }
public void WeldCurvedSegments() { var sketch = Sketch.Create(); var sb = new SketchBuilder(sketch); sb.Arc(0.0, 0.0, 10.0, 0.0, 5.0, 5.0); // 0, 1, 2 s0 sb.Arc(0.0, 5.0, 10.0, 5.0, 5.0, 0.0); // 2, 3, 4 s1 Assert.IsTrue(SketchUtils.WeldSegments(sketch, new[] { sketch.Segments[0], sketch.Segments[1] })); Assert.AreEqual(12, sketch.Points.Count); Assert.AreEqual(6, sketch.Segments.Count); }
public void SplitPoint() { var sketch = TestSketchGenerator.CreateSketch(TestSketchGenerator.SketchType.Rectangle); Assert.IsTrue(SketchUtils.CanSplitPoint(sketch, 0)); var newPoints = SketchUtils.SplitPoint(sketch, 0); Assert.That(newPoints.SequenceEqual(new[] { 4 })); Assert.AreEqual(5, sketch.Points.Count); Assert.AreEqual(4, sketch.Segments[0].StartPoint); Assert.AreEqual(0, sketch.Segments[3].EndPoint); Assert.IsFalse(SketchUtils.CanSplitPoint(sketch, 0)); }
public void DeletePointLineLine() { var sketch = Sketch.Create(); int p1 = sketch.AddPoint(new Pnt2d(0, 0)); int p2 = sketch.AddPoint(new Pnt2d(10, 0)); int p3 = sketch.AddPoint(new Pnt2d(20, 0)); int s1 = sketch.AddSegment(new SketchSegmentLine(p1, p2)); int s2 = sketch.AddSegment(new SketchSegmentLine(p2, p3)); SketchUtils.DeletePointTrySubstituteSegments(sketch, p2); Assert.AreEqual(2, sketch.Points.Count); Assert.AreEqual(1, sketch.Segments.Count); Assert.AreEqual(p1, sketch.Segments[s2 + 1].StartPoint); Assert.AreEqual(p3, sketch.Segments[s2 + 1].EndPoint); }
public void WeldPoints_IncorrectParameters() { var sketch = Sketch.Create(); var sb = new SketchBuilder(sketch); sb.Line(1.0, 1.0, 2.0, 2.0); // 0, 1 sb.Line(1.0, 1.0, -2.0, -2.0); // 2, 3 sb.Line(1.2, 1.2, -2.0, 2.0); // 4, 5 Assert.IsFalse(SketchUtils.WeldPoints(sketch, new[] { 0 })); Assert.AreEqual(6, sketch.Points.Count); Assert.IsTrue(SketchUtils.WeldPoints(sketch, new[] { 0, 2, 0 })); Assert.AreEqual(5, sketch.Points.Count); }
public void WeldPointsRemoveSegments() { var sketch = Sketch.Create(); var sb = new SketchBuilder(sketch); sb.Line(0.0, 0.0, 0.0, 1.0); // 0, 1 sb.Line(1.0, 0.0, 1.0, 1.0); // 2, 3 sketch.AddSegment(new SketchSegmentLine(0, 2)); sketch.AddSegment(new SketchSegmentLine(3, 1)); Assert.IsTrue(SketchUtils.WeldPoints(sketch, new[] { 0, 1 })); Assert.AreEqual(3, sketch.Points.Count); Assert.AreEqual(3, sketch.Segments.Count); }
public void SplitLine_IncorrectParameters() { 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 s2 = sketch.AddSegment(new SketchSegmentLine(p2, p1)); // U is out of bound Assert.AreEqual(SketchUtils.SplitSegmentFailed, SketchUtils.SplitSegment(sketch, sketch.Segments[s1], -1.0)); Assert.AreEqual(SketchUtils.SplitSegmentFailed, SketchUtils.SplitSegment(sketch, sketch.Segments[s1], 0.0)); Assert.AreEqual(SketchUtils.SplitSegmentFailed, SketchUtils.SplitSegment(sketch, sketch.Segments[s1], 10.0)); Assert.AreEqual(SketchUtils.SplitSegmentFailed, SketchUtils.SplitSegment(sketch, sketch.Segments[s1], 11.0)); Assert.AreEqual(SketchUtils.SplitSegmentFailed, SketchUtils.SplitSegment(sketch, sketch.Segments[s2], -1.0)); Assert.AreEqual(SketchUtils.SplitSegmentFailed, SketchUtils.SplitSegment(sketch, sketch.Segments[s2], 11.0)); }
public void DeletePointBezierBezier() { 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 p4 = sketch.AddPoint(new Pnt2d(5.5, 5)); int p5 = sketch.AddPoint(new Pnt2d(8, 0)); int s2 = sketch.AddSegment(new SketchSegmentBezier(p3, p4, p5)); SketchUtils.DeletePointTrySubstituteSegments(sketch, p3); Assert.AreEqual(3, sketch.Points.Count); Assert.AreEqual(1, sketch.Segments.Count); Assert.AreEqual(p1, sketch.Segments[s2 + 1].StartPoint); Assert.AreEqual(p5, sketch.Segments[s2 + 1].EndPoint); }
/// <summary> /// 创建尺寸约束 /// </summary> /// <param name="rectangle"></param> /// <param name="center"></param> /// <param name="i"></param> private void SetSketch(Line[] rectangle, Line[] center, string width) { Point3d dimOrigin = new Point3d(0, 0, 0); Expression ex1 = SketchUtils.CreateDim(center[0], rectangle[0], dimOrigin, NXOpen.Annotations.DimensionMeasurementBuilder.MeasurementMethod.Vertical, InferSnapType.SnapType.Origin); Expression ex2 = SketchUtils.CreateDim(center[0], rectangle[2], dimOrigin, NXOpen.Annotations.DimensionMeasurementBuilder.MeasurementMethod.Vertical, InferSnapType.SnapType.Origin); ex1.RightHandSide = "PreparationY/2-" + width; ex2.RightHandSide = "PreparationY/2-" + width; Expression ex3 = SketchUtils.CreateDim(center[1], rectangle[1], dimOrigin, NXOpen.Annotations.DimensionMeasurementBuilder.MeasurementMethod.Horizontal, InferSnapType.SnapType.Origin); Expression ex4 = SketchUtils.CreateDim(center[1], rectangle[3], dimOrigin, NXOpen.Annotations.DimensionMeasurementBuilder.MeasurementMethod.Horizontal, InferSnapType.SnapType.Origin); ex3.RightHandSide = "PreparationX/2-" + width; ex4.RightHandSide = "PreparationX/2-" + width; }
public void WeldPointWithLineSegments() { var sketch = Sketch.Create(); var sb = new SketchBuilder(sketch); sb.Line(0.0, 0.0, 10.0, 0.0); // 0, 1, s0 sb.Line(5.0, 0.0, 5.0, 5.0); // 2, 3, s1 sb.Line(0.0, 0.1, 10.0, 0.1); // 4, 5, s2 - Parallel line segment Assert.IsTrue(SketchUtils.WeldPointsWithSegments(sketch, new[] { sketch.Segments[0], sketch.Segments[2] }, new[] { 2 })); Assert.AreEqual(6, sketch.Points.Count); Assert.AreEqual(4, sketch.Segments.Count); Assert.IsFalse(sketch.Segments.ContainsKey(0)); Assert.IsTrue(sketch.Segments.ContainsKey(1)); Assert.IsTrue(sketch.Points[6].IsEqual(new Pnt2d(5.0, 0.0), 0.01)); }
public void WeldPointWithSegment_IncorrectParameters() { var sketch = Sketch.Create(); var sb = new SketchBuilder(sketch); sb.Line(0.0, 0.0, 10.0, 0.0); // 0, 1, s0 Assert.IsFalse(SketchUtils.WeldPointsWithSegments(sketch, new[] { sketch.Segments[0] }, new[] { 0 })); Assert.AreEqual(2, sketch.Points.Count); Assert.AreEqual(1, sketch.Segments.Count); Assert.IsFalse(SketchUtils.WeldPointsWithSegments(sketch, new SketchSegment[] { }, new[] { 0 })); Assert.AreEqual(2, sketch.Points.Count); Assert.AreEqual(1, sketch.Segments.Count); Assert.IsFalse(SketchUtils.WeldPointsWithSegments(sketch, new[] { sketch.Segments[0] }, new int[] { })); Assert.AreEqual(2, sketch.Points.Count); Assert.AreEqual(1, sketch.Segments.Count); }
public void WeldOverlapSegments(int segOrder) { var sketch = Sketch.Create(); var sb = new SketchBuilder(sketch); sb.Line(0.0, 0.0, 10.0, 0.0); // 0, 1, s0 sb.Line(2.5, 0.0, 7.5, 0.0); // 2, 3, s1 Assert.IsTrue(SketchUtils.WeldSegments(sketch, new[] { sketch.Segments[0 + segOrder], sketch.Segments[1 - segOrder] })); Assert.AreEqual(4, sketch.Points.Count); Assert.AreEqual(3, sketch.Segments.Count); Assert.AreEqual(0, sketch.Segments[2].StartPoint); Assert.AreEqual(4, sketch.Segments[2].EndPoint); Assert.AreEqual(4, sketch.Segments[4].StartPoint); Assert.AreEqual(5, sketch.Segments[4].EndPoint); Assert.AreEqual(5, sketch.Segments[5].StartPoint); Assert.AreEqual(1, sketch.Segments[5].EndPoint); }
public void WeldLineSegmentsInOnePoint(int segOrder) { var sketch = Sketch.Create(); var sb = new SketchBuilder(sketch); sb.Line(0.0, 0.0, 10.0, 0.0); // 0, 1, s0 sb.Line(5.0, 0.0, 5.0, 5.0); // 2, 3, s1 Assert.IsTrue(SketchUtils.WeldSegments(sketch, new[] { sketch.Segments[0 + segOrder], sketch.Segments[1 - segOrder] })); Assert.AreEqual(4, sketch.Points.Count); Assert.AreEqual(3, sketch.Segments.Count); Assert.AreEqual(0, sketch.Segments[2].StartPoint); Assert.AreEqual(4, sketch.Segments[2].EndPoint); Assert.AreEqual(4, sketch.Segments[3].StartPoint); Assert.AreEqual(1, sketch.Segments[3].EndPoint); Assert.AreEqual(4, sketch.Segments[1].StartPoint); Assert.AreEqual(3, sketch.Segments[1].EndPoint); Assert.IsTrue(sketch.Points[4].IsEqual(new Pnt2d(5.0, 0.0), 0.01)); }
public void ConvertToLine() { 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)); var s1 = new SketchSegmentArc(p1, p2, pr); sketch.AddSegment(s1); Assert.IsTrue(SketchUtils.CanConvertSegment(sketch, s1, typeof(SketchSegmentLine))); var s2 = SketchUtils.ConvertSegment(sketch, s1, typeof(SketchSegmentLine)); Assert.AreNotEqual(SketchUtils.ConvertSegmentFailed, s2); Assert.AreEqual(1, sketch.Segments.Count); Assert.IsInstanceOf <SketchSegmentLine>(sketch.Segments[1]); Assert.AreEqual(p1, sketch.Segments[s2].StartPoint); Assert.AreEqual(p2, sketch.Segments[s2].EndPoint); }
public void ConvertEllipticalArcToArc() { 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)); var s1 = new SketchSegmentEllipticalArc(p1, p2, pc); sketch.AddSegment(s1); Assert.IsTrue(SketchUtils.CanConvertSegment(sketch, s1, typeof(SketchSegmentArc))); var s2 = SketchUtils.ConvertSegment(sketch, s1, typeof(SketchSegmentArc)); Assert.AreNotEqual(SketchUtils.ConvertSegmentFailed, s2); Assert.AreEqual(1, sketch.Segments.Count); Assert.IsInstanceOf <SketchSegmentArc>(sketch.Segments[1]); Assert.AreEqual(p1, sketch.Segments[s2].StartPoint); Assert.AreEqual(p2, sketch.Segments[s2].EndPoint); Assert.AreEqual(pc + 1, sketch.Segments[s2].Points[2]); }
public void WeldPoints() { var sketch = Sketch.Create(); var sb = new SketchBuilder(sketch); sb.Line(1.0, 1.0, 2.0, 2.0); // 0, 1 sb.Line(1.0, 1.0, -2.0, -2.0); // 2, 3 sb.Line(1.2, 1.2, -2.0, 2.0); // 4, 5 Assert.IsTrue(SketchUtils.WeldPoints(sketch, new[] { 0, 2, 4 })); Assert.AreEqual(4, sketch.Points.Count); Assert.AreEqual(3, sketch.Segments.Count); Assert.AreEqual(6, sketch.Segments[0].StartPoint); Assert.AreEqual(1, sketch.Segments[0].EndPoint); Assert.AreEqual(6, sketch.Segments[1].StartPoint); Assert.AreEqual(3, sketch.Segments[1].EndPoint); Assert.AreEqual(6, sketch.Segments[2].StartPoint); Assert.AreEqual(5, sketch.Segments[2].EndPoint); Assert.That(new Pnt2d(3.2 / 3, 3.2 / 3).IsEqual(sketch.Points[6], 0.001)); }
public void DeletePointArcArc() { var sketch = Sketch.Create(); int p1 = sketch.AddPoint(new Pnt2d(0, 5)); int p2 = sketch.AddPoint(new Pnt2d(4, 3)); int p3 = sketch.AddPoint(new Pnt2d(3, 4)); var arc1 = new SketchSegmentArc(p1, p2, p3); int s1 = sketch.AddSegment(arc1); int p4 = sketch.AddPoint(new Pnt2d(4, -3)); int p5 = sketch.AddPoint(new Pnt2d(5, 0)); var arc2 = new SketchSegmentArc(p2, p4, p5); int s2 = sketch.AddSegment(arc2); Assume.That(arc1.Center(sketch.Points).IsEqual(arc2.Center(sketch.Points), 0.001)); SketchUtils.DeletePointTrySubstituteSegments(sketch, p2); Assert.AreEqual(3, sketch.Points.Count); Assert.AreEqual(1, sketch.Segments.Count); Assert.AreEqual(p1, sketch.Segments[s2 + 1].StartPoint); Assert.AreEqual(p4, sketch.Segments[s2 + 1].EndPoint); }
public void ConvertBezierToArc() { 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)); var s1 = new SketchSegmentBezier(p1, p2, p3); sketch.AddSegment(s1); Assert.IsTrue(SketchUtils.CanConvertSegment(sketch, s1, typeof(SketchSegmentArc))); var s2 = SketchUtils.ConvertSegment(sketch, s1, typeof(SketchSegmentArc)); Assert.AreNotEqual(SketchUtils.ConvertSegmentFailed, s2); Assert.AreEqual(1, sketch.Segments.Count); Assert.IsInstanceOf <SketchSegmentArc>(sketch.Segments[1]); Assert.AreEqual(p1, sketch.Segments[s2].StartPoint); Assert.AreEqual(p3, sketch.Segments[s2].EndPoint); Assert.AreEqual(p3 + 1, sketch.Segments[s2].Points[2]); }
public void ConvertLineToBezier() { var sketch = Sketch.Create(); int p1 = sketch.AddPoint(new Pnt2d(0, 0)); int p2 = sketch.AddPoint(new Pnt2d(10, 0)); var s1 = new SketchSegmentLine(p1, p2); sketch.AddSegment(s1); Assert.IsTrue(SketchUtils.CanConvertSegment(sketch, s1, typeof(SketchSegmentBezier))); var s2 = SketchUtils.ConvertSegment(sketch, s1, typeof(SketchSegmentBezier)); Assert.AreNotEqual(SketchUtils.ConvertSegmentFailed, s2); Assert.AreEqual(1, sketch.Segments.Count); Assert.IsInstanceOf <SketchSegmentBezier>(sketch.Segments[1]); Assert.AreEqual(p1, sketch.Segments[s2].StartPoint); Assert.AreEqual(p2, sketch.Segments[s2].EndPoint); Assert.AreEqual(p2 + 1, sketch.Segments[s2].Points[1]); Assert.AreEqual(p2 + 2, sketch.Segments[s2].Points[2]); }