public RectangleD(V2D pos, V2D size) { X = pos.X; Y = pos.Y; Width = size.X; Height = size.Y; }
/// <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); } }
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); } }
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); } } } }
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); }
public double Dot(V2D a) { return X * a.X + Y * a.Y; }
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; }
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); }
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)); }
public double Dot(V2D a) { return(X * a.X + Y * a.Y); }
public Tile(string image, V2D pos, V2D size) { ImageFile = image; Position = pos; Size = size; }