Skip to content

Commit

Permalink
formatted
Browse files Browse the repository at this point in the history
  • Loading branch information
dogukankaratas committed Jan 29, 2025
1 parent 7857451 commit ff686b4
Show file tree
Hide file tree
Showing 38 changed files with 946 additions and 787 deletions.
4 changes: 2 additions & 2 deletions src/specklepy/objects/data_objects.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from dataclasses import dataclass, field
from typing import Dict, List

from specklepy.logging.exceptions import SpeckleException
from specklepy.objects.base import Base
from specklepy.objects.interfaces import IDataObject, IGisObject, IHasUnits
from specklepy.logging.exceptions import SpeckleException


@dataclass(kw_only=True)
Expand All @@ -12,7 +13,6 @@ class DataObject(
speckle_type="Objects.Data.DataObject",
detachable={"displayValue"},
):

name: str
properties: Dict[str, object]
displayValue: List[Base]
Expand Down
32 changes: 16 additions & 16 deletions src/specklepy/objects/geometry/__init__.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
from specklepy.objects.geometry.arc import Arc
from specklepy.objects.geometry.line import Line
from specklepy.objects.geometry.mesh import Mesh
from specklepy.objects.geometry.plane import Plane
from specklepy.objects.geometry.point import Point
from specklepy.objects.geometry.polyline import Polyline
from specklepy.objects.geometry.vector import Vector
from specklepy.objects.geometry.box import Box
from specklepy.objects.geometry.circle import Circle
from specklepy.objects.geometry.control_point import ControlPoint
from specklepy.objects.geometry.ellipse import Ellipse
from specklepy.objects.geometry.point_cloud import PointCloud
from specklepy.objects.geometry.polycurve import Polycurve
from specklepy.objects.geometry.spiral import Spiral
from specklepy.objects.geometry.surface import Surface
from .arc import Arc
from .box import Box
from .circle import Circle
from .control_point import ControlPoint
from .ellipse import Ellipse
from .line import Line
from .mesh import Mesh
from .plane import Plane
from .point import Point
from .point_cloud import PointCloud
from .polycurve import Polycurve
from .polyline import Polyline
from .spiral import Spiral
from .surface import Surface
from .vector import Vector

# re-export them at the geometry package level
__all__ = [
Expand All @@ -30,5 +30,5 @@
"PointCloud",
"Polycurve",
"Spiral",
"Surface"
"Surface",
]
10 changes: 6 additions & 4 deletions src/specklepy/objects/geometry/arc.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,16 @@ def length(self) -> float:
start_to_mid = self.startPoint.distance_to(self.midPoint)
mid_to_end = self.midPoint.distance_to(self.endPoint)
r = self.radius
angle = (2 * math.asin(start_to_mid / (2 * r))) + \
(2 * math.asin(mid_to_end / (2 * r)))
angle = (2 * math.asin(start_to_mid / (2 * r))) + (
2 * math.asin(mid_to_end / (2 * r))
)
return r * angle

@property
def measure(self) -> float:
start_to_mid = self.startPoint.distance_to(self.midPoint)
mid_to_end = self.midPoint.distance_to(self.endPoint)
r = self.radius
return (2 * math.asin(start_to_mid / (2 * r))) + \
(2 * math.asin(mid_to_end / (2 * r)))
return (2 * math.asin(start_to_mid / (2 * r))) + (
2 * math.asin(mid_to_end / (2 * r))
)
19 changes: 15 additions & 4 deletions src/specklepy/objects/geometry/box.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,39 @@
import math
from dataclasses import dataclass

from specklepy.objects.base import Base
from specklepy.objects.geometry.plane import Plane
from specklepy.objects.interfaces import IHasArea, IHasUnits, IHasVolume
from specklepy.objects.primitive import Interval
from specklepy.objects.interfaces import IHasUnits, IHasVolume, IHasArea


@dataclass(kw_only=True)
class Box(Base, IHasUnits, IHasArea, IHasVolume, speckle_type="Objects.Geometry.Box"):
"""
a 3-dimensional box oriented on a plane
"""

basePlane: Plane
xSize: Interval
ySize: Interval
zSize: Interval

def __repr__(self) -> str:
return f"{self.__class__.__name__}(basePlane: {self.basePlane}, xSize: {self.xSize}, ySize: {self.ySize}, zSize: {self.zSize}, units: {self.units})"
return (
f"{self.__class__.__name__}("
f"basePlane: {self.basePlane}, "
f"xSize: {self.xSize}, "
f"ySize: {self.ySize}, "
f"zSize: {self.zSize}, "
f"units: {self.units})"
)

@property
def area(self) -> float:
return 2 * (self.xSize.length * self.ySize.length + self.xSize.length * self.zSize.length + self.ySize.length * self.zSize.length)
return 2 * (
self.xSize.length * self.ySize.length
+ self.xSize.length * self.zSize.length
+ self.ySize.length * self.zSize.length
)

@property
def volume(self) -> float:
Expand Down
13 changes: 10 additions & 3 deletions src/specklepy/objects/geometry/circle.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,32 @@
from specklepy.objects.base import Base
from specklepy.objects.geometry.plane import Plane
from specklepy.objects.geometry.point import Point
from specklepy.objects.interfaces import ICurve, IHasUnits, IHasArea
from specklepy.objects.interfaces import ICurve, IHasArea, IHasUnits


