public static void Draw(float x1, float y1, float x2, float y2, Graphics gfx, Pen pen, TransformParams tr, BoundingArea.ReadOnly bounding_area) { #if !NO_PARTIAL_RENDERING Utils.ThrowException(gfx == null ? new ArgumentNullException("gfx") : null); Utils.ThrowException(pen == null ? new ArgumentNullException("pen") : null); Utils.ThrowException(tr.NotSet ? new ArgumentValueException("tr") : null); Utils.ThrowException(bounding_area == null ? new ArgumentNullException("bounding_area") : null); Vector2D pt1 = tr.Transform(new Vector2D(x1, y1)); Vector2D pt2 = tr.Transform(new Vector2D(x2, y2)); Vector2D isect_pt1 = new Vector2D(); Vector2D isect_pt2 = new Vector2D(); BoundingArea inflated_area = bounding_area.GetWritableCopy(); inflated_area.Inflate(pen.Width / 2f + 5f, pen.Width / 2f + 5f); ArrayList <KeyDat <float, PointInfo> > points = new ArrayList <KeyDat <float, PointInfo> >(); foreach (RectangleF rect in inflated_area.Rectangles) { if (LineIntersectRectangle(pt1, pt2, rect, ref isect_pt1, ref isect_pt2)) { float dist_pt1 = (pt1 - isect_pt1).GetLength(); // *** don't need sqrt here float dist_pt2 = (pt1 - isect_pt2).GetLength(); // *** don't need sqrt here bool start_pt1 = dist_pt1 < dist_pt2; points.Add(new KeyDat <float, PointInfo>(dist_pt1, new PointInfo(isect_pt1, start_pt1))); points.Add(new KeyDat <float, PointInfo>(dist_pt2, new PointInfo(isect_pt2, !start_pt1))); } } points.Sort(); int ref_count = 0; int start_idx = 0; for (int i = 0; i < points.Count; i++) { PointInfo point_info = points[i].Dat; if (point_info.IsStartPoint) { ref_count++; } else { ref_count--; if (ref_count == 0) { gfx.DrawLine(pen, points[start_idx].Dat.Point, point_info.Point); start_idx = i + 1; } } } #else Draw(x1, y1, x2, y2, gfx, pen, tr); #endif }
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); Vector2DF line = new Vector2DF(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); Vector2DF stepVec = line; stepVec.SetLength(lineLen / (float)steps); Vector2DF pt1 = new Vector2DF(x1, y1); Vector2DF 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 Vector2DF(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 }
public static ArrayList <RectangleF> OptimizeBoundingArea(BoundingArea boundingArea) { return(OptimizeBoundingArea(boundingArea.Rectangles)); }
protected void InvalidateBoundingArea() { mBoundingArea = null; }