Exemple #1
0
        public void BinaryRountrip()
        {
            var v = new Vector2D(1, 2);

            using (var ms = new MemoryStream())
            {
                var formatter = new BinaryFormatter();
                formatter.Serialize(ms, v);
                ms.Flush();
                ms.Position = 0;
                var roundTrip = (Vector2D)formatter.Deserialize(ms);
                AssertGeometry.AreEqual(v, roundTrip);
            }
        }
Exemple #2
0
        public void BinaryRountrip()
        {
            var v = new Ray3D(new Point3D(1, 2, -3), new UnitVector3D(1, 2, 3));

            using (var ms = new MemoryStream())
            {
                var formatter = new BinaryFormatter();
                formatter.Serialize(ms, v);
                ms.Flush();
                ms.Position = 0;
                var roundTrip = (Ray3D)formatter.Deserialize(ms);
                AssertGeometry.AreEqual(v, roundTrip);
            }
        }
Exemple #3
0
        public void BinaryRountrip()
        {
            var line = new Line3D(new Point3D(1, 2, 3), new Point3D(4, 5, 6));

            using (var ms = new MemoryStream())
            {
                var formatter = new BinaryFormatter();
                formatter.Serialize(ms, line);
                ms.Flush();
                ms.Position = 0;
                var roundTrip = (Line3D)formatter.Deserialize(ms);
                AssertGeometry.AreEqual(line, roundTrip);
            }
        }
Exemple #4
0
        public void RotateToTest(string v1s, string v2s, string @as)
        {
            UnitVector3D?    axis   = string.IsNullOrEmpty(@as) ? (UnitVector3D?)null : UnitVector3D.Parse(@as);
            UnitVector3D     v1     = UnitVector3D.Parse(v1s);
            UnitVector3D     v2     = UnitVector3D.Parse(v2s);
            CoordinateSystem actual = CoordinateSystem.RotateTo(v1, v2, axis);

            Console.WriteLine(actual);
            var rv = actual.Transform(v1);

            AssertGeometry.AreEqual(v2, rv);
            actual = CoordinateSystem.RotateTo(v2, v1, axis);
            rv     = actual.Transform(v2);
            AssertGeometry.AreEqual(v1, rv);
        }
Exemple #5
0
        public void InterSectionWithPlaneTest(string pl1s, string pl2s, string eps, string evs)
        {
            var plane1        = Plane.Parse(pl1s);
            var plane2        = Plane.Parse(pl2s);
            var intersections = new[]
            {
                plane1.IntersectionWith(plane2),
                plane2.IntersectionWith(plane1)
            };

            foreach (var intersection in intersections)
            {
                AssertGeometry.AreEqual(Point3D.Parse(eps), intersection.ThroughPoint);
                AssertGeometry.AreEqual(UnitVector3D.Parse(evs), intersection.Direction);
            }
        }
Exemple #6
0
        public void Rotate(string vs, string @as, string evs)
        {
            var v       = Vector2D.Parse(vs);
            var angle   = Angle.Parse(@as);
            var actuals = new[]
            {
                v.Rotate(angle),
                v.Rotate(angle.Degrees, AngleUnit.Degrees)
            };
            var expected = Vector2D.Parse(evs);

            foreach (var actual in actuals)
            {
                AssertGeometry.AreEqual(expected, actual, 0.01);
            }
        }
Exemple #7
0
        public void MidPoint(string p1s, string p2s, string eps)
        {
            var p1        = Point2D.Parse(p1s);
            var p2        = Point2D.Parse(p2s);
            var centroids = new[]
            {
                Point2D.Centroid(p1, p2),
                Point2D.MidPoint(p1, p2),
            };
            var expected = Point2D.Parse(eps);

            foreach (var centroid in centroids)
            {
                AssertGeometry.AreEqual(expected, centroid);
            }
        }
