From 59f9ecf883f23d784b2c005ce1a8e67bc73823bd Mon Sep 17 00:00:00 2001 From: adam-urbanczyk <13981538+adam-urbanczyk@users.noreply.github.com> Date: Mon, 18 Aug 2025 18:21:00 +0200 Subject: [PATCH] Add tolerance to volume calculation --- cadquery/occ_impl/shapes.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/cadquery/occ_impl/shapes.py b/cadquery/occ_impl/shapes.py index 5e4e8b22b..904111b7e 100644 --- a/cadquery/occ_impl/shapes.py +++ b/cadquery/occ_impl/shapes.py @@ -795,16 +795,17 @@ def _mass_calc_function(obj: "Shape") -> Any: return shape_properties_LUT[type_] @staticmethod - def computeMass(obj: "Shape") -> float: + def computeMass(obj: "Shape", tol: Optional[float] = None) -> float: """ Calculates the 'mass' of an object. :param obj: Compute the mass of this object + :param tol: Numerical integration tolerance (optional). """ Properties = GProp_GProps() calc_function = Shape._mass_calc_function(obj) - calc_function(obj.wrapped, Properties) + calc_function(obj.wrapped, Properties, *(tol if tol else ())) return Properties.Mass() @@ -1010,12 +1011,12 @@ def Area(self) -> float: return Properties.Mass() - def Volume(self) -> float: + def Volume(self, tol: Optional[float] = None) -> float: """ :returns: The volume of this Shape """ # when density == 1, mass == volume - return Shape.computeMass(self) + return Shape.computeMass(self, tol) def _apply_transform(self: T, Tr: gp_Trsf) -> T: