示例#1
0
        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)));
        }
示例#2
0
 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);
     }
 }
示例#3
0
 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);
 }
示例#4
0
        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));
        }
示例#5
0
        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)));
        }
示例#6
0
        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));
        }
示例#7
0
 public RectBox Offset(PointI point)
 {
     x += point.x;
     y += point.y;
     return(this);
 }
示例#8
0
 public bool Equals(PointI point)
 {
     return(Equals(point.x, point.y));
 }
示例#9
0
 public PointI(PointI p)
 {
     this.x = p.x;
     this.y = p.y;
 }
示例#10
0
 public PointI Cpy(PointI p)
 {
     return(new PointI(p.x, p.y));
 }
示例#11
0
 public PointI Set(PointI p)
 {
     this.x = p.x;
     this.y = p.y;
     return(this);
 }
示例#12
0
        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);
        }
示例#13
0
 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));
 }