public int DistanceTo(PointI p) { int tx = this.x - p.x; int ty = this.y - p.y; return((int)MathUtils.Sqrt(MathUtils.Mul(tx, tx) + MathUtils.Mul(ty, ty))); }
public static void SetBoundingPointAtAngle(PointI p, int boundingX, int boundingY, int boundingWidth, int boundingHeight, int angle) { if (angle >= 315 || angle <= 45) { p.Set(boundingX + boundingWidth, boundingY + (boundingHeight * (65536 - (int)((uint)MathUtils.ToShift(angle)) >> 17))); } else if (angle > 45 && angle < 135) { p.Set(boundingX + (boundingWidth * (65536 + (int)((uint)MathUtils.ToShift(angle)) >> 17)), boundingY); } else if (angle >= 135 && angle <= 225) { p.Set(boundingX, boundingY + (boundingHeight * (65536 + (int)((uint)MathUtils.ToShift(angle)) >> 17))); } else { p.Set(boundingX + (boundingWidth * (65536 - (int)((uint)MathUtils.ToShift(angle)) >> 17)), boundingY + boundingHeight); } }
public bool Contains(PointI point) { if (this.x < point.x && this.x + this.width > point.x && this.y < point.y && this.y + this.height > point.y) { return(true); } return(false); }
public PointI TransformPoint(int pointX, int pointY, PointI resultPoint) { int x = (int)(this.m00 * pointX + this.m01 * pointY + this.tx); int y = (int)(this.m10 * pointX + this.m11 * pointY + this.ty); if (resultPoint != null) { resultPoint.Set(x, y); return(resultPoint); } return(new PointI(x, y)); }
public int DistanceTo(PointI p1, PointI p2) { int tx = p2.x - p1.x; int ty = p2.y - p1.y; int u = MathUtils.Div(MathUtils.Mul(x - p1.x, tx) + MathUtils.Mul(y - p1.y, ty), MathUtils.Mul(tx, tx) + MathUtils.Mul(ty, ty)); int ix = p1.x + MathUtils.Mul(u, tx); int iy = p1.y + MathUtils.Mul(u, ty); int dx = ix - x; int dy = iy - y; return((int)MathUtils.Sqrt(MathUtils.Mul(dx, dx) + MathUtils.Mul(dy, dy))); }
public override bool Equals(object obj) { if (this == obj) { return(true); } if (obj == null) { return(false); } if (GetType() != obj.GetType()) { return(false); } PointI other = (PointI)obj; return(Equals(other)); }
public RectBox Offset(PointI point) { x += point.x; y += point.y; return(this); }
public bool Equals(PointI point) { return(Equals(point.x, point.y)); }
public PointI(PointI p) { this.x = p.x; this.y = p.y; }
public PointI Cpy(PointI p) { return(new PointI(p.x, p.y)); }
public PointI Set(PointI p) { this.x = p.x; this.y = p.y; return(this); }
public static bool GetSegmentIntersectionIndices(int x, int y, int w, int h, int x1, int y1, int x2, int y2, int ti1, int ti2, PointI ti, PointI n1, PointI n2) { int dx = x2 - x1; int dy = y2 - y1; int nx = 0, ny = 0; int nx1 = 0, ny1 = 0, nx2 = 0, ny2 = 0; int p, q, r; for (int side = 1; side <= 4; side++) { switch (side) { case 1: nx = -1; ny = 0; p = -dx; q = x1 - x; break; case 2: nx = 1; ny = 0; p = dx; q = x + w - x1; break; case 3: nx = 0; ny = -1; p = -dy; q = y1 - y; break; default: nx = 0; ny = -1; p = dy; q = y + h - y1; break; } if (p == 0) { if (q <= 0) { return(false); } } else { r = q / p; if (p < 0) { if (r > ti2) { return(false); } else if (r > ti1) { ti1 = r; nx1 = nx; ny1 = ny; } } else { if (r < ti1) { return(false); } else if (r < ti2) { ti2 = r; nx2 = nx; ny2 = ny; } } } } ti.Set(ti1, ti2); n1.Set(nx1, ny1); n2.Set(nx2, ny2); return(true); }
public static void GetNearestCorner(int x, int y, int w, int h, int px, int py, PointI result) { result.Set((int)MathUtils.Nearest(px, x, x + w), (int)MathUtils.Nearest(y, y, y + h)); }