示例#1
0
        public void Divide()
        {
            var p2 = new XY(1, 2);

            Assert.AreEqual(new XY(0.5, 1), p2.Divided(2));
            p2.Divide(2);
            Assert.AreEqual(new XY(0.5, 1), p2);
        }
示例#2
0
        //--------------------------------------------------------------------------------------------------

        void _UpdateTrihedron()
        {
            if (!Points.Any())
            {
                return;
            }

            // Calc Center
            var center = new XY();

            Points.ForEach(i => center.Add(_Sketch.Points[i].Coord));
            center.Divide(Points.Count);
            _Center2D = center.ToPnt();

            //Debug.WriteLine("MoveSketchPointAction - Center {0} {1}", center.X(), center.Y());

            // Project center point onto sketch plane
            var center3D = ElSLib.Value(center.X, center.Y, _Sketch.Plane);

            //Debug.WriteLine("MoveSketchPointAction - Center3D {0} {1} {2}", center3D.X(), center3D.Y(), center3D.Z());

            // Calculate center point on working plane
            if (_Sketch.Plane.Location.IsEqual(WorkspaceController.Workspace.WorkingPlane.Location, 0.00001))
            {
                _Center2DOnWorkingPlane = _Center2D;
            }
            else
            {
                double u = 0, v = 0;
                ElSLib.Parameters(WorkspaceController.Workspace.WorkingPlane, _Sketch.Plane.Location, ref u, ref v);
                _Center2DOnWorkingPlane = _Center2D.Translated(new Vec2d(u, v));
            }


            // Use plane from sketch, but translate it to center position
            var plane = _Sketch.Plane;

            plane.Location = center3D;
            _GizmoPlane    = new Geom_Plane(plane);
            _GeomPlane     = new Geom_Plane(plane);

            // Create Gizmo
            if (Gizmo == null)
            {
                Gizmo = new AIS_TranslationGizmo2D(_GizmoPlane);
                Gizmo.SetLength(100);
                WorkspaceController.Workspace.AisContext.Display(Gizmo, false);
            }
            else
            {
                Gizmo.SetComponent(_GeomPlane);
                WorkspaceController.Workspace.AisContext.Redisplay(Gizmo, false);
            }
        }
        public void ValueType_XY()
        {
            var p1 = new XY(1, 2);
            var p2 = new XY(4, 5);

            Assert.AreEqual(5, p1.SquareModulus());
            Assert.AreEqual(Math.Sqrt(5), p1.Modulus());

            Assert.IsTrue(p1.IsEqual(p2, 3));
            Assert.IsFalse(p1.IsEqual(p2, 2.99));

            p2 = p1;
            p2.Add(new XY(1, 2));
            Assert.AreEqual(new XY(2, 4), p2);
            Assert.AreEqual(new XY(2, 4), p1.Added(new XY(1, 2)));
            p2 += new XY(1, 2);
            Assert.AreEqual(new XY(3, 6), p2);

            Assert.AreEqual(-4, p1.Crossed(new XY(3, 2)));

            Assert.AreEqual(Math.Sqrt(16), p1.CrossMagnitude(new XY(3, 2)));
            Assert.AreEqual(16, p1.CrossSquareMagnitude(new XY(3, 2)));

            p2 = new XY(1, 2);
            p2.Divide(2);
            Assert.AreEqual(new XY(0.5, 1), p2);
            Assert.AreEqual(new XY(0.5, 1), p1.Divided(2));

            Assert.AreEqual(5, p1.Dot(new XY(1, 2)));

            p2 = new XY(1, 2);
            p2.Multiply(2);
            Assert.AreEqual(new XY(2, 4), p2);
            Assert.AreEqual(new XY(2, 4), p1.Multiplied(2));
            Assert.AreEqual(new XY(2, 4), p1 * 2);

            p2 = new XY(1, 2);
            p2.Multiply(new XY(1, 2));
            Assert.AreEqual(new XY(1, 4), p2);
            Assert.AreEqual(new XY(1, 4), p1.Multiplied(new XY(1, 2)));
            Assert.AreEqual(new XY(1, 4), p1 * new XY(1, 2));

            Mat2d m1 = new Mat2d();

            m1.SetRotation(Math.PI / 2);
            p2 = new XY(4, 5);
            Assert.AreEqual("-5,4", p2.Multiplied(m1).ToString());
            Assert.AreEqual("-5,4", (p2 * m1).ToString());
            p2.Multiply(m1);
            Assert.AreEqual("-5,4", p2.ToString());

            p2 = new XY(1, 23);
            Assert.AreEqual("0.0434372242763069,0.99905615835506", p2.Normalized().ToString());
            p2.Normalize();
            Assert.AreEqual("0.0434372242763069,0.99905615835506", p2.ToString());

            p2 = new XY(1, 2);
            p2.Reverse();
            Assert.AreEqual(new XY(-1, -2), p2);
            Assert.AreEqual(new XY(-1, -2), p1.Reversed());

            p2 = new XY(1, 2);
            p2.Subtract(new XY(3, 2));
            Assert.AreEqual(new XY(-2, 0), p2);
            Assert.AreEqual(new XY(-2, 0), p1.Subtracted(new XY(3, 2)));
            Assert.AreEqual(new XY(-2, 0), p1 - new XY(3, 2));

            p2.SetLinearForm(new XY(1, 2), new XY(4, 5));
            Assert.AreEqual(new XY(5, 7), p2);
            p2.SetLinearForm(2, new XY(1, 2), new XY(4, 5));
            Assert.AreEqual(new XY(6, 9), p2);
            p2.SetLinearForm(2, new XY(1, 2), 3, new XY(4, 5));
            Assert.AreEqual(new XY(14, 19), p2);
            p2.SetLinearForm(2, new XY(1, 2), 3, new XY(4, 5), new XY(7, 8));
            Assert.AreEqual(new XY(21, 27), p2);
            //TestContext.WriteLine(string.Format(CultureInfo.InvariantCulture, "{0},{1}", gp2.x, gp2.y));
            //TestContext.WriteLine(string.Format(CultureInfo.InvariantCulture, "{0},{1}", new gp_XY(1, 23).Normalized().X(), new gp_XY(1, 23).Normalized().Y()));
        }