Exemple #1
0
        IEnumerable <Polygon> ExtractPolygon(XElement xelement)
        {
            List <Polygon> ret                  = new List <Polygon>();
            string         pointsString         = xelement.Attribute("points")?.Value;
            string         styleString          = xelement.Attribute("style")?.Value;
            string         transformationString = xelement.Attribute("transform")?.Value;

            string color  = ColorFromStyle(styleString);
            string stroke = StrokeFromStyle(styleString);

            var transformation = new TransformationParser(transformationString).GetTransformation();

            if (!string.IsNullOrEmpty(pointsString))
            {
                var points = pointsString
                             .Split(' ')
                             .Select(position => position.Split(','))
                             .SelectMany(positionParts => AddPoint(positionParts, transformation))
                             .ToList();

                ret.Add(new Polygon(points, color, stroke));
            }

            return(ret);
        }
Exemple #2
0
        public void MatrixAndTranslate()
        {
            TransformationParser tp = new TransformationParser("matrix(2,0,0,2,0,0) translate(3,-4.0)");

            double[] tr = tp.GetTransformation();
            var      p  = new Point(1, 2, tr);

            Assert.AreEqual(5, p.X);
            Assert.AreEqual(0, p.Y);
        }
Exemple #3
0
        public void Rotate()
        {
            TransformationParser tp = new TransformationParser("rotate(90)");

            double[] tr = tp.GetTransformation();
            var      p  = new Point(1, 0, tr);

            Assert.AreEqual(0, Math.Round(p.X, 8));
            Assert.AreEqual(1, Math.Round(p.Y, 8));
        }
Exemple #4
0
        public void Translate()
        {
            TransformationParser tp = new TransformationParser("translate(15, -34.8)");

            double[] tr = tp.GetTransformation();
            var      p  = new Point(1, 2, tr);

            Assert.AreEqual(16, p.X);
            Assert.AreEqual(-32.8, p.Y);
        }
Exemple #5
0
        public void Matrix()
        {
            TransformationParser tp = new TransformationParser("matrix(1,0,0,2,-3, 3)");

            double[] tr = tp.GetTransformation();
            var      p  = new Point(1, 2, tr);

            Assert.AreEqual(-2, p.X);
            Assert.AreEqual(7, p.Y);
        }
Exemple #6
0
        public void SkewY()
        {
            TransformationParser tp = new TransformationParser("skewY(-30)");

            double[] tr = tp.GetTransformation();
            var      p  = new Point(1, 1, tr);

            Assert.AreEqual(1, Math.Round(p.X, 8));
            Assert.AreEqual(Math.Round(1 - 1 / Math.Sqrt(3.0), 8), Math.Round(p.Y, 8));
        }
Exemple #7
0
        public void Scale2()
        {
            TransformationParser tp = new TransformationParser("scale(0.2)");

            double[] tr = tp.GetTransformation();
            var      p  = new Point(-5, 10, tr);

            Assert.AreEqual(-1, Math.Round(p.X, 8));
            Assert.AreEqual(2, Math.Round(p.Y, 8));
        }
Exemple #8
0
        public void Scale1()
        {
            TransformationParser tp = new TransformationParser("scale(3)");

            double[] tr = tp.GetTransformation();
            var      p  = new Point(1, -2, tr);

            Assert.AreEqual(3, Math.Round(p.X, 8));
            Assert.AreEqual(-6, Math.Round(p.Y, 8));
        }
Exemple #9
0
        public void NullIsParsedAsNoTransformation()
        {
            TransformationParser tp = new TransformationParser(null);

            double[] tr = tp.GetTransformation();

            Assert.AreEqual(1, tr[0]);
            Assert.AreEqual(1, tr[3]);

            Assert.AreEqual(0, tr[1]);
            Assert.AreEqual(0, tr[2]);
            Assert.AreEqual(0, tr[4]);
            Assert.AreEqual(0, tr[5]);
        }
Exemple #10
0
        public void EmptyStringIsParsedAsNoTransformation()
        {
            TransformationParser tp = new TransformationParser(string.Empty);

            double[] tr = tp.GetTransformation();

            Assert.AreEqual(1, tr[0]);
            Assert.AreEqual(1, tr[3]);

            Assert.AreEqual(0, tr[1]);
            Assert.AreEqual(0, tr[2]);
            Assert.AreEqual(0, tr[4]);
            Assert.AreEqual(0, tr[5]);
        }