EntityObject Bounding Box

Mar 17, 2015 at 11:42 PM
There is a plan to support BoundingRectangle for EntityObject ?

Implementing this method for common objects, such point, line, arc, circle, text, would enough to get bbox for lwpolyline or blocks by using the explode method.
Would helpful for example if I want to add some blocks and organize them in an automatic way using their bbox. Todo that a BBox3D class should manage union of Vector3.

Declaring such virtual method on EntityObject would results in an easy implementation for the basic entities while for the not yet implemented entities an exception may be thrown.

Note : in some circumstances may useful to get the bbox referred to another UCS than the WCS, so that virtual method should consider the ucs argument, for example a line (0,0,0)-(1,1,1) could have its start,end points as bbox in wcs while in an ucs where x axis is aligned within the line itself the same bbox should results in (0,0,0)-(1,0,0). I know this is not so easy to implement as I write expecial for some more complex entity (without have to consider that the text extension for example depends on the font used...), but consider that if I have a method like obj.BBox() in first instance without Ucs argument this will return the Wcs bounding rectangle of the object (that is more easy and useful) and if the Ucs version will considered useful in a future would easy to wrap the methods on top of EntityObject like this
public BBox3D BBox() { return BBox(Wcs); }
public virtual BBox3D BBox(Ucs ucs) { throw new NotImplementedException(); }
Let me think what you think about that, If is not preferrable to have a bbox not fully working in the EntityObject another solution could be to establish an helper like
public static Toolkit
    public static BBox3D BBox(EntityObject obj)
        switch (obj.Type)
            case EntityObject.Point: return new BBox3D((obj as Point).Location);
            default: throw new NotImplementedException();
Mar 18, 2015 at 6:31 PM
This is something I have been thinking for a long time. There was another user that was asking for the implementation of the drawing extents parameters that are stored in the dxf HEADER section, and to calculated that, some kind entity bounding box needs to be implemented. At the moment my main interest was to present the data stored in a dxf in a more meaningful way, not to solve geometric problems; like methods to calculate distances or intersections, stuff that some day I might add, at least for common objects.

My last idea is to implement this through interfaces, while all entities will benefit from having a bounding box (in world coordinates), while some are purely 3d (like polyline, meshes, splines, 3d faces,...), many of them are in essence 2d and are expressed in local coordiantes (lwpolylines, circles, ellipses, images,...). For those, it will be useful to also have a bounding rectangle (in object coordinates). Many times autocad is used for drawing 2d plans where only the x, and y coordinates are really needed. This way, some entities might implement the interface while others don't, without the need of the ugly NotImplementedException(), it is like leaving it unfinished, even if a little bit of casting needs to be done in order to check if it is computable or not.

Also while implementing this for some entities is straight forward, like lines, circles, polylines,... others not so, like texts or mtexts. An spline bounding box could be implemented using the control points, it will not be exact but making a more approximate one can be very costly to compute.