Table of Contents

Class CadSpatial

Namespace
OpenCAD2D
Assembly
OpenCAD2D.Core.dll

Questions about where things are drawn, for a program that lays a drawing out and wants to score it: the box each entity really takes (Bounds(CadDocument, CadSpace)) and which of them overlap (Overlaps(CadDocument, CadSpace, CadOverlapOptions, Tolerance)). Both read the display list of the space, the items the canvas draws, so the answer is what is on the screen: the letters of an SHX or TrueType word and not its insertion point, the picture of a dimension, the contents of a block however deep and scaled, the columns of an MTEXT, the width of a wide polyline, the area of a hatch. A drawing of 100 000 entities has its answers in a fraction of a second after the list is made, and again after an edit at the cost of the entities the edit changed.

public static class CadSpatial
Inheritance
CadSpatial
Inherited Members

Methods

Bounds(CadDocument, CadSpace)

Gets the box of every entity a space draws, in the order it draws them. The box of an entity is the box of its display items, the same that Bounds holds for the whole space; an entity that draws nothing (on a frozen layer, with no words) has no row. A line from (0, 0) to (100, 0) is the box from (0, 0) to (100, 0); a TEXT 2.5 high and 10 long set at (0, 0) in an SHX font is the box of its letters and of the frame they stand in. A text in a TrueType font is measured by its font's letters, as an MTEXT's words are.

Bounds(CadDocument, IEnumerable<string>)

Gets the boxes of the entities of some handles, in the order given, each in the space that holds it (model space or a layout). A handle the drawing has no entity of, or one that draws nothing, has no row.

Fits(CadDocument, CadSpace, CadFrame, CadFreeSpaceOptions, Tolerance)

Whether a candidate place is free: nothing of the kinds asked about runs through it or comes within the margin of it. The candidate is taken as a word is by Overlaps(CadDocument, CadSpace, CadOverlapOptions, Tolerance), on the real shapes and not their boxes: a line passing a turned frame's corner at 1 mm is outside it, a word whose frame overlaps it by a hair inside the tolerance is outside it. A candidate from (40, 10) to (60, 20) fits beside a line at x 70, and does not fit with a margin of 15 or with the line at x 50.

FreeSpace(CadDocument, CadSpace, DisplayBox, CadFreeSpaceOptions, Tolerance)

Finds the empty places of a frame: the largest rectangles, not turned, that no line or word of the kinds asked about runs through (or comes within the margin of) and that cannot be made larger without doing so. A thing whose box fits in the frame at all lies inside one of them, which is what a program that lays words out looks for. A frame 100 by 50 holding one vertical line at x 40 from y 0 to y 50 has two: from (0, 0) to (40, 50) and from (40, 0) to (100, 50); one short line at x 40 from y 20 to y 30 has four, the two halves of the frame and the strips above and below it. A word is taken by the box of its turned frame, cut into pieces when it is turned off the axes, a line by the boxes of its segments, a slanted one cut into pieces of at most a thirty-second of the frame's shorter side across so that a diagonal does not take the whole square it spans, an arc as the chain it is drawn as, a hatch or any filled area by its box. The margin grows each of them by that much on every side. The rectangles are found by the free-rectangle list of the MaxRects bin packer (Jukka Jylanki, "A Thousand Ways to Pack the Bin", 2010): the list starts as the frame and each obstacle, taken in the order of its box, cuts every rectangle it enters into the largest pieces on either side of it, a piece lying in another rectangle dropped. The list is exact whatever the order. A frame crowded with thousands of small things has thousands of rectangles: give the width and height of the thing to place as the least size and only the rectangles it could stand in are found, which is exact and much faster; a frame so crowded that listing every rectangle takes some seconds is refused.

Overlaps(CadDocument, CadSpace, CadOverlapOptions, Tolerance)

Finds the entities whose words overlap what is drawn near them. A word is the frame of a text (a TEXT, an MTEXT's words one run of a line at a time so that a gap between columns is no word, a dimension's text), the rectangle its height and the width of its letters make, turned as the text is. It overlaps a line, an arc, a polyline or a hatch's edge that runs through it, a filled area it lies in, and the frame of another word it shares an area with; one that only touches it, or comes within the tolerance of its edge, does not. Two parts of one entity never overlap: a dimension's text is not over its own lines. A row is a pair of entities with the box of every place they meet, however many their parts. With a word frame from (0, 0) to (20, 5) and a line from (10, -10) to (10, 10), the pair is one row whose box runs from (10, 0.001) to (10, 4.999) at a tolerance of 0.001.

Select(CadDocument, CadSpace, CadAreaSelection, IReadOnlyList<GeoPoint2>, double)

Takes the entities of a space by where they are drawn, as "Select objects:" takes them, but whole: the answer is not held to the view of a window, so the same drawing gives the same handles with a window or without. A box from (0, 0) to (100, 50) in Window takes a line from (10, 10) to (20, 10) and leaves a circle of radius 30 about (50, 25), which Crossing takes. The pickfirst selection of the drawing is not changed, and objects on locked, off or frozen layers are taken as the space draws them (what draws nothing is not found).