Exemple #8
0
        public void FromPlanes(string pl1s, string pl2s, string pl3s, string eps)
        {
            var plane1 = Plane.Parse(pl1s);
            var plane2 = Plane.Parse(pl2s);
            var plane3 = Plane.Parse(pl3s);
            var p1     = Point3D.ItersectionOf(plane1, plane2, plane3);
            var p2     = Point3D.ItersectionOf(plane2, plane1, plane3);
            var p3     = Point3D.ItersectionOf(plane2, plane3, plane1);
            var p4     = Point3D.ItersectionOf(plane3, plane1, plane2);
            var p5     = Point3D.ItersectionOf(plane3, plane2, plane1);
            var ep     = Point3D.Parse(eps);

            foreach (var p in new[] { p1, p2, p3, p4, p5 })
            {
                AssertGeometry.AreEqual(ep, p);
            }
        }
Exemple #9
0
        public void XmlRoundTrips()
        {
            var uv         = new UnitVector3D(0.2672612419124244, -0.53452248382484879, 0.80178372573727319);
            var xml        = @"<UnitVector3D X=""0.2672612419124244"" Y=""-0.53452248382484879"" Z=""0.80178372573727319"" />";
            var elementXml = @"<UnitVector3D><X>0.2672612419124244</X><Y>-0.53452248382484879</Y><Z>0.80178372573727319</Z></UnitVector3D>";

            AssertXml.XmlRoundTrips(uv, xml, (e, a) => AssertGeometry.AreEqual(e, a));
            var serializer = new XmlSerializer(typeof(UnitVector3D));
            var actuals    = new[]
            {
                UnitVector3D.ReadFrom(XmlReader.Create(new StringReader(xml))),
                (UnitVector3D)serializer.Deserialize(new StringReader(xml)),
                (UnitVector3D)serializer.Deserialize(new StringReader(elementXml))
            };

            foreach (var actual in actuals)
            {
                AssertGeometry.AreEqual(uv, actual);
            }
        }
Exemple #10
0
        public void ConstructorTest(string ps, string xs, string ys, string zs)
        {
            var origin = Point3D.Parse(ps);
            var xAxis  = Vector3D.Parse(xs);
            var yAxis  = Vector3D.Parse(ys);
            var zAxis  = Vector3D.Parse(zs);
            var css    = new[]
            {
                new CoordinateSystem(origin, xAxis, yAxis, zAxis),
                new CoordinateSystem(xAxis, yAxis, zAxis, origin)
            };

            foreach (var cs in css)
            {
                AssertGeometry.AreEqual(origin, cs.Origin);
                AssertGeometry.AreEqual(xAxis, cs.XAxis);
                AssertGeometry.AreEqual(yAxis, cs.YAxis);
                AssertGeometry.AreEqual(zAxis, cs.ZAxis);
            }
        }
Exemple #11
0
        public void RotationAroundVector(string ps, string @as, string vs, string eps)
        {
            var p                 = Point3D.Parse(ps);
            var angle             = Angle.Parse(@as);
            var coordinateSystems = new[]
            {
                CoordinateSystem.Rotation(angle, UnitVector3D.Parse(vs)),
                CoordinateSystem.Rotation(angle, Vector3D.Parse(vs)),
                CoordinateSystem.Rotation(angle.Degrees, AngleUnit.Degrees, Vector3D.Parse(vs)),
                CoordinateSystem.Rotation(angle.Radians, AngleUnit.Radians, Vector3D.Parse(vs)),
            };
            var expected = Point3D.Parse(eps);

            foreach (var coordinateSystem in coordinateSystems)
            {
                var rotatedPoint = coordinateSystem.Transform(p);
                //Console.WriteLine(coordinateSystem.ToString());
                AssertGeometry.AreEqual(expected, rotatedPoint);
            }
        }
