Exemple #1
0
        public static BoundingArea GetBoundingArea(float x1, float y1, float x2, float y2)
        {
#if !SIMPLE_BOUNDING_AREA
            if (x1 == x2 || y1 == y2)
            {
                return(new BoundingArea(VisualizationUtils.CreateRectangle(x1, y1, x2, y2)));
            }
            float   delta   = Math.Abs((x2 - x1) / (y2 - y1));
            float   stepMax = (float)Math.Sqrt(mMaxBoxArea / delta + delta * mMaxBoxArea);
            VectorF line    = new VectorF(x1, y1, x2, y2);
            float   lineLen = line.GetLength();
            if (stepMax >= lineLen)
            {
                return(new BoundingArea(VisualizationUtils.CreateRectangle(x1, y1, x2, y2)));
            }
            BoundingArea boundingArea = new BoundingArea();
            int          steps        = (int)Math.Ceiling(lineLen / stepMax);
            VectorF      stepVec      = line;
            stepVec.SetLength(lineLen / (float)steps);
            VectorF pt1 = new VectorF(x1, y1);
            VectorF pt2;
            for (int i = 0; i < steps - 1; i++)
            {
                pt2 = pt1 + stepVec;
                boundingArea.AddRectangles(VisualizationUtils.CreateRectangle(pt1.X, pt1.Y, pt2.X, pt2.Y));
                pt1 = pt2;
            }
            pt2 = new VectorF(x2, y2);
            boundingArea.AddRectangles(VisualizationUtils.CreateRectangle(pt1.X, pt1.Y, pt2.X, pt2.Y));
            return(boundingArea);
#else
            BoundingArea boundingArea = new BoundingArea();
            boundingArea.AddRectangles(VisualizationUtils.CreateRectangle(x1, y1, x2, y2));
            return(boundingArea);
#endif
        }