コード例 #1
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));
        }
コード例 #2
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);
        }
コード例 #3
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));
 }