Maps the marks of a redline package from sheet fractions to drawing coordinates and sizes the revision clouds drawn round accepted items.
How the precision is kept
A redline item carries its geometry as fractions (0 to 1) of the sheet's visible area. The fractions are mapped onto a frame in the drawing with one multiplication and one addition per coordinate, in 64-bit. Cloud size and margin are multiples of the drawing's dimension text height.
Calculations under this policy
4 calculations in 1 source file. The code is read from the released app when this page loads. It is the calculation people run, not a copy kept for this page.
The drawing area a redline sheet is mapped onto: a given box, or the extents of everything drawn.
Minimums and maximums only; no arithmetic on the coordinates. A given box is used when its two x values and its two y values differ; extents with zero width or height give no frame.
redline.js
lines 73 to 82
CadCraft 0.8.2
/** The drawing area one sheet maps onto: the box if given ({x0,y0,x1,y1}), else the extents of everything drawn. */
export function frameOf(doc, { box = null } = {}) {
if (box && [box.x0, box.y0, box.x1, box.y1].every((v) => Number.isFinite(v)) && box.x1 !== box.x0 && box.y1 !== box.y0) {
return { x0: Math.min(box.x0, box.x1), y0: Math.min(box.y0, box.y1), x1: Math.max(box.x0, box.x1), y1: Math.max(box.y0, box.y1) };
}
const b = emptyBounds();
for (const e of doc.all()) { const eb = entityBounds(e, doc.blocks); if (validBounds(eb)) { growPt(b, eb.minX, eb.minY); growPt(b, eb.maxX, eb.maxY); } }
if (!validBounds(b) || b.maxX === b.minX || b.maxY === b.minY) return null;
return { x0: b.minX, y0: b.minY, x1: b.maxX, y1: b.maxY };
}
Item geometry in drawing units
64-bit
An item's box, points and center in drawing coordinates.
x = x0 + fx × (x1 − x0); y = y0 + fy × (y1 − y0); center = midpoint of the box
One multiplication and one addition per coordinate in 64-bit. The width and height of the frame are each one subtraction, done once.
redline.js
lines 84 to 96
CadCraft 0.8.2
export function toDrawing(item, frame) {
const w = frame.x1 - frame.x0, h = frame.y1 - frame.y0;
const at = (p) => ({ x: frame.x0 + p[0] * w, y: frame.y0 + p[1] * h });
const f = item.frac;
let box = null;
if (f.box) { const a = at([f.box[0], f.box[1]]), b = at([f.box[2], f.box[3]]); box = { x0: Math.min(a.x, b.x), y0: Math.min(a.y, b.y), x1: Math.max(a.x, b.x), y1: Math.max(a.y, b.y) }; }
const pts = (f.pts || []).map(at);
if (!box && pts.length) {
const b = emptyBounds(); for (const p of pts) growPt(b, p.x, p.y);
box = { x0: b.minX, y0: b.minY, x1: b.maxX, y1: b.maxY };
}
return { box, pts, centre: { x: (box.x0 + box.x1) / 2, y: (box.y0 + box.y1) / 2 } };
}
Cloud arc length and margin
64-bit
The arc length of a revision cloud, the margin round the item and the text height of the revision mark.
base = text height × dimension scale; arc = 4 × base; margin = arc; text = 1.4 × base
Taken from the drawing's current dimension style, with 2.5 and 1 when the style has no text height or scale. Given values for arc and margin replace the defaults.
redline.js
lines 145 to 147
CadCraft 0.8.2
const base = (dim.txt || 2.5) * (dim.scale || 1);
const arcLen = arc || base * 4, margin = pad ?? arcLen;
const th = base * 1.4;
Revision cloud outline
64-bit
The rectangle a revision cloud is drawn round: the item's box grown by the margin.