//-------------------------------------------------------------------------------------------------- public override bool ReplaceOperand(int operandIndex, IShapeOperand operandShape) { if (operandIndex != 1 || Operands.Count < 1 || !(Operands[1] is BodyShapeOperand) || !(operandShape is Shape)) { return(base.ReplaceOperand(operandIndex, operandShape)); } var solidShape = operandShape as Solid; if (solidShape == null) { return(false); } // Transform operandShape var trsf = new Trsf(GetCoordinateSystem(), (Operands[1] as BodyShapeOperand).Body.GetCoordinateSystem()); var bRep = solidShape.GetBRep()?.Moved(new TopLoc_Location(trsf)); if (bRep == null) { return(false); } solidShape.UpdateShape(bRep); // RemoveShape will replace the shape with the predecessor Predecessor = operandShape; Body.RemoveShape(this); return(true); }
public void TopoDSEquality() { var shape = new Box { DimensionX = 10, DimensionY = 5, DimensionZ = 2 }; Assert.IsTrue(shape.Make(Shape.MakeFlags.None)); var ocShape = shape.GetBRep(); var edges1 = ocShape.Edges(); var edges2 = ocShape.Edges(); Assert.AreNotEqual(edges1[1], edges2[0]); Assert.AreEqual(edges1[0], edges2[0]); var faces1 = ocShape.Faces(); var faces2 = ocShape.Faces(); Assert.AreNotEqual(faces1[1], faces2[0]); Assert.AreEqual(faces1[0], faces2[0]); var trsf = new Trsf(new Vec(1, 0, 0)); var ocShape2 = ocShape.Moved(new TopLoc_Location(trsf)); Assert.AreNotEqual(ocShape.Location(), ocShape2.Location()); Assert.AreEqual(edges1[0].Location(), edges2[0].Location()); }
//-------------------------------------------------------------------------------------------------- protected TopoDS_Shape GetOperand2DFaces(int operandIndex, Pln?boundToPlane) { if (boundToPlane.HasValue) { GetOperand(operandIndex)?.BindToPlane(GetCoordinateSystem(), this, boundToPlane); } var sourceBrep = GetOperandBRep(operandIndex); if (sourceBrep == null) { return(null); } // Check if we already have faces var exp = new TopExp_Explorer(sourceBrep, TopAbs_ShapeEnum.TopAbs_FACE, TopAbs_ShapeEnum.TopAbs_SHAPE); if (exp.More()) { return(sourceBrep); } var baseFacesShape = TopoUtils.CreateFacesFromWires(sourceBrep, Pln.XOY); if (boundToPlane != null && baseFacesShape != null) { var trsf = new Trsf(boundToPlane.Value.Rotation(), boundToPlane.Value.Location.ToVec()); baseFacesShape = baseFacesShape.Moved(new TopLoc_Location(trsf)); } return(baseFacesShape); }
//-------------------------------------------------------------------------------------------------- bool _CreateSlices() { var sliceInterval = SliceThickness / SliceCount; for (int sliceIndex = 0; sliceIndex < SliceCount; sliceIndex++) { var sliceOffset = sliceInterval * (sliceIndex + 0.5); var cutPlane = _RefPlane.Translated(SliceDirection.ToVec().Multiplied(sliceOffset)); var cutPlaneFace = new TopoDS_Face(); new BRep_Builder().MakeFace(cutPlaneFace, new Geom_Plane(cutPlane), 1e-7); // Create contour var common = new BRepAlgoAPI_Common(SourceShape, cutPlaneFace); if (!common.IsDone()) { Messages.Error("Cannot create contour face from shape."); return(false); } var bodySpaceShape = common.Shape(); // Move to origin var transform = new Trsf(Ax3.XOY, cutPlane.Position); var transformer = new BRepBuilderAPI_Transform(bodySpaceShape, transform, true); var shape = transformer.Shape(); var slice = new Slice(shape, cutPlane); _Slices[sliceIndex] = slice; } return(true); }
//-------------------------------------------------------------------------------------------------- public static void Rotate(ITransformable entity, Ax1 rotationAxis, double angle) { var rotTrsf = new Trsf(rotationAxis, angle); var trsf = rotTrsf.Multiplied(new Trsf(entity.Rotation, entity.Position.ToVec())); entity.Position = trsf.TranslationPart().ToPnt(); entity.Rotation = trsf.GetRotation(); }
//-------------------------------------------------------------------------------------------------- public void Rotate(Ax1 rotationAxis, double angle) { var rotTrsf = new Trsf(rotationAxis, angle); var trsf = rotTrsf.Multiplied(GetTransformation()); Position = trsf.TranslationPart().ToPnt(); Rotation = trsf.GetRotation(); }
//-------------------------------------------------------------------------------------------------- public override Trsf GetTransformation() { if (_BoundToPlane != null) { var trsf = new Trsf(_BoundToPlane.Value.Rotation(), _BoundToPlane.Value.Location.ToVec()); return(base.GetTransformation().Multiplied(trsf)); } return(base.GetTransformation()); }
public void FromTrsf2d() { Trsf2d m2d = new Trsf2d(); m2d.SetRotation(Pnt2d.Origin, Math.PI / 2); var m1 = new Trsf(m2d); Assert.AreEqual(TrsfForm.Rotation, m1.Form); Assert.AreEqual(Math.PI / 2, m1.GetRotation().GetRotationAngle()); }
public void Transform() { Trsf t1 = new Trsf(); t1.SetRotation(Ax1.OZ, Math.PI / 2); var p2 = new Dir(0, 1, 0); Assert.That(new Dir(-1, 0, 0).IsEqual(p2.Transformed(t1), 0.0001)); p2.Transform(t1); Assert.That(new Dir(-1, 0, 0).IsEqual(p2, 0.0001)); }
public void Transform() { Trsf t1 = new Trsf(); t1.SetRotation(Ax1.OZ, Math.PI / 2); var p2 = new Vec(4, 5, 6); Assert.That(new Vec(-5, 4, 6).IsEqual(p2.Transformed(t1), 0.000001, 0.0001)); p2.Transform(t1); Assert.That(new Vec(-5, 4, 6).IsEqual(p2, 0.000001, 0.0001)); }
//-------------------------------------------------------------------------------------------------- public TranslateAction(object owner, Ax3 coordinateSystem) : base(owner) { _CoordinateSystem = coordinateSystem; // Create inverse rotation matrix var rotAx3 = _CoordinateSystem; rotAx3.Location = Pnt.Origin; _InverseRotation = new Trsf(rotAx3); _InverseRotation.Invert(); }
public void Transform() { Trsf m1 = new Trsf(); m1.SetRotation(Ax1.OZ, Math.PI / 2); var c1 = new XYZ(10, 5, 2); m1.Transforms(ref c1); Assert.AreEqual(-5, c1.X, 0.000001); Assert.AreEqual(10, c1.Y, 0.000001); Assert.AreEqual(2, c1.Z, 0.000001); }
//-------------------------------------------------------------------------------------------------- void _PreviewHeight(ToolAction toolAction) { if (!(toolAction is AxisValueAction axisValueAction)) { return; } _ClearPreviews(); _Position = ElSLib.Value(Math.Min(_PointPlane1.X, _PointPlane2.X), Math.Min(_PointPlane1.Y, _PointPlane2.Y), _Plane).Round(); _Rotation = WorkspaceController.Workspace.GetWorkingPlaneRotation(); if (_PreviewShape == null) { // Create solid _PreviewShape = new Box { DimensionX = Math.Abs(_PointPlane1.X - _PointPlane2.X).Round(), DimensionY = Math.Abs(_PointPlane1.Y - _PointPlane2.Y).Round(), DimensionZ = 0.1 }; } var height = axisValueAction.Value.Round(); _PreviewShape.DimensionZ = (Math.Abs(height) >= 0.001) ? height : 0.001; var ocShape = _PreviewShape.GetTransformedBRep(); if (ocShape != null) { var trsf = new Trsf(_Rotation, _Position.ToVec()); _AisPreviewEdges = new AIS_Shape(ocShape); _AisPreviewEdges.SetDisplayMode(0); _AisPreviewEdges.SetLocalTransformation(trsf); WorkspaceController.Workspace.AisContext.Display(_AisPreviewEdges, false); WorkspaceController.Workspace.AisContext.Deactivate(_AisPreviewEdges); _AisPreviewSolid = new AIS_Shape(ocShape); _AisPreviewSolid.SetDisplayMode(1); _AisPreviewSolid.SetLocalTransformation(trsf); WorkspaceController.Workspace.AisContext.Display(_AisPreviewSolid, false); WorkspaceController.Workspace.AisContext.Deactivate(_AisPreviewSolid); } StatusText = $"Selected height: {height:0.00}"; if (_ValueHudElement != null) { _ValueHudElement.Value = height; } WorkspaceController.Invalidate(); }
public void Transform() { Trsf t1 = new Trsf(); t1.SetRotation(Ax1.OZ, Math.PI / 2); var p1 = new Ax1(new Pnt(1, 2, 3), new Dir(1, 0, 0)); Assert.That(new Pnt(-2, 1, 3).IsEqual(p1.Transformed(t1).Location, 0.0000001)); Assert.That(new Dir(0, 1, 0).IsEqual(p1.Transformed(t1).Direction, 0.0000001)); p1.Transform(t1); Assert.That(new Pnt(-2, 1, 3).IsEqual(p1.Location, 0.0000001)); Assert.That(new Dir(0, 1, 0).IsEqual(p1.Direction, 0.0000001)); }
//-------------------------------------------------------------------------------------------------- void _OnActionPreview(ToolAction toolAction) { if (toolAction == _TranslateAction) { var transformation = new Trsf(_TranslateAction.Delta); _UpdateTransformations(transformation); } else if (toolAction == _RotateAction) { var transformation = new Trsf(_RotateAction.RotationAxis, _RotateAction.Delta); _UpdateTransformations(transformation); } }
public void ValueType_Trsf() { Trsf m1 = new Trsf(); m1.SetRotation(Ax1.OZ, Math.PI / 2); var c1 = new XYZ(10, 5, 2); m1.Transforms(ref c1); Assert.AreEqual("-5,10,2", c1.ToString()); Trsf2d m2d = new Trsf2d(); m2d.SetRotation(Pnt2d.Origin, Math.PI / 2); m1 = new Trsf(m2d); Assert.AreEqual(TrsfForm.Rotation, m1.Form); Assert.AreEqual(Math.PI / 2, m1.GetRotation().GetRotationAngle()); }
public void Transform() { Trsf t1 = new Trsf(); t1.SetRotation(Ax1.OZ, Math.PI / 2); var p2 = new Ax3(new Pnt(1, 2, 3), new Dir(1, 0, 0)); var p3 = p2.Transformed(t1); Assert.That(new Pnt(-2, 1, 3).IsEqual(p3.Location, 0.0000001)); Assert.That(new Dir(0, 0, 1).IsEqual(p3.XDirection, 0.0000001)); Assert.That(new Dir(1, 0, 0).IsEqual(p3.YDirection, 0.0000001)); Assert.That(new Dir(0, 1, 0).IsEqual(p3.Direction, 0.0000001)); p2.Transform(t1); Assert.That(new Pnt(-2, 1, 3).IsEqual(p2.Location, 0.0000001)); Assert.That(new Dir(0, 0, 1).IsEqual(p2.XDirection, 0.0000001)); Assert.That(new Dir(1, 0, 0).IsEqual(p2.YDirection, 0.0000001)); Assert.That(new Dir(0, 1, 0).IsEqual(p2.Direction, 0.0000001)); }
//-------------------------------------------------------------------------------------------------- void _PreviewRadius(ToolAction toolAction) { if (!(toolAction is AxisValueAction axisValueAction)) { return; } _ClearPreviews(); if (_PreviewShape == null) { // Create solid _PreviewShape = new Sphere() { Radius = 0.1 }; } var radius = axisValueAction.Distance.Round(); if (radius > 0) { var trsf = new Trsf(_Point.ToVec()); _PreviewShape.Radius = radius; _AisPreviewEdges = new AIS_Shape(_PreviewShape.GetTransformedBRep()); _AisPreviewEdges.SetDisplayMode(0); _AisPreviewEdges.SetLocalTransformation(trsf); WorkspaceController.Workspace.AisContext.Display(_AisPreviewEdges, false); WorkspaceController.Workspace.AisContext.Deactivate(_AisPreviewEdges); _AisPreviewSolid = new AIS_Shape(_PreviewShape.GetTransformedBRep()); _AisPreviewSolid.SetDisplayMode(1); _AisPreviewSolid.SetLocalTransformation(trsf); WorkspaceController.Workspace.AisContext.Display(_AisPreviewSolid, false); WorkspaceController.Workspace.AisContext.Deactivate(_AisPreviewSolid); StatusText = $"Select Radius: {radius:0.00}"; if (_ValueHudElement != null) { _ValueHudElement.Value = radius; } } }
//-------------------------------------------------------------------------------------------------- IEnumerable <Geom_Curve> _CreateRectangleProfileCurves(Pln plane, double sx, double sy) { if (_Flags.HasFlag(PipeFlags.SymmetricProfile)) { sy = sx; } Trsf tf = new Trsf(plane.Position.Rotated(plane.Axis, _Rotation.ToRad()), Ax3.XOY); Dir dx = Dir.DX.Transformed(tf); Dir dy = Dir.DY.Transformed(tf); yield return(new Geom_TrimmedCurve(new Geom_Line(new Pnt(0, sy, 0).Transformed(tf), dx), -sx, sx)); yield return(new Geom_TrimmedCurve(new Geom_Line(new Pnt(sx, 0, 0).Transformed(tf), dy), -sy, sy)); yield return(new Geom_TrimmedCurve(new Geom_Line(new Pnt(0, -sy, 0).Transformed(tf), dx.Reversed()), -sx, sx)); yield return(new Geom_TrimmedCurve(new Geom_Line(new Pnt(-sx, 0, 0).Transformed(tf), dy.Reversed()), -sy, sy)); }
//-------------------------------------------------------------------------------------------------- bool _MakeFlangeSection(MakeContext context) { if (_Length <= 0) { return(true); } var brepAdaptor = new BRepAdaptor_Surface(context.FlangeFace); if (brepAdaptor.GetGeomType() != GeomAbs_SurfaceType.GeomAbs_Plane) { Messages.Error("Flanges can only be added to planar faces."); return(false); } var direction = brepAdaptor.Plane().Position.Direction; if (context.FlangeFace.Orientation() == TopAbs_Orientation.TopAbs_REVERSED) { direction.Reverse(); } // Extrude var makePrism = new BRepPrimAPI_MakePrism(context.FlangeFace, direction.ToVec().Multiplied(_Length)); if (!makePrism.IsDone()) { Messages.Error("Failed building flange."); return(false); } var flangeShape = makePrism.Shape(); // Rotate if bended if (_Angle > 0) { var trsf = new Trsf(context.BendAxis, _Angle.Clamp(0.0, 180.0).ToRad()); flangeShape.Location(new TopLoc_Location(trsf)); } context.FlangeShape = flangeShape; return(true); }
//-------------------------------------------------------------------------------------------------- public void AddSubshape(TopoDS_Shape shape, Trsf trsf, bool isSelected, int refId) { var subshape = new Subshape() { Shape = shape, IsSelected = isSelected, AisShape = new AIS_Shape(shape), RefId = refId }; //Debug.WriteLine(string.Format("Added component to sum: {0}", Subshapes.Count)); subshape.AisShape.SetLocalTransformation(trsf); subshape.AisShape.SetColor(isSelected ? Colors.FilteredSubshapesHot : Colors.FilteredSubshapes); subshape.AisShape.Attributes().WireAspect().SetWidth(2); subshape.AisShape.SetZLayer(-2); WorkspaceController.Workspace.AisContext.Display(subshape.AisShape, false); WorkspaceController.Workspace.AisContext.Activate(subshape.AisShape, 0, false); WorkspaceController.Workspace.AisContext.SetSelectionSensitivity(subshape.AisShape, 0, 10); Subshapes.Add(subshape); }
//-------------------------------------------------------------------------------------------------- protected SketchEditorElement(SketchEditorTool sketchEditorTool, Trsf transform, Pln plane) { SketchEditorTool = sketchEditorTool; Transform = transform; Plane = plane; }
public void ValueType_Ax3() { var s1 = new Ax3(new Pnt(1, 2, 3), new Dir(1, 0, 0)); var s2 = new Ax3(new Pnt(2, 3, 4), new Dir(0, 1, 0)); Assert.AreEqual(new Pnt(1, 2, 3), s1.Location); Assert.AreEqual(new Dir(1, 0, 0), s1.Direction); Assert.AreEqual(new Dir(0, 0, 1), s1.XDirection); Assert.AreEqual(new Dir(0, -1, 0), s1.YDirection); var p2 = s2; Assert.IsFalse(s1.IsCoplanar(p2, 0.1, 0.1)); Assert.IsFalse(s1.IsCoplanar(p2, 0.1, 2.0)); Assert.IsFalse(s1.IsCoplanar(p2, 0.1, Math.PI / 2)); Assert.IsTrue(s1.IsCoplanar(p2, 1.0, Math.PI / 2)); Assert.AreEqual(Math.PI / 2, s1.Angle(p2)); p2.Location = new Pnt(3, 2, 1); Assert.AreEqual(new Pnt(3, 2, 1), p2.Location); p2.Direction = new Dir(0, 1, 0); Assert.AreEqual(new Dir(0, 1, 0), p2.Direction); p2.XDirection = new Dir(0, 0, -1); Assert.AreEqual(new Dir(0, 0, -1), p2.XDirection); p2.YDirection = new Dir(1, 0, 0); Assert.AreEqual(new Dir(1, 0, 0), p2.YDirection); p2.XReverse(); Assert.AreEqual(new Dir(0, 0, -1), p2.XDirection); p2.YReverse(); Assert.AreEqual(new Dir(-1, 0, 0), p2.YDirection); p2.ZReverse(); Assert.AreEqual(new Dir(0, -1, 0), p2.Direction); Assert.IsFalse(p2.Direct()); var res = new Ax3(new Pnt(1, -2, -3), new Dir(-1, 0, 0), new Dir(0, 0, -1)); res.YReverse(); p2 = s1; Assert.AreEqual(res, p2.Mirrored(new Pnt(1, 0, 0))); p2.Mirror(new Pnt(1, 0, 0)); Assert.AreEqual(res, p2); res = new Ax3(new Pnt(1, -2, 3), new Dir(1, 0, 0), new Dir(0, 0, 1)); res.YReverse(); var a2 = new Ax2(new Pnt(1, 0, 0), new Dir(0, 1, 0)); p2 = s1; Assert.AreEqual(res, p2.Mirrored(a2)); p2.Mirror(a2); Assert.AreEqual(res, p2); res = new Ax3(new Pnt(1, -2, -3), new Dir(1, 0, 0), new Dir(0, 0, -10)); var a1 = new Ax1(new Pnt(1, 0, 0), new Dir(1, 0, 0)); p2 = s1; Assert.AreEqual(res, p2.Mirrored(a1)); p2.Mirror(a1); Assert.AreEqual(res, p2); res = new Ax3(new Pnt(1, 1, 2), new Dir(1, 0, 0), new Dir(0, -1, 0)); a1 = new Ax1(new Pnt(2, 2, 2), new Dir(1, 0, 0)); Assert.IsTrue(res.IsCoplanar(s1.Rotated(a1, Math.PI / 2), 0, 0)); p2 = s1; p2.Rotate(a1, Math.PI / 2); Assert.IsTrue(res.IsCoplanar(p2, 0, 0)); res = new Ax3(new Pnt(-1, 0, 5), new Dir(1, 0, 0)); p2 = s1; Assert.AreEqual(res, p2.Scaled(new Pnt(2, 3, 2), 3)); p2.Scale(new Pnt(2, 3, 2), 3); Assert.AreEqual(res, p2); res = new Ax3(new Pnt(-1, -1, 2), new Dir(1, 0, 0)); p2 = s1; Assert.AreEqual(res, p2.Translated(new Pnt(3, 5, 4), new Pnt(1, 2, 3))); p2.Translate(new Pnt(3, 5, 4), new Pnt(1, 2, 3)); Assert.AreEqual(res, p2); res = new Ax3(new Pnt(3, 5, 4), new Dir(1, 0, 0)); p2 = s1; Assert.AreEqual(res, p2.Translated(new Vec(2, 3, 1))); p2.Translate(new Vec(2, 3, 1)); Assert.AreEqual(res, p2); //gp_Trsf gt1 = new gp_Trsf(); //gt1.SetRotation(gp.OZ(), Math.PI / 2); //gp2.Transform(gt1); //TestContext.WriteLine(string.Format(CultureInfo.InvariantCulture, $"({gp2.Location().x},{gp2.Location().y},{gp2.Location().z}),({gp2.XDirection().x},{gp2.XDirection().y},{gp2.XDirection().z}),({gp2.YDirection().x},{gp2.YDirection().y},{gp2.YDirection().z}),({gp2.Direction().x},{gp2.Direction().y},{gp2.Direction().z})")); Trsf t1 = new Trsf(); t1.SetRotation(Ax1.OZ, Math.PI / 2); p2 = s1; Assert.AreEqual("(-2,1,3),(0,0,1),(1,-1.11022302462516E-16,0),(1.11022302462516E-16,1,0)", p2.Transformed(t1).ToString()); p2.Transform(t1); Assert.AreEqual("(-2,1,3),(0,0,1),(1,-1.11022302462516E-16,0),(1.11022302462516E-16,1,0)", p2.ToString()); }
public void ValueType_Ax1() { Assert.AreEqual(new Ax1(Pnt.Origin, Dir.DX), Ax1.OX); Assert.AreEqual(new Ax1(Pnt.Origin, Dir.DY), Ax1.OY); Assert.AreEqual(new Ax1(Pnt.Origin, Dir.DZ), Ax1.OZ); var s1 = new Ax1(new Pnt(1, 2, 3), new Dir(1, 0, 0)); var s2 = new Ax1(new Pnt(2, 3, 4), new Dir(0, 1, 0)); var p1 = s1; var p2 = s2; Assert.IsFalse(p1.IsCoaxial(p2, 0.1, 0.1)); Assert.IsFalse(p1.IsCoaxial(p2, Math.PI / 2, 0.1)); Assert.IsTrue(p1.IsCoaxial(p2, Math.PI / 2, 2.0)); Assert.IsTrue(p1.IsNormal(p2, 0.1)); Assert.IsFalse(p1.IsOpposite(p2, 0.1)); Assert.IsTrue(p1.IsOpposite(p2, Math.PI / 2)); Assert.IsFalse(p1.IsParallel(p2, 0.1)); Assert.IsTrue(p1.IsParallel(p2, Math.PI / 2)); Assert.AreEqual(Math.PI / 2, p1.Angle(p2)); var m1 = new Ax1(new Pnt(1, 2, 3), new Dir(-1, 0, 0)); p2 = s1; p2.Reverse(); Assert.AreEqual(m1, p2); Assert.AreEqual(m1, p1.Reversed()); m1 = new Ax1(new Pnt(-1, 0, -3), new Dir(-1, 0, 0)); p2 = s1; p2.Mirror(new Pnt(0, 1, 0)); Assert.AreEqual(m1, p2); Assert.AreEqual(m1, p1.Mirrored(new Pnt(0, 1, 0))); m1 = new Ax1(new Pnt(-1, 2, -3), new Dir(-1, 0, 0)); var m2 = new Ax1(new Pnt(0, 1, 0), new Dir(0, 1, 0)); p2 = s1; p2.Mirror(m2); Assert.AreEqual(m1, p2); Assert.AreEqual(m1, p1.Mirrored(m2)); m1 = new Ax1(new Pnt(3, 2, -1), new Dir(0, 0, -1)); p2 = s1; p2.Rotate(m2, Math.PI / 2); Assert.IsTrue(m1.IsCoaxial(p2, 0.0001, 0.001)); Assert.IsTrue(m1.IsCoaxial(p1.Rotated(m2, Math.PI / 2), 0.0001, 0.001)); m1 = new Ax1(new Pnt(-1, 0, 5), new Dir(1, 0, 0)); p2 = s1; p2.Scale(new Pnt(2, 3, 2), 3); Assert.AreEqual(m1, p2); Assert.AreEqual(m1, p1.Scaled(new Pnt(2, 3, 2), 3)); m1 = new Ax1(new Pnt(-1, -1, 2), new Dir(1, 0, 0)); p2 = s1; p2.Translate(new Pnt(3, 5, 4), new Pnt(1, 2, 3)); Assert.AreEqual(m1, p2); Assert.AreEqual(m1, p1.Translated(new Pnt(3, 5, 4), new Pnt(1, 2, 3))); m1 = new Ax1(new Pnt(3, 5, 4), new Dir(1, 0, 0)); p2 = s1; p2.Translate(new Vec(2, 3, 1)); Assert.AreEqual(m1, p2); Assert.AreEqual(m1, p1.Translated(new Vec(2, 3, 1))); // TestContext.WriteLine(string.Format(CultureInfo.InvariantCulture, $"{gp2.Location().x},{gp2.Location().y},{gp2.Location().z} - {gp2.Direction().x},{gp2.Direction().y},{gp2.Direction().z}")); Trsf t1 = new Trsf(); t1.SetRotation(Ax1.OZ, Math.PI / 2); p2 = s1; Assert.AreEqual("(-2,1,3),(1.11022302462516E-16,1,0)", p2.Transformed(t1).ToString()); p2.Transform(t1); Assert.AreEqual("(-2,1,3),(1.11022302462516E-16,1,0)", p2.ToString()); var a2 = new Ax2(new Pnt(-1, 2, -3), new Dir(-1, 0, 0)); p2 = new Ax1(new Pnt(1, 2, 3), new Dir(1, 0, 0)); Assert.AreEqual("(-3,2,3),(-1,0,0)", p2.Mirrored(a2).ToString()); p2.Mirror(a2); Assert.AreEqual("(-3,2,3),(-1,0,0)", p2.ToString()); }
public void ValueType_Dir() { Assert.AreEqual(new Dir(1, 0, 0), Dir.DX); Assert.AreEqual(new Dir(0, 1, 0), Dir.DY); Assert.AreEqual(new Dir(0, 0, 1), Dir.DZ); var p1 = new Dir(1, 0, 0); var p2 = new Dir(0, 1, 0); Assert.IsFalse(p1.IsEqual(p2, 0.1)); Assert.IsTrue(p1.IsEqual(p2, Math.PI / 2)); Assert.IsTrue(p1.IsNormal(p2, 0.1)); Assert.IsFalse(p1.IsOpposite(p2, 0.1)); Assert.IsTrue(p1.IsOpposite(p2, Math.PI / 2)); Assert.IsFalse(p1.IsParallel(p2, 0.1)); Assert.IsTrue(p1.IsParallel(p2, Math.PI / 2)); Assert.AreEqual(Math.PI / 2, p1.Angle(p2)); Assert.AreEqual(Math.PI / 2, p1.AngleWithRef(p2, new Dir(0, 0, 1))); p2 = new Dir(1, 0, 0); p2.Cross(new Dir(0, 1, 0)); Assert.AreEqual(new Dir(0, 0, 1), p2); Assert.AreEqual(new Dir(0, 0, 1), p1.Crossed(new Dir(0, 1, 0))); p2 = new Dir(1, 0, 0); p2.CrossCross(new Dir(0, 1, 0), new Dir(1, 0, 1)); Assert.AreEqual(new Dir(0, 1, 0), p2); Assert.AreEqual(new Dir(0, 1, 0), p1.CrossCrossed(new Dir(0, 1, 0), new Dir(1, 0, 1))); Assert.AreEqual(Math.Sqrt(2) / 2, p1.Dot(new Dir(1, 1, 0)), 0.0000001); Assert.AreEqual(Math.Sqrt(2) / 2, p1.DotCross(new Dir(0, 1, 0), new Dir(1, 0, 1)), 0.0000001); p2 = new Dir(1, 0, 0); p2.Reverse(); Assert.AreEqual(new Dir(-1, 0, 0), p2); Assert.AreEqual(new Dir(-1, 0, 0), p1.Reversed()); p2 = new Dir(1, 0, 0); p2.Mirror(new Dir(0, 1, 0)); Assert.AreEqual(new Dir(-1, 0, 0), p2); Assert.AreEqual(new Dir(-1, 0, 0), p1.Mirrored(new Dir(0, 1, 0))); var m2 = new Ax1(new Pnt(-1, 2, -3), new Dir(-1, 0, 0)); p2 = new Dir(1, 0, 0); p2.Mirror(m2); Assert.AreEqual(new Dir(1, 0, 0), p2); Assert.AreEqual(new Dir(1, 0, 0), p1.Mirrored(m2)); var a2 = new Ax2(new Pnt(-1, 2, -3), new Dir(-1, 0, 0)); p2 = new Dir(1, 0, 0); Assert.AreEqual(new Dir(-1, 0, 0), p2.Mirrored(a2)); p2.Mirror(a2); Assert.AreEqual(new Dir(-1, 0, 0), p2); p2 = new Dir(1, 0, 0); p2.Rotate(m2, Math.PI / 2); Assert.AreEqual(new Dir(1, 0, 0), p2); Assert.AreEqual(new Dir(1, 0, 0), p1.Rotated(m2, Math.PI / 2)); //TestContext.WriteLine(string.Format(CultureInfo.InvariantCulture, "{0},{1},{2}", gp2.x, gp2.y, gp2.z)); Trsf t1 = new Trsf(); t1.SetRotation(Ax1.OZ, Math.PI / 2); p2 = new Dir(0, 1, 0); Assert.AreEqual("-1,1.11022302462516E-16,0", p2.Transformed(t1).ToString()); p2.Transform(t1); Assert.AreEqual("-1,1.11022302462516E-16,0", p2.ToString()); }
public void ValueType_Vec() { var p1 = new Vec(1, 0, 0); var p2 = new Vec(0, 1, 0); Assert.IsFalse(p1.IsEqual(p2, 0.99, 0.1)); Assert.IsTrue(p1.IsEqual(p2, 1.01, 0.1)); Assert.IsTrue(p1.IsEqual(p2, 0.99, Math.PI / 2)); Assert.IsTrue(p1.IsNormal(p2, 0.1)); Assert.IsFalse(p1.IsOpposite(p2, 0.1)); Assert.IsTrue(p1.IsOpposite(p2, Math.PI / 2)); Assert.IsFalse(p1.IsParallel(p2, 0.1)); Assert.IsTrue(p1.IsParallel(p2, Math.PI / 2)); p1 = new Vec(1, 2, 3); p2 = new Vec(4, 5, 6); Assert.AreEqual(14, p1.SquareMagnitude()); Assert.AreEqual(Math.Sqrt(14), p1.Magnitude()); p2 = p1; p2.Add(new Vec(1, 2, 3)); Assert.AreEqual(new Vec(2, 4, 6), p2); Assert.AreEqual(new Vec(2, 4, 6), p1.Added(new Vec(1, 2, 3))); p2 = new Vec(1, 2, 3); p2.Subtract(new Vec(3, 2, 1)); Assert.AreEqual(new Vec(-2, 0, 2), p2); Assert.AreEqual(new Vec(-2, 0, 2), p1.Subtracted(new Vec(3, 2, 1))); p2 = new Vec(1, 2, 3); p2.Cross(new Vec(3, 2, 1)); Assert.AreEqual(new Vec(-4, 8, -4), p2); Assert.AreEqual(new Vec(-4, 8, -4), p1.Crossed(new Vec(3, 2, 1))); Assert.AreEqual(Math.Sqrt(96), p1.CrossMagnitude(new Vec(3, 2, 1))); Assert.AreEqual(96, p1.CrossSquareMagnitude(new Vec(3, 2, 1))); p2 = new Vec(1, 2, 3); p2.CrossCross(new Vec(1, 2, 3), new Vec(4, 5, 6)); Assert.AreEqual(new Vec(-24, -6, 12), p2); Assert.AreEqual(new Vec(-24, -6, 12), p1.CrossCrossed(new Vec(1, 2, 3), new Vec(4, 5, 6))); p2 = new Vec(1, 2, 3); p2.Divide(2); Assert.AreEqual(new Vec(0.5, 1, 1.5), p2); Assert.AreEqual(new Vec(0.5, 1, 1.5), p1.Divided(2)); Assert.AreEqual(14, p1.Dot(new Vec(1, 2, 3))); Assert.AreEqual(0, p1.DotCross(new Vec(4, 5, 6), new Vec(4, 5, 6))); p2 = new Vec(1, 2, 3); p2.Multiply(2); Assert.AreEqual(new Vec(2, 4, 6), p2); Assert.AreEqual(new Vec(2, 4, 6), p1.Multiplied(2)); p2 = new Vec(1, 2, 3); p2.Scale(2); Assert.AreEqual(new Vec(2, 4, 6), p2); Assert.AreEqual(new Vec(2, 4, 6), p1.Scaled(2)); p2 = new Vec(1, 2, 3); p2.Normalize(); Assert.IsTrue(p2.IsEqual(new Vec(0.26726, 0.53452, 0.80178), 0.00001, 0.00001)); Assert.IsTrue(p1.Normalized().IsEqual(new Vec(0.26726, 0.53452, 0.80178), 0.00001, 0.00001)); p2 = new Vec(1, 2, 3); p2.Reverse(); Assert.AreEqual(new Vec(-1, -2, -3), p2); Assert.AreEqual(new Vec(-1, -2, -3), p1.Reversed()); p2.SetLinearForm(new Vec(1, 2, 3), new Vec(4, 5, 6)); Assert.AreEqual(new Vec(5, 7, 9), p2); p2.SetLinearForm(2, new Vec(1, 2, 3), new Vec(4, 5, 6)); Assert.AreEqual(new Vec(6, 9, 12), p2); p2.SetLinearForm(2, new Vec(1, 2, 3), 3, new Vec(4, 5, 6)); Assert.AreEqual(new Vec(14, 19, 24), p2); p2.SetLinearForm(2, new Vec(1, 2, 3), 3, new Vec(4, 5, 6), new Vec(7, 8, 9)); Assert.AreEqual(new Vec(21, 27, 33), p2); p2.SetLinearForm(2, new Vec(1, 2, 3), 3, new Vec(4, 5, 6), 4, new Vec(7, 8, 9)); Assert.AreEqual(new Vec(42, 51, 60), p2); p2.SetLinearForm(2, new Vec(1, 2, 3), 3, new Vec(4, 5, 6), 4, new Vec(7, 8, 9), new Vec(10, 11, 12)); Assert.AreEqual(new Vec(52, 62, 72), p2); p2 = new Vec(2, 0, 0); p2.Mirror(new Vec(0, 1, 0)); Assert.AreEqual(new Vec(-2, 0, 0), p2); Assert.AreEqual(new Vec(2, 0, 0), p2.Mirrored(new Vec(0, 1, 0))); var m2 = new Ax1(new Pnt(-1, 2, -3), new Dir(-1, 0, 0)); p2 = new Vec(2, 1, 3); Assert.AreEqual(new Vec(2, -1, -3), p2.Mirrored(m2)); p2.Mirror(m2); Assert.AreEqual(new Vec(2, -1, -3), p2); var a2 = new Ax2(new Pnt(-1, 2, -3), new Dir(-1, 0, 0)); p2 = new Vec(2, 1, 3); Assert.AreEqual("-2,1,3", p2.Mirrored(a2).ToString()); p2.Mirror(a2); Assert.AreEqual("-2,1,3", p2.ToString()); p2 = new Vec(2, 1, 3); Assert.IsTrue(new Vec(2, 3, -1).IsEqual(p2.Rotated(m2, Math.PI / 2), 0.0001, 0.0001)); p2.Rotate(m2, Math.PI / 2); Assert.IsTrue(new Vec(2, 3, -1).IsEqual(p2, 0.0001, 0.0001)); //TestContext.WriteLine(string.Format(CultureInfo.InvariantCulture, "{0},{1},{2}", gp2.x, gp2.y, gp2.z)); Trsf t1 = new Trsf(); t1.SetRotation(Ax1.OZ, Math.PI / 2); p2 = new Vec(4, 5, 6); Assert.AreEqual("-5,4,6", p2.Transformed(t1).ToString()); p2.Transform(t1); Assert.AreEqual("-5,4,6", p2.ToString()); }
public void ValueType_Pnt() { var p1 = new Pnt(1, 2, 3); var p2 = new Pnt(4, 5, 6); Assert.AreEqual(new Pnt(0, 0, 0), Pnt.Origin); Assert.AreEqual(27, p1.SquareDistance(p2)); Assert.AreEqual(Math.Sqrt(27), p1.Distance(p2)); Assert.IsTrue(p1.IsEqual(p2, 5.2)); Assert.IsFalse(p1.IsEqual(p2, 5.18)); p2 = new Pnt(1, 2, 3); p2.Mirror(new Pnt(2, 2, 2)); Assert.AreEqual(new Pnt(3, 2, 1), p2); Assert.AreEqual(new Pnt(3, 2, 1), p1.Mirrored(new Pnt(2, 2, 2))); p2 = new Pnt(1, 2, 3); p2.Translate(new Pnt(2, 2, 2), new Pnt(1, 2, 3)); Assert.AreEqual(new Pnt(0, 2, 4), p2); Assert.AreEqual(new Pnt(0, 2, 4), p1.Translated(new Pnt(2, 2, 2), new Pnt(1, 2, 3))); Assert.AreEqual(new XYZ(1, 2, 3), p1.ToXYZ()); p2 = new Pnt(1, 2, 3); p2.Scale(new Pnt(2, 2, 2), 2); Assert.AreEqual(new Pnt(0, 2, 4), p2); Assert.AreEqual(new Pnt(0, 2, 4), p1.Scaled(new Pnt(2, 2, 2), 2)); p2.BaryCenter(2, p1, 5); Assert.IsTrue(p2.IsEqual(new Pnt(0.71428, 2, 3.28571), 0.00001)); p2 = new Pnt(1, 2, 3); p2.Translate(new Vec(2, 2, 2)); Assert.AreEqual(new Pnt(3, 4, 5), p2); Assert.AreEqual(new Pnt(3, 4, 5), p1.Translated(new Vec(2, 2, 2))); p2 = new Pnt(2, 1, 3); Assert.AreEqual(new Pnt(4, 4, 7), p2.Translated(new Vec(2, 3, 4))); p2.Translate(new Vec(2, 3, 4)); Assert.AreEqual(new Pnt(4, 4, 7), p2); var m2 = new Ax1(new Pnt(-1, 2, -3), new Dir(-1, 0, 0)); p2 = new Pnt(2, 1, 3); Assert.AreEqual(new Pnt(2, 3, -9), p2.Mirrored(m2)); p2.Mirror(m2); Assert.AreEqual(new Pnt(2, 3, -9), p2); var a2 = new Ax2(new Pnt(-1, 2, -3), new Dir(-1, 0, 0)); p2 = new Pnt(2, 1, 3); Assert.AreEqual(new Pnt(-4, 1, 3), p2.Mirrored(a2)); p2.Mirror(a2); Assert.AreEqual(new Pnt(-4, 1, 3), p2); p2 = new Pnt(2, 1, 3); Assert.IsTrue(new Pnt(2, 8, -2).IsEqual(p2.Rotated(m2, Math.PI / 2), 0.0001)); p2.Rotate(m2, Math.PI / 2); Assert.IsTrue(new Pnt(2, 8, -2).IsEqual(p2, 0.0001)); //TestContext.WriteLine(string.Format(CultureInfo.InvariantCulture, "{0},{1},{2}", gp2.x, gp2.y, gp2.z)); Trsf t1 = new Trsf(); t1.SetRotation(Ax1.OZ, Math.PI / 2); p2 = new Pnt(4, 5, 6); Assert.AreEqual("-5,4,6", p2.Transformed(t1).ToString()); p2.Transform(t1); Assert.AreEqual("-5,4,6", p2.ToString()); }
//-------------------------------------------------------------------------------------------------- public SketchEditorSegmentElement(SketchEditorTool sketchEditorTool, int segmentIndex, SketchSegment segment, Trsf transform, Pln plane) : base(sketchEditorTool, transform, plane) { Segment = segment; SegmentIndex = segmentIndex; }
//-------------------------------------------------------------------------------------------------- public SketchEditorConstraintElement(SketchEditorTool sketchEditorTool, SketchConstraint constraint, Trsf transform, Pln plane) : base(sketchEditorTool, transform, plane) { Constraint = constraint; }
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); }