@dataclass(kw_only=True)
class Circle(Base, IHasUnits, ICurve, IHasArea, speckle_type="Objects.Geometry.Circle"):
"""
a circular curve based on a plane
"""

plane: Plane
center: Point
radius: float

def __repr__(self) -> str:
return f"{self.__class__.__name__}(plane: {self.plane}, center: {self.center}, radius: {self.radius}, units: {self.units})"
return (
f"{self.__class__.__name__}("
f"plane: {self.plane}, "
f"center: {self.center}, "
f"radius: {self.radius}, "
f"units: {self.units})"
)

@property
def length(self) -> float:
return 2 * math.pi * self.radius

@property
def area(self) -> float:
return math.pi * self.radius ** 2
return math.pi * self.radius**2
10 changes: 9 additions & 1 deletion src/specklepy/objects/geometry/control_point.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,18 @@ class ControlPoint(Base, IHasUnits, speckle_type="Objects.Geometry.ControlPoint"
"""
a single 3-dimensional point
"""

x: float
y: float
z: float
weight: float

def __repr__(self) -> str:
return f"{self.__class__.__name__}(x: {self.x}, y: {self.y}, z: {self.z}, weight: {self.weight}, units: {self.units})"
return (
f"{self.__class__.__name__}("
f"x: {self.x}, "
f"y: {self.y}, "
f"z: {self.z}, "
f"weight: {self.weight}, "
f"units: {self.units})"
)
14 changes: 8 additions & 6 deletions src/specklepy/objects/geometry/ellipse.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

from specklepy.objects.base import Base
from specklepy.objects.geometry.plane import Plane
from specklepy.objects.interfaces import IHasArea, IHasUnits, ICurve
from specklepy.objects.interfaces import ICurve, IHasArea, IHasUnits


@dataclass(kw_only=True)
class Ellipse(Base, IHasUnits, ICurve, IHasArea, speckle_type="Objects.Geometry.Ellipse"):
class Ellipse(
Base, IHasUnits, ICurve, IHasArea, speckle_type="Objects.Geometry.Ellipse"
):
"""
an ellipse
"""
Expand All @@ -17,16 +19,16 @@ class Ellipse(Base, IHasUnits, ICurve, IHasArea, speckle_type="Objects.Geometry.

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

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

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

@area.setter
def area(self, value: float) -> None:
self.__dict__['_area'] = value
self.__dict__["_area"] = value
7 changes: 1 addition & 6 deletions src/specklepy/objects/geometry/line.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,7 @@


@dataclass(kw_only=True)
class Line(
Base,
IHasUnits,
ICurve,
speckle_type="Objects.Geometry.Line"
):
class Line(Base, IHasUnits, ICurve, speckle_type="Objects.Geometry.Line"):
start: Point
end: Point

Expand Down
20 changes: 11 additions & 9 deletions src/specklepy/objects/geometry/mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ class Mesh(
serialize_ignore={"vertices_count", "texture_coordinates_count"},
):
"""
a 3D mesh consisting of vertices and faces with optional colors and texture coordinates
a 3D mesh consisting of vertices and faces
with optional colors and texture coordinates
"""

vertices: List[float]
faces: List[int]
colors: List[int] = field(default_factory=list)
Expand All @@ -48,8 +50,9 @@ def vertices_count(self) -> int:

if len(self.vertices) % 3 != 0:
raise ValueError(
f"Invalid vertices list: length ({len(
self.vertices)}) must be a multiple of 3"
f"Invalid vertices list: length ({
len(self.vertices)
}) must be a multiple of 3"
)
return len(self.vertices) // 3

Expand All @@ -62,19 +65,19 @@ def texture_coordinates_count(self) -> int:

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

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

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

@volume.setter
def volume(self, value: float) -> None:
self.__dict__['_volume'] = value
self.__dict__["_volume"] = value

def calculate_area(self) -> float:
"""
Expand Down Expand Up @@ -180,8 +183,7 @@ def get_face_vertices(self, face_index: int) -> List[Point]:
for j in range(vertex_count):
vertex_index = self.faces[i + j + 1]
if vertex_index >= self.vertices_count:
raise IndexError(
f"Vertex index {vertex_index} out of range")
raise IndexError(f"Vertex index {vertex_index} out of range")
vertices.append(self.get_point(vertex_index))
return vertices

Expand Down
8 changes: 7 additions & 1 deletion src/specklepy/objects/geometry/point.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@ class Point(Base, IHasUnits, speckle_type="Objects.Geometry.Point"):
z: float

def __repr__(self) -> str:
return f"{self.__class__.__name__}(x: {self.x}, y: {self.y}, z: {self.z}, units: {self.units})"
return (
f"{self.__class__.__name__}("
f"x: {self.x}, "
f"y: {self.y}, "
f"z: {self.z}, "
f"units: {self.units})"
)

def distance_to(self, other: "Point") -> float:
"""
Expand Down
6 changes: 5 additions & 1 deletion src/specklepy/objects/geometry/point_cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ class PointCloud(Base, IHasUnits, speckle_type="Objects.Geometry.PointCloud"):
points: list

def __repr__(self) -> str:
return f"{self.__class__.__name__}(points: {len(self.points)}, units: {self.units})"
return (
f"{self.__class__.__name__}("
f"points: {len(self.points)}, "
f"units: {self.units})"
)

# sizes and colors could be added in the future
Loading

0 comments on commit ff686b4

Please sign in to comment.