Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: geometry objects with new structure #373

Merged
merged 17 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
296 changes: 0 additions & 296 deletions src/specklepy/objects/geometry.py

This file was deleted.

18 changes: 18 additions & 0 deletions src/specklepy/objects/geometry/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +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

# re-export them at the geometry package level
__all__ = [
"Arc",
"Line",
"Mesh",
"Plane",
"Point",
"Polyline",
"Vector"
]
31 changes: 31 additions & 0 deletions src/specklepy/objects/geometry/arc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import math
from dataclasses import dataclass

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


@dataclass(kw_only=True)
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.startPoint.distance_to(self.plane.origin)
dogukankaratas marked this conversation as resolved.
Show resolved Hide resolved

@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)))

@property
def length(self) -> float:
return self.radius * self.measure
22 changes: 22 additions & 0 deletions src/specklepy/objects/geometry/line.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from dataclasses import dataclass

from specklepy.objects.base import Base
from specklepy.objects.geometry.point import Point
from specklepy.objects.interfaces import ICurve, IHasUnits


@dataclass(kw_only=True)
class Line(Base, IHasUnits, ICurve, speckle_type="Objects.Geometry.Line"):
"""
a line defined by two points in 3D space
"""

start: Point
end: Point

@property
def length(self) -> float:
"""
calculate the length of the line using Point's distance_to method
"""
return self.start.distance_to(self.end)
Loading