Ejemplo n.º 1
0
 public RectangleD(V2D pos, V2D size)
 {
     X      = pos.X;
     Y      = pos.Y;
     Width  = size.X;
     Height = size.Y;
 }
Ejemplo n.º 2
0
            /// <summary>
            /// Exact or interpolated distance to specified point (exact if the spline is a straight line)
            /// </summary>
            /// <param name="point"></param>
            /// <returns></returns>
            public float DistanceToPoint(PointF point)
            {
                var a = (V2D)(this.A);
                var b = (V2D)(this.D);
                var c = new V2D(point.X, point.Y);

                if (this.L)
                {
                    return((float)V2D.LineToPointDistance(a, b, c));
                }
                else
                {
                    var d  = -1f;
                    var e  = 0f;
                    var i1 = (V2D)this.I1;
                    var i2 = (V2D)this.I2;
                    var i3 = (V2D)this.I3;
                    d = (float)V2D.LineToPointDistance(a, i1, c);
                    e = (float)V2D.LineToPointDistance(i1, i2, c); if (e < d)
                    {
                        d = e;
                    }
                    e = (float)V2D.LineToPointDistance(i2, i3, c); if (e < d)
                    {
                        d = e;
                    }
                    e = (float)V2D.LineToPointDistance(i3, b, c); if (e < d)
                    {
                        d = e;
                    }
                    return(d);
                }
            }
Ejemplo n.º 3
0
        private void picBox_MouseDown(object sender, MouseEventArgs e)
        {
            if (map != null)
            {
                centerStartDrag = Center;
                mouseStartDrag  = e.Location;

                V2D pt = ((V2D)Center / map.TileSets[Zoom].Muliplier - ((V2D)this.Size / 2) + (V2D)e.Location) * map.TileSets[Zoom].Muliplier;
                MouseDownScaled?.Invoke(this, pt);
            }
        }
Ejemplo n.º 4
0
 private void PicBox_Draw_Paint(object sender, PaintEventArgs e)
 {
     if (map != null)
     {
         if (map.TileSets != null)
         {
             if (map.TileSets.Count > Zoom)
             {
                 V2D pt = ((V2D)this.Size / 2) - (V2D)Center / map.TileSets[Zoom].Muliplier;
                 e.Graphics.TranslateTransform((float)pt.X, (float)pt.Y);
                 e.Graphics.ScaleTransform((float)(1.0 / map.TileSets[Zoom].Muliplier), (float)(1.0 / map.TileSets[Zoom].Muliplier));
                 OnDrawObjectsScaled?.Invoke(this, e.Graphics);
             }
         }
     }
 }
Ejemplo n.º 5
0
    public static double LineToPointDistance(V2D a, V2D b, V2D c)
    {
        var d  = (b - a).Length;
        var d2 = d * d;

        if (d2 == 0d)
        {
            return((c - a).Length);
        }
        var t = ((c - a).Dot(b - a)) / d2;

        if (t < 0d)
        {
            return((c - a).Length);
        }
        else if (t > 1d)
        {
            return((c - b).Length);
        }
        var e = a + t * (b - a);

        return((e - c).Length);
    }
Ejemplo n.º 6
0
 public double Dot(V2D a)
 {
     return X * a.X + Y * a.Y;
 }
Ejemplo n.º 7
0
 public static double LineToPointDistance(V2D a, V2D b, V2D c)
 {
     var d = (b - a).Length;
     var d2 = d * d;
     if (d2 == 0d) return (c - a).Length;
     var t = ((c - a).Dot(b - a)) / d2;
     if (t < 0d) return (c - a).Length;
     else if (t > 1d) return (c - b).Length;
     var e = a + t * (b - a);
     return (e - c).Length;
 }
Ejemplo n.º 8
0
 public static V2D Interpolate(V2D a, V2D b, double t)
 {
     return new V2D(a.X * (1 - t) + b.X * t, a.Y * (1 - t) + b.Y * t);
 }
Ejemplo n.º 9
0
 public static V2D Interpolate(V2D a, V2D b, double t)
 {
     return(new V2D(a.X * (1 - t) + b.X * t, a.Y * (1 - t) + b.Y * t));
 }
Ejemplo n.º 10
0
 public double Dot(V2D a)
 {
     return(X * a.X + Y * a.Y);
 }
Ejemplo n.º 11
0
 public Tile(string image, V2D pos, V2D size)
 {
     ImageFile = image;
     Position  = pos;
     Size      = size;
 }