Skip to content

Commit

Permalink
updated objects
Browse files Browse the repository at this point in the history
  • Loading branch information
dogukankaratas committed Jan 23, 2025
1 parent 516eff4 commit 989c975
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 41 deletions.
18 changes: 2 additions & 16 deletions src/specklepy/objects/geometry/arc.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,18 @@


@dataclass(kw_only=True)
class Arc(Base, IHasUnits, ICurve, speckle_type="Objects.Geometry.Arc", serialize_ignore={"radius", "length"}):
class Arc(Base, IHasUnits, ICurve, speckle_type="Objects.Geometry.Arc"):
plane: Plane
startPoint: Point
midPoint: Point
endPoint: Point

@property
def radius(self) -> float:
return self.__dict__.get('_radius')

@radius.setter
def radius(self, value: float) -> None:
self.__dict__['_radius'] = value
return self.startPoint.distance_to(self.plane.origin)

@property
def length(self) -> float:
return self.__dict__.get('_length')

@length.setter
def length(self, value: float) -> None:
self.__dict__['_length'] = value

def calculate_radius(self) -> float:
return self.startPoint.distance_to(self.plane.origin)

def calculate_length(self) -> float:
start_to_mid = self.startPoint.distance_to(self.midPoint)
mid_to_end = self.midPoint.distance_to(self.endPoint)
r = self.calculate_radius()
Expand Down
12 changes: 2 additions & 10 deletions src/specklepy/objects/geometry/line.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,11 @@ class Line(
Base,
IHasUnits,
ICurve,
speckle_type="Objects.Geometry.Line",
serialize_ignore={"length"}
speckle_type="Objects.Geometry.Line"
):
start: Point
end: Point

@property
def length(self) -> float:
return self.__dict__.get('_length')

@length.setter
def length(self, value: float) -> None:
self.__dict__['_length'] = value

def calculate_length(self) -> float:
return self.start.distance_to(self.end)
self.start.distance_to(self.end)
7 changes: 3 additions & 4 deletions src/specklepy/objects/geometry/mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ class Mesh(
"colors": 62500,
"textureCoordinates": 31250,
},
serialize_ignore={"area", "volume",
"vertices_count", "texture_coordinates_count"},
serialize_ignore={"vertices_count", "texture_coordinates_count"},
):
"""
a 3D mesh consisting of vertices and faces with optional colors and texture coordinates
Expand Down Expand Up @@ -63,15 +62,15 @@ def texture_coordinates_count(self) -> int:

@property
def area(self) -> float:
return self.__dict__.get('_area')
return self.__dict__.get('_area', 0.0)

@area.setter
def area(self, value: float) -> None:
self.__dict__['_area'] = value

@property
def volume(self) -> float:
return self.__dict__.get('_volume')
return self.__dict__.get('_volume', 0.0)

@volume.setter
def volume(self, value: float) -> None:
Expand Down
1 change: 1 addition & 0 deletions src/specklepy/objects/geometry/point.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ def distance_to(self, other: "Point") -> float:
dx = other.x - self.x
dy = other.y - self.y
dz = other.z - self.z

return (dx * dx + dy * dy + dz * dz) ** 0.5
4 changes: 2 additions & 2 deletions src/specklepy/objects/geometry/polyline.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@


@dataclass(kw_only=True)
class Polyline(Base, IHasUnits, ICurve, speckle_type="Objects.Geometry.Polyline", serialize_ignore={"length"}):
class Polyline(Base, IHasUnits, ICurve, speckle_type="Objects.Geometry.Polyline"):
"""
a polyline curve, defined by a set of vertices.
"""
Expand Down Expand Up @@ -40,7 +40,7 @@ def is_closed(self, tolerance: float = 1e-6) -> bool:

@property
def length(self) -> float:
return self.__dict__.get('_length')
return self.__dict__.get('_length', 0.0)

@length.setter
def length(self, value: float) -> None:
Expand Down
2 changes: 1 addition & 1 deletion src/specklepy/objects/geometry/vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


@dataclass(kw_only=True)
class Vector(Base, IHasUnits, speckle_type="Objects.Geometry.Vector"):
class Vector(Base, IHasUnits, speckle_type="Objects.Geometry.Vector", serialize_ignore = {"length"}):
"""
a 3-dimensional vector
"""
Expand Down
9 changes: 1 addition & 8 deletions src/specklepy/objects/primitive.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,7 @@ def __repr__(self) -> str:

@property
def length(self) -> float:
return self.__dict__.get('_length')

@length.setter
def length(self, value: float) -> None:
self.__dict__['_length'] = value

def calculate_length(self) -> float:
return abs(self.end - self.start)
abs(self.end - self.start)

@classmethod
def unit_interval(cls) -> "Interval":
Expand Down

0 comments on commit 989c975

Please sign in to comment.