Skip to content

Commit

Permalink
topology.py -> incorporate suggested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
jdegenstein authored Jan 31, 2024
1 parent 3c16dc8 commit aa851b6
Showing 1 changed file with 29 additions and 10 deletions.
39 changes: 29 additions & 10 deletions src/build123d/topology.py
Original file line number Diff line number Diff line change
Expand Up @@ -2251,12 +2251,6 @@ def area(self) -> float:

return properties.Mass()

@property
def volume(self) -> float:
"""volume - the volume of this Shape"""
# when density == 1, mass == volume
return Shape.compute_mass(self)

def _apply_transform(self, transformation: gp_Trsf) -> Self:
"""Private Apply Transform
Expand Down Expand Up @@ -3814,9 +3808,9 @@ def __repr__(self):

@property
def volume(self) -> float:
"""volume - the volume of this Shape"""
"""volume - the volume of this Compound"""
# when density == 1, mass == volume
return sum(i.volume for i in self.solids())
return sum(i.volume for i in [*self.get_type(Solid), *self.get_type(Shell)])

def center(self, center_of: CenterOf = CenterOf.MASS) -> Vector:
"""Return center of object
Expand Down Expand Up @@ -5048,7 +5042,7 @@ def to_axis(self) -> Axis:
return Axis(self.position_at(0), self.position_at(1) - self.position_at(0))


class Face(Mixin2D, Shape):
class Face(Shape):
"""a bounded surface that represents part of the boundary of a solid"""

# pylint: disable=too-many-public-methods
Expand All @@ -5066,6 +5060,11 @@ def length(self) -> float:
result = face_vertices[-1].X - face_vertices[0].X
return result

@property
def volume(self) -> float:
"""volume - the volume of this Face, which is always zero"""
return 0.0

@property
def width(self) -> float:
"""width of planar face"""
Expand Down Expand Up @@ -5826,11 +5825,20 @@ def is_inside(self, point: VectorLike, tolerance: float = 1.0e-6) -> bool:
return Compound.make_compound([self]).is_inside(point, tolerance)


class Shell(Mixin2D, Shape):
class Shell(Shape):
"""the outer boundary of a surface"""

_dim = 2

@property
def volume(self) -> float:
"""volume - the volume of this Shell if manifold, otherwise zero"""
# when density == 1, mass == volume
if self.is_manifold:
return Solid.make_solid(self).volume
else:
return 0.0

@classmethod
def make_shell(cls, faces: Iterable[Face]) -> Shell:
"""Create a Shell from provided faces"""
Expand All @@ -5856,6 +5864,12 @@ class Solid(Mixin3D, Shape):

_dim = 3

@property
def volume(self) -> float:
"""volume - the volume of this Solid"""
# when density == 1, mass == volume
return Shape.compute_mass(self)

@classmethod
def make_solid(cls, shell: Shell) -> Solid:
"""Create a Solid object from the surface shell"""
Expand Down Expand Up @@ -6598,6 +6612,11 @@ def __init__(self, *args, **kwargs):
super().__init__(ocp_vx)
self.X, self.Y, self.Z = self.to_tuple()

@property
def volume(self) -> float:
"""volume - the volume of this Vertex, which is always zero"""
return 0.0

def to_tuple(self) -> tuple[float, float, float]:
"""Return vertex as three tuple of floats"""
geom_point = BRep_Tool.Pnt_s(self.wrapped)
Expand Down

0 comments on commit aa851b6

Please sign in to comment.