コード例 #1
0
        private static Point ReflectPointIn(Point point, Point anchor)
        {
            Vector magnitude = Point.Subtract(point, anchor);

            // Reflect
            magnitude.Negate();

            return(Point.Add(anchor, magnitude));
        }
コード例 #2
0
ファイル: Rect.cs プロジェクト: pmq20/mono_forked
 public Rect(Point point, Vector vector) : this(point, Point.Add(point, vector))
 {
 }
コード例 #3
0
ファイル: Vector2.cs プロジェクト: Zoomicon/ZUI
 /// <summary>
 /// Initializes a new instance of the <see cref="Vector2"/> class.
 /// </summary>
 /// <param name="start">The starting point.</param>
 /// <param name="lengthX">The length by X-coordinate.</param>
 /// <param name="lengthY">The length by Y-coordinate.</param>
 public Vector2(Point start, double lengthX, double lengthY)
 {
     this.Start = start;
     this.End = start.Add(lengthX, lengthY);
 }
コード例 #4
0
ファイル: Morpher.cs プロジェクト: danielhodek/ImageMorpher
        private DirectBitmap Warp(DirectBitmap bitmap, List <Tuple <Point, Point> > lines, int frameIndex)
        {
            DirectBitmap result = new DirectBitmap(width, height);

            for (int i = 0; i < source.Height; i++)
            {
                for (int j = 0; j < source.Width; j++)
                {
                    double totalWeight = 0;
                    double totalDeltaX = 0;
                    double totalDeltaY = 0;

                    Point t1 = new Point(j, i);

                    for (int k = 0; k < lines.Count; k++)
                    {
                        Tuple <Point, Point>   line  = lines[k];
                        Tuple <Vector, Vector> delta = deltas[k];

                        // Destination
                        Point p1 = Point.Add(line.Item1, delta.Item1 * frameIndex);
                        Point q1 = Point.Add(line.Item2, delta.Item2 * frameIndex);

                        Vector p1q1 = q1 - p1;
                        Vector n1   = new Vector(p1q1.Y, -(p1q1.X));
                        Vector t1p1 = p1 - t1;
                        Vector p1t1 = t1 - p1;

                        double d = (t1p1 * n1) / n1.Length;
                        double f = ((p1t1 * p1q1) / p1q1.Length) / p1q1.Length;

                        // Source
                        Point p2 = line.Item1;
                        Point q2 = line.Item2;

                        Vector p2q2 = q2 - p2;
                        Vector n2   = new Vector(p2q2.Y, -(p2q2.X));
                        n2 /= n2.Length;
                        Point fp = new Point(p2.X + f * p2q2.X, p2.Y + f * p2q2.Y);
                        Point t2 = new Point(fp.X - n2.X * d, fp.Y - n2.Y * d);

                        if (f < 0)
                        {
                            d = t1p1.Length;
                        }
                        else if (f > 1)
                        {
                            Vector t1q1 = t1 - q1;
                            d = t1q1.Length;
                        }

                        double w      = Math.Pow(Math.Pow(p1q1.Length, p) / (a + Math.Abs(d)), b);
                        double deltaX = (t2.X - t1.X) * w;
                        double deltaY = (t2.Y - t1.Y) * w;

                        totalWeight += w;
                        totalDeltaX += deltaX;
                        totalDeltaY += deltaY;
                    }

                    Point sp = new Point(t1.X + (totalDeltaX / totalWeight), t1.Y + (totalDeltaY / totalWeight));

                    if (sp.X < 0)
                    {
                        sp.X = 0;
                    }
                    else if (sp.X > source.Width)
                    {
                        sp.X = source.Width - 1;
                    }
                    if (sp.Y < 0)
                    {
                        sp.Y = 0;
                    }
                    else if (sp.Y > source.Height)
                    {
                        sp.Y = source.Height - 1;
                    }

                    result.SetPixel((int)t1.X, (int)t1.Y, bitmap.GetPixel((int)sp.X, (int)sp.Y));
                }
            }

            return(result);
        }
コード例 #5
0
        private static void Draw(StreamGeometryContext dc, IPathCommand element, IPathCommand previous, Vector startOffset)
        {
            if (element is LineTo)
            {
                dc.LineTo(new System.Windows.Point((element as LineTo).X + startOffset.X, (element as LineTo).Y + startOffset.Y), true, true);
            }
            else if (element is MoveTo)
            {
                dc.LineTo(new System.Windows.Point((element as MoveTo).X + startOffset.X, (element as MoveTo).Y + startOffset.Y), false, true);
            }
            else if (element is CurveTo)
            {
                Point controlStart = Point.Add((element as CurveTo).ControlStart.ToWinPoint(), startOffset);
                Point controlEnd   = Point.Add((element as CurveTo).ControlEnd.ToWinPoint(), startOffset);
                Point end          = Point.Add((element as CurveTo).End.ToWinPoint(), startOffset);
                dc.BezierTo(controlStart, controlEnd, end, true, true);
            }
            else if (element is EllipticalArcTo)
            {
                dc.ArcTo(Point.Add((element as EllipticalArcTo).End.ToWinPoint(), startOffset), (element as EllipticalArcTo).Size.ToWinSize(), (element as EllipticalArcTo).RotationAngle, (element as EllipticalArcTo).IsLargeArc, (element as EllipticalArcTo).SweepDirection == Path.SweepDirection.Clockwise ? System.Windows.Media.SweepDirection.Clockwise : System.Windows.Media.SweepDirection.Counterclockwise, true, true);
            }
            else if (element is SmoothCurveTo)
            {
                SmoothCurveTo item = element as SmoothCurveTo;

                // If previous command is not S or C, then control points are the same
                Point controlStart = item.ControlEnd.ToWinPoint();

                // Else reflect ControlEnd of previous command in StartPoint
                if (previous is SmoothCurveTo)
                {
                    controlStart = ReflectPointIn((previous as SmoothCurveTo).ControlEnd.ToWinPoint(), (previous as SmoothCurveTo).End.ToWinPoint());
                }
                else if (previous is CurveTo)
                {
                    controlStart = ReflectPointIn((previous as CurveTo).ControlEnd.ToWinPoint(), (previous as CurveTo).End.ToWinPoint());
                }

                dc.BezierTo(Point.Add(controlStart, startOffset), Point.Add(item.ControlEnd.ToWinPoint(), startOffset), Point.Add(item.End.ToWinPoint(), startOffset), true, true);
            }
            else if (element is SmoothQuadraticBeizerCurveTo)
            {
                SmoothQuadraticBeizerCurveTo item = element as SmoothQuadraticBeizerCurveTo;

                if (previous is SmoothQuadraticBeizerCurveTo)
                {
                    throw new NotSupportedException();
                }
                else if (previous is QuadraticBeizerCurveTo)
                {
                    throw new NotSupportedException();
                }
                else
                {
                    // If previous command is not Q or T, then draw a line
                    dc.LineTo(item.End.ToWinPoint(), true, true);
                }
            }
            else if (element is QuadraticBeizerCurveTo)
            {
                QuadraticBeizerCurveTo item = element as QuadraticBeizerCurveTo;
                dc.QuadraticBezierTo(Point.Add(item.Control.ToWinPoint(), startOffset), Point.Add(item.End.ToWinPoint(), startOffset), true, true);
            }
        }