Sizes a pasted picture, or a copied area pasted at its true size, in drawing units.
How the precision is kept
A picture's scale is one 64-bit division, drawing width ÷ pixel width, stored as the picture's two axis vectors. A copied area's size in millimeters is turned into drawing units with a factor built from the drawing's units. Pixel counts are whole numbers.
Calculations under this policy
3 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.
One 64-bit division; the result is stored as both axis vectors (ux and vy), so pixels are square. With no width given the picture is one drawing unit per pixel. The fade value is rounded to a whole percent between 0 and 100.
The factor that turns a size in millimeters into the drawing's units.
units per mm = units per point × 72 ÷ 25.4
unitScale (pdfmodel.js) gives drawing units per PDF point from the drawing's units, for example 25.4 ÷ 72 for millimeters and 1 ÷ 72 for inches. It is multiplied by 72 and then divided by 25.4, three rounded operations in all.
The width and height a copied area takes in the drawing, on paper or at its real size.
size = size in mm × units per mm
The area's width and height in millimeters (areaclip.js sizeMm) are each multiplied once by the factor above. Without a scale on the copied sheet the real size is not known and nothing is returned.
pastepic.js
lines 106 to 111
CadCraft 0.8.2
export function areaSize(doc, clip, use = 'real') {
const mm = sizeMm(clip, { use });
if (!mm) return null;
const k = unitsPerMm(doc);
return [mm[0] * k, mm[1] * k];
}
In detail
Method
units per pixel = width ÷ pixel width. Copied area: size in mm × (drawing units per PDF point × 72 ÷ 25.4).
Number types
64-bit numbers; pixel counts are integers.
Approach: 64-bit, direct
Every value is a 64-bit number from input to result. Formulas are closed form or a direct solve, and every comparison uses a stated tolerance.