예제 #1
0
        public Polygon Clone()
        {
            var other = new Polygon();

            other.SetPoints(_Points.ToArray());
            return(other);
        }
예제 #2
0
        public void TestPolygonCollision()
        {
            Polygon a = new Polygon();
            Polygon b = new Polygon();
            Polygon c = new Polygon();

            a.SetPoints(new Vector2[]
            {
                new Vector2(0, 0),
                new Vector2(1, 0),
                new Vector2(1, 1),
                new Vector2(0, 1)
            });

            b.SetPoints(a.Points);
            b.Offset(0.9f,0);

            c.SetPoints(b.Points);
            c.Offset(0.9f, 0);

            var resultA = Polygon.Collision(a, b, new Vector2());
            var resultB = Polygon.Collision(b, c, new Vector2());
            var resultC = Polygon.Collision(a, c, new Vector2());

            Assert.AreEqual(true , resultA.Intersect );
            Assert.AreEqual(true, resultB.Intersect);
            Assert.AreEqual(false, resultC.Intersect);
        }
예제 #3
0
        public void PolygonClone()
        {
            Polygon a = new Polygon();
            a.SetPoints( new[]{
                new Vector2(0, 0),
                new Vector2(2, 0),
                new Vector2(2, 1),
                new Vector2(0, 1),
            });

            var b = a.Clone();
            Assert.AreEqual( 0 , b.Points[0].X );
            Assert.AreEqual(2, b.Points[1].X);
            Assert.AreEqual(1, b.Points[3].Y);
        }
예제 #4
0
 public Polygon Clone()
 {
     var other = new Polygon();
     other.SetPoints(_Points.ToArray());
     return other;
 }
예제 #5
0
 private void _SetPolygon(Regulus.CustomType.Polygon polygon, Vector2[] paths)
 {
     polygon.SetPoints(from p in paths select new Regulus.CustomType.Vector2(p.x, p.y));
 }
예제 #6
0
        public void TestPolygonSerializ()
        {
            var polygon1 = new Polygon();
            polygon1.SetPoints(new[]{
                    new Vector2(0,0),
                    new Vector2(1,0),
                    new Vector2(1,1),
                    new Vector2(0,1)});

            var buffer = Regulus.TypeHelper.Serializer(polygon1);
            var polygon2 = Regulus.TypeHelper.Deserialize<Polygon>(buffer);

            Assert.AreEqual(polygon2.Points[0] , polygon1.Points[0]);
        }
예제 #7
0
        public void TestPolygonXMLSerializ()
        {
            var polygon1 = new Polygon();
            polygon1.SetPoints(new[]{
                    new Vector2(0,0),
                    new Vector2(1,0),
                    new Vector2(1,1),
                    new Vector2(0,1)});
            var xml = "";
            using (var stream = new StringWriter())
            {
                var x = new XmlSerializer(typeof(Polygon));
                x.Serialize(stream, polygon1);
                xml= stream.ToString();
            }
            Polygon polygon2;
            using (var stream = new StringReader(xml))
            {
                var ser = new XmlSerializer(typeof(Polygon));
                polygon2=(Polygon)ser.Deserialize(stream);
            }

            Assert.AreEqual(polygon2.Points[0], polygon1.Points[0]);
        }
예제 #8
0
        public void TestPolygonsXMLSerializ()
        {
            var polygon1 = new Polygon();
            polygon1.SetPoints(new[]{
                    new Vector2(0,0),
                    new Vector2(1,0),
                    new Vector2(1,1),
                    new Vector2(0,1)});
            var polygon2 = new Polygon();
            polygon2.SetPoints(new[]{
                    new Vector2(2,0),
                    new Vector2(1,0),
                    new Vector2(1,1),
                    new Vector2(0,1)});
            var polygons1 = new Polygon[]
            {
                polygon1,
                polygon2
            };
            var xml = "";
            using (var stream = new StringWriter())
            {
                var x = new XmlSerializer(typeof(Polygon[]));
                x.Serialize(stream, polygons1);
                xml = stream.ToString();
            }
            Polygon[] polygons2;
            using (var stream = new StringReader(xml))
            {
                var ser = new XmlSerializer(typeof(Polygon[]));
                polygons2 = (Polygon[])ser.Deserialize(stream);
            }

            Assert.IsTrue( Regulus.Utility.ValueHelper.DeepEqual(polygons2 , polygons1));
        }