Пример #1
0
        private static SvgCommand ScalePoint(SvgCommand point, double amount)
        {
            point.x  *= amount;
            point.y  *= amount;
            point.rx *= amount;
            point.ry *= amount;
            point.x1 *= amount;
            point.y1 *= amount;

            return(point);
        }
Пример #2
0
        private static SvgCommand TranslatePoint(SvgCommand point, double deltaX, double deltaY)
        {
            point.x  += deltaX;
            point.y  += deltaY;
            point.rx += deltaX;
            point.ry += deltaY;
            point.x1 += deltaX;
            point.y1 += deltaY;

            return(point);
        }
Пример #3
0
        private static SvgCommand DenormalizePoint(SvgCommand point, SvgCommand center)
        {
            point.x  = point.x + center.x;
            point.y  = point.y + center.y;
            point.x1 = point.x1 + center.x;
            point.y1 = point.y1 + center.y;
            point.rx = point.rx + center.x;
            point.ry = point.ry + center.y;

            return(point);
        }
Пример #4
0
        private static SvgCommand NormalizePoint(SvgCommand point, SvgCommand center)
        {
            point.x  = point.x - center.x;
            point.y  = point.y - center.y;
            point.x1 = point.x1 - center.x;
            point.y1 = point.y1 - center.y;
            point.rx = point.rx - center.x;
            point.ry = point.ry - center.y;

            return(point);
        }
Пример #5
0
        public SvgCommand lCmd(double x, double y)
        {
            SvgCommand returnValue = new SvgCommand();

            InitPoint(returnValue);

            returnValue.type = PointType.l;
            returnValue.x    = x;
            returnValue.y    = y;

            return(returnValue);
        }
Пример #6
0
 private void InitPoint(SvgCommand point)
 {
     point.x             = 0;
     point.y             = 0;
     point.xAxisRotation = 0;
     point.largeArc      = 0;
     point.sweep         = 0;
     point.rx            = 0;
     point.ry            = 0;
     point.x1            = 0;
     point.y1            = 0;
 }
Пример #7
0
        public SvgCommand qCmd(double x, double y, double x1, double y1)
        {
            SvgCommand returnValue = new SvgCommand();

            InitPoint(returnValue);

            returnValue.type = PointType.q;
            returnValue.x    = x;
            returnValue.y    = y;
            returnValue.x1   = x1;
            returnValue.y1   = y1;

            return(returnValue);
        }
Пример #8
0
        public SvgCommand aCmd(double x, double y, double rx, double ry, double xAxisRotation, double largeArc, double sweep)
        {
            SvgCommand returnValue = new SvgCommand();

            InitPoint(returnValue);

            returnValue.type          = PointType.a;
            returnValue.x             = x;
            returnValue.y             = y;
            returnValue.rx            = rx;
            returnValue.ry            = ry;
            returnValue.xAxisRotation = xAxisRotation;
            returnValue.largeArc      = largeArc;
            returnValue.sweep         = sweep;

            return(returnValue);
        }
Пример #9
0
        public static void RotatePathToDegrees(ref SvgElement svg, double degrees, SvgCommand center)
        {
            for (var i = 0; i < svg.Path.Count; i++)
            {
                // Console.WriteLine("start" + svg.Path[i].x + ", " + svg.Path[i].y);

                svg.Path[i] = NormalizePoint(svg.Path[i], center);

                //Console.WriteLine("norm : " + svg.Path[i].x + ", " + svg.Path[i].y);

                svg.Path[i] = RotatePointToDegrees(svg.Path[i], degrees, center);

                //Console.WriteLine("rotate : " + svg.Path[i].x + ", " + svg.Path[i].y);

                svg.Path[i] = DenormalizePoint(svg.Path[i], center);

                //Console.WriteLine("denorm : " + svg.Path[i].x + ", " + svg.Path[i].y);
            }
        }
Пример #10
0
        public SvgCommand DeepCopyPoint(ref SvgCommand toCopy)
        {
            SvgCommand returnValue = new SvgCommand();

            InitPoint(returnValue);

            returnValue.type          = toCopy.type;
            returnValue.x             = toCopy.x;
            returnValue.y             = toCopy.y;
            returnValue.xAxisRotation = toCopy.xAxisRotation;
            returnValue.largeArc      = toCopy.largeArc;
            returnValue.sweep         = toCopy.sweep;
            returnValue.rx            = toCopy.rx;
            returnValue.ry            = toCopy.ry;
            returnValue.x1            = toCopy.x1;
            returnValue.y1            = toCopy.y1;

            return(returnValue);
        }
Пример #11
0
        private static SvgCommand RotatePointToDegrees(SvgCommand point, double degrees, SvgCommand center)
        {
            degrees = degrees * Math.PI / 180;
            double oldVal;

            oldVal  = point.x;
            point.x = Math.Round(point.x * Math.Cos(degrees), 2) - Math.Round(point.y * Math.Sin(degrees), 2);
            point.y = Math.Round(oldVal * Math.Sin(degrees), 2) + Math.Round(point.y * Math.Cos(degrees), 2);

            //Console.WriteLine(point);

            point.x1 = point.x1 * Math.Cos(degrees) - point.y1 * Math.Sin(degrees + 180);
            point.y1 = point.x1 * Math.Sin(degrees) + point.y1 * Math.Cos(degrees + 180);
            point.rx = point.rx * Math.Cos(degrees) - point.ry * Math.Sin(degrees + 180);
            point.ry = point.rx * Math.Sin(degrees) + point.ry * Math.Cos(degrees + 180);



            return(point);
        }
Пример #12
0
        static void testrun1()
        {
            //
            var a = new SvgDocumentParser();
            SvgCommandFactory factory = new SvgCommandFactory();
            SvgCommand        p1      = factory.MCmd(0, 0);
            SvgCommand        p2      = factory.LCmd(70, 70);
            //SvgCommand p3 = factory.LCmd(70, 60);

            SvgElement line = new SvgElement();

            line.Path.Add(p1);
            line.Path.Add(p2);
            //line.Path.Add(p3);
            line.SetAttribute("stroke", "red");
            line.SetAttribute("fill", "transparent");

            //PathOperation.ScalePath(ref line, 0.5);
            //PathOperation.TranslatePath(ref line, 250, 250);

            SvgCommand d = new SvgCommand();

            d.x = 35;
            d.y = 35;

            PathMatrixOperation.RotatePathToDegrees(ref line, 45, d);



            SvgDocumentWriter writer = new SvgDocumentWriter();

            SvgWrapper wrapper = new SvgWrapper();

            wrapper.SetChild("one", line);

            writer.WriteToFile("MySvg.svg", wrapper);
        }
Пример #13
0
        private static double CalculateAngleBetween(SvgCommand point, SvgCommand center)
        {
            point.x -= center.x;
            point.y -= center.y;

            int xSector = point.x < 0 ? -1 : 1;
            int ySector = point.y < 0 ? -1 : 1;

            point.x = Math.Abs(point.x);
            point.y = Math.Abs(point.y);

            double hypotenuse = Math.Sqrt(Math.Pow(point.x, 2) + Math.Pow(point.y, 2));

            double angle = (180 / Math.PI) * Math.Asin(point.y / hypotenuse);

            if (xSector < 1)
            {
                if (ySector < 1) // Sector 2
                {
                    angle += 180;
                }
                else // Sector 2
                {
                    angle += 90;
                }
            }
            else
            {
                if (ySector < 1) // Sector 4
                {
                    angle += 270;
                }
            }
            Console.WriteLine($"Angle : {angle}");
            return(angle);
        }