// 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);
        }
        // new scaling methods rewritten by Lisa as of 8/9/2009 from input from Jake
        public static List <PointR> Scale(List <PointR> pts, double oneDRatio, SizeR size) // scales the oriented bbox based on 1D or 2D
        {
            if (NDollarParameters.Instance.UseUniformScaling)                              // scale to a uniform circle
            {
                // do new thing
                PointR centroid      = Utils.Centroid(pts);
                double radiusSquared = 1.0d;
                foreach (PointR point in pts)
                {
                    double distanceSquared = Math.Pow((centroid.X - point.X), 2.0) + Math.Pow((centroid.Y - point.Y), 2.0);
                    if (distanceSquared > radiusSquared)
                    {
                        radiusSquared = distanceSquared;
                    }
                }

                double factor = size.Width / Math.Sqrt(radiusSquared); //Assume that size is a square and arbitrarily select width
                                                                       //this could also be replaced with a constant value (250?)

                List <PointR> scaledPts = new List <PointR>();
                for (int i = 0; i < pts.Count; i++)
                {
                    PointR p = new PointR((PointR)pts[i]);
                    p.X *= factor;
                    p.Y *= factor;
                    scaledPts.Add(p);
                }
                return(scaledPts);
            }
            else // do old thing
            {
                return(Utils.ScaleByDimension(pts, oneDRatio, size));
            }
        }
        // translates the points by the given delta amounts
        public static List <PointR> TranslateBy(List <PointR> points, SizeR sz)
        {
            List <PointR> newPoints = new List <PointR>(points.Count);

            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);
        }
        // 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);
        }
        // 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);
        }
        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);
        }