Exemple #12
0
        public void RotationYawPitchRoll(string yaws, string pitchs, string rolls, string ps, string eps)
        {
            var p                 = Point3D.Parse(ps);
            var yaw               = Angle.Parse(yaws);
            var pitch             = Angle.Parse(pitchs);
            var roll              = Angle.Parse(rolls);
            var coordinateSystems = new[]
            {
                CoordinateSystem.Rotation(yaw, pitch, roll),
                CoordinateSystem.Rotation(yaw.Degrees, pitch.Degrees, roll.Degrees, AngleUnit.Degrees),
                CoordinateSystem.Rotation(yaw.Radians, pitch.Radians, roll.Radians, AngleUnit.Radians),
            };
            var expected = Point3D.Parse(eps);

            foreach (var coordinateSystem in coordinateSystems)
            {
                var rotatedPoint = coordinateSystem.Transform(p);
                //Console.WriteLine(coordinateSystem.ToString());
                AssertGeometry.AreEqual(expected, rotatedPoint);
            }
        }
Exemple #13
0
        public void PointFromPlanes(string pl1s, string pl2s, string pl3s, string eps)
        {
            var plane1 = Plane.Parse(pl1s);
            var plane2 = Plane.Parse(pl2s);
            var plane3 = Plane.Parse(pl3s);
            var points = new[]
            {
                Plane.PointFromPlanes(plane1, plane2, plane3),
                Plane.PointFromPlanes(plane2, plane1, plane3),
                Plane.PointFromPlanes(plane1, plane3, plane2),
                Plane.PointFromPlanes(plane2, plane3, plane1),
                Plane.PointFromPlanes(plane3, plane2, plane1),
                Plane.PointFromPlanes(plane3, plane1, plane2),
            };
            var expected = Point3D.Parse(eps);

            foreach (var point in points)
            {
                AssertGeometry.AreEqual(expected, point);
            }
        }
Exemple #14
0
        public void XmlRountrip()
        {
            var          p          = new Point2D(1, 2);
            const string Xml        = @"<Point2D X=""1"" Y=""2"" />";
            const string ElementXml = @"<Point2D><X>1</X><Y>2</Y></Point2D>";

            AssertXml.XmlRoundTrips(p, Xml, (e, a) => AssertGeometry.AreEqual(e, a));
            var serializer = new XmlSerializer(typeof(Point2D));

            var actuals = new[]
            {
                Point2D.ReadFrom(XmlReader.Create(new StringReader(Xml))),
                Point2D.ReadFrom(XmlReader.Create(new StringReader(ElementXml))),
                (Point2D)serializer.Deserialize(new StringReader(Xml)),
                (Point2D)serializer.Deserialize(new StringReader(ElementXml))
            };

            foreach (var actual in actuals)
            {
                AssertGeometry.AreEqual(p, actual);
            }
        }
Exemple #15
0
        public void XmlRoundtrip()
        {
            var          p          = new Point3D(1, -2, 3);
            const string Xml        = @"<Point3D X=""1"" Y=""-2"" Z=""3"" />";
            const string ElementXml = @"<Point3D><X>1</X><Y>-2</Y><Z>3</Z></Point3D>";

            AssertXml.XmlRoundTrips(p, Xml, (expected, actual) => AssertGeometry.AreEqual(expected, actual));
            var serializer = new XmlSerializer(typeof(Point3D));

            var actuals = new[]
            {
                Point3D.ReadFrom(XmlReader.Create(new StringReader(Xml))),
                Point3D.ReadFrom(XmlReader.Create(new StringReader(ElementXml))),
                (Point3D)serializer.Deserialize(new StringReader(Xml)),
                (Point3D)serializer.Deserialize(new StringReader(ElementXml))
            };

            foreach (var actual in actuals)
            {
                AssertGeometry.AreEqual(p, actual);
            }
        }
Exemple #16
0
        public void SetToAlignCoordinateSystemsTest(string fcss, string tcss)
        {
            var fcs = CoordinateSystem.Parse(fcss);
            var tcs = CoordinateSystem.Parse(tcss);

            var css = new[]
            {
                CoordinateSystem.SetToAlignCoordinateSystems(fcs.Origin, fcs.XAxis, fcs.YAxis, fcs.ZAxis, tcs.Origin, tcs.XAxis, tcs.YAxis, tcs.ZAxis),
                CoordinateSystem.CreateMappingCoordinateSystem(fcs, tcs)
            };

            foreach (var cs in css)
            {
                var aligned = cs.Transform(fcs);
                AssertGeometry.AreEqual(tcs.Origin, aligned.Origin);

                AssertGeometry.AreEqual(tcs.XAxis, aligned.XAxis);

                AssertGeometry.AreEqual(tcs.YAxis, aligned.YAxis);

                AssertGeometry.AreEqual(tcs.ZAxis, aligned.ZAxis);
            }
        }
Exemple #17
0
        public void SerializeDeserialize()
        {
            var          v          = new Vector3D(1, -2, 3);
            const string Xml        = @"<Vector3D X=""1"" Y=""-2"" Z=""3"" />";
            const string ElementXml = @"<Vector3D><X>1</X><Y>-2</Y><Z>3</Z></Vector3D>";
            var          roundTrip  = AssertXml.XmlSerializerRoundTrip(v, Xml);

            AssertGeometry.AreEqual(v, roundTrip);

            var serializer = new XmlSerializer(typeof(Vector3D));

            var actuals = new[]
            {
                Vector3D.ReadFrom(XmlReader.Create(new StringReader(Xml))),
                Vector3D.ReadFrom(XmlReader.Create(new StringReader(ElementXml))),
                (Vector3D)serializer.Deserialize(new StringReader(Xml)),
                (Vector3D)serializer.Deserialize(new StringReader(ElementXml))
            };

            foreach (var actual in actuals)
            {
                AssertGeometry.AreEqual(v, actual);
            }
        }
Exemple #18
0
        public void SetToRotateToTest(string vs, string vts, string axisString)
        {
            var          v    = UnitVector3D.Parse(vs);
            var          vt   = UnitVector3D.Parse(vts);
            UnitVector3D?axis = null;

            if (axisString != null)
            {
                axis = UnitVector3D.Parse(axisString);
            }
            CoordinateSystem cs = CoordinateSystem.RotateTo(v, vt, axis);
            var rv = cs.Transform(v);

            AssertGeometry.AreEqual(vt, rv);

            CoordinateSystem invert     = cs.Invert();
            Vector3D         rotateBack = invert.Transform(rv);

            AssertGeometry.AreEqual(v, rotateBack);

            cs         = CoordinateSystem.RotateTo(vt, v, axis);
            rotateBack = cs.Transform(rv);
            AssertGeometry.AreEqual(v, rotateBack);
        }
Exemple #19
0
        public void XmlRoundtrip()
        {
            const string Xml        = @"<Vector2D X=""1"" Y=""2"" />";
            const string ElementXml = @"<Vector2D><X>1</X><Y>2</Y></Vector2D>";
            var          v          = new Vector2D(1, 2);

            AssertXml.XmlRoundTrips(v, Xml, (e, a) => AssertGeometry.AreEqual(e, a));

            var serializer = new XmlSerializer(typeof(Vector2D));


            var actuals = new[]
            {
                Vector2D.ReadFrom(XmlReader.Create(new StringReader(Xml))),
                Vector2D.ReadFrom(XmlReader.Create(new StringReader(ElementXml))),
                (Vector2D)serializer.Deserialize(new StringReader(Xml)),
                (Vector2D)serializer.Deserialize(new StringReader(ElementXml))
            };

            foreach (var actual in actuals)
            {
                AssertGeometry.AreEqual(v, actual);
            }
        }
Exemple #20
0
        public void XmlRoundTrips(string p1s, string xml)
        {
            var plane = Plane.Parse(p1s);

            AssertXml.XmlRoundTrips(plane, xml, (e, a) => AssertGeometry.AreEqual(e, a));
        }
Exemple #21
0
        public void XmlTests(string ps, string vs, bool asElements, string xml)
        {
            var ray = new Ray3D(Point3D.Parse(ps), UnitVector3D.Parse(vs));

            AssertXml.XmlRoundTrips(ray, xml, (e, a) => AssertGeometry.AreEqual(e, a, 1e-6));
        }
Exemple #22
0
        public void ToVectorAndBack(string ps)
        {
            Point3D p = Point3D.Parse(ps);

            AssertGeometry.AreEqual(p, p.ToVector3D().ToPoint3D(), 1e-9);
        }