// scales the points so that they form the size given. does not restore the
        // origin of the box.
        // adapted from ScaleTo() to smartly handle 1D scaling -- ie, if a gesture is 1D,
        // scale to the longer dimension only, or we warp our gestures too much
        // Lisa 12/28/2007
        public static List <PointR> ScaleTo1D(List <PointR> points, SizeR sz)
        {
            List <PointR> newPoints = new List <PointR>(points.Count);
            RectangleR    r         = FindBox(points);

            // scale both by same factor
            double scaleFactor = 0.0;

            if (r.Width > r.Height)
            {
                scaleFactor = r.Width;
            }
            else
            {
                scaleFactor = r.Height;
            }

            for (int i = 0; i < points.Count; i++)
            {
                PointR p = (PointR)points[i];
                if (r.Width != 0d)
                {
                    p.X *= (sz.Width / scaleFactor);
                }

                if (r.Height != 0d)
                {
                    p.Y *= (sz.Height / scaleFactor);
                }
                newPoints.Add(p);
            }
            return(newPoints);
        }
 // copy constructor
 public RectangleR(RectangleR r)
 {
     _x      = r.X;
     _y      = r.Y;
     _width  = r.Width;
     _height = r.Height;
 }
 public override bool Equals(object obj)
 {
     if (obj is RectangleR)
     {
         RectangleR r = (RectangleR)obj;
         return(X == r.X && Y == r.Y && Width == r.Width && Height == r.Height);
     }
     return(false);
 }
        // scales the points so that the length of their shorter side
        // matches the length of the shorter side of the given box.
        // thus, both dimensions are warped proportionally, rather than
        // independently, like in the function ScaleTo.
        public static List <PointR> ScaleToMin(List <PointR> points, RectangleR box)
        {
            List <PointR> newPoints = new List <PointR>(points.Count);
            RectangleR    r         = FindBox(points);

            for (int i = 0; i < points.Count; i++)
            {
                PointR p = (PointR)points[i];
                p.X *= (box.MinSide / r.MinSide);
                p.Y *= (box.MinSide / r.MinSide);
                newPoints.Add(p);
            }
            return(newPoints);
        }
        // scales by the percentages contained in the 'sz' parameter. values of 1.0 would result in the
        // identity scale (that is, no change).
        public static List <PointR> ScaleBy(List <PointR> points, SizeR sz)
        {
            List <PointR> newPoints = new List <PointR>(points.Count);
            RectangleR    r         = FindBox(points);

            for (int i = 0; i < points.Count; i++)
            {
                PointR p = (PointR)points[i];
                p.X *= sz.Width;
                p.Y *= sz.Height;
                newPoints.Add(p);
            }
            return(newPoints);
        }
        // translates the points so that the upper-left corner of their bounding box lies at 'toPt'
        public static List <PointR> TranslateBBoxTo(List <PointR> points, PointR toPt)
        {
            List <PointR> newPoints = new List <PointR>(points.Count);
            RectangleR    r         = Utils.FindBox(points);

            for (int i = 0; i < points.Count; i++)
            {
                PointR p = (PointR)points[i];
                p.X += (toPt.X - r.X);
                p.Y += (toPt.Y - r.Y);
                newPoints.Add(p);
            }
            return(newPoints);
        }
        public static List <PointR> ScaleByDimension(List <PointR> points, double oneDRatio, SizeR size) // scales properly based on 1D or 2D
        {
            RectangleR B         = FindBox(points);
            bool       uniformly = false; // Lisa 8/16/2009; if we're not testing for 1D (i.e., when emulating $1), never scale uniformly

            if (NDollarParameters.Instance.TestFor1D)
            {
                uniformly = (Math.Min(B.Width / B.Height, B.Height / B.Width) <= oneDRatio); // 1D or 2D gesture test
            }
            List <PointR> newpoints = new List <PointR>(points.Count);

            for (int i = 0; i < points.Count; i++)
            {
                double qx = uniformly ? ((PointR)points[i]).X * (size.Width / Math.Max(B.Width, B.Height)) : ((PointR)points[i]).X * (size.Width / B.Width);
                double qy = uniformly ? ((PointR)points[i]).Y * (size.Height / Math.Max(B.Width, B.Height)) : ((PointR)points[i]).Y * (size.Height / B.Height);
                newpoints.Add(new PointR(qx, qy));
            }
            return(newpoints);
        }
        // determine if this gesture is 1D or 2D based on ratio of "oriented" (rotated to 0)
        // bounding box compared to a threshold (determined empirically)
        // Lisa 1/2/2008
        public static bool Is1DGesture(List <PointR> rawPts) //, String name)
        {
            // make a copy of the pts
            List <PointR> pts = new List <PointR>(rawPts);

            // rotate points to 0 (temporarily!)
            double radians = Utils.AngleInRadians(Utils.Centroid(pts), (PointR)pts[0], false);

            pts = Utils.RotateByRadians(pts, -radians); // undo angle

            // determine ratio of height to width to see which side is shorter
            RectangleR r = Utils.FindBox(pts);

            // check for divide by zero
            if ((r.Width == 0) || (r.Height == 0))
            {
                return(true);
            }
            else if ((r.Width / r.Height) < (r.Height / r.Width)) // width is shorter side
            {
                if ((r.Width / r.Height) < 0.30)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else // else height is shorter side
            {
                if ((r.Height / r.Width) < 0.30)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }
        // scales the points so that they form the size given. does not restore the
        // origin of the box.
        public static List <PointR> ScaleTo(List <PointR> points, SizeR sz)
        {
            List <PointR> newPoints = new List <PointR>(points.Count);
            RectangleR    r         = FindBox(points);

            for (int i = 0; i < points.Count; i++)
            {
                PointR p = (PointR)points[i];
                if (r.Width != 0d)
                {
                    p.X *= (sz.Width / r.Width);
                }

                if (r.Height != 0d)
                {
                    p.Y *= (sz.Height / r.Height);
                }
                newPoints.Add(p);
            }
            return(newPoints);
        }