"""The units boundary between the engine and build123d.build123d, like most CAD kernels, works in plain numbers and assumes they aremillimetres. The rest of this engine never uses a bare number. This module isthe one border crossing, and it is deliberately tiny so every crossing is easyto audit: mm(Q_(0.15, "m")) -> 150.0 a length leaving the unit system volume(part) -> Q_(8587.4, "mm^3") mass(part, Q_(1.55, "g/cm^3")) -> Q_(13.3, "g")The classic bug this prevents: handing build123d a length in metres (0.15)where it expects millimetres (150). The part comes out 1000 times too smalland its volume 10^9 times too small (EL01, bug U10), with no error anywhere."""from__future__importannotationsfromhwe.unitsimportQ_,Quantity,quantities,requiredefmm(length:Quantity)->float:"""A length as a bare number of millimetres, for build123d."""returnrequire(length,"[length]","length").m_as("mm")defvolume(part)->Quantity:"""The solid's volume (build123d reports it in cubic millimetres)."""returnQ_(part.volume,"mm^3")@quantities(density="[density]",returns="[mass]")defmass(part,density):"""Mass of a solid part of uniform density: m = density x volume. Returns grams."""return(density*volume(part)).to("g")defcentre_of_mass(part)->tuple[Quantity,Quantity,Quantity]:"""The centre of mass (uniform density) as three lengths in mm. Used from EL02 on."""frombuild123dimportCenterOfc=part.center(CenterOf.MASS)returnQ_(c.X,"mm"),Q_(c.Y,"mm"),Q_(c.Z,"mm")