Skip to content

Commit

Permalink
chore: partially fix linting
Browse files Browse the repository at this point in the history
  • Loading branch information
gjedlicska committed Feb 8, 2025
1 parent adc0c40 commit 06e2115
Show file tree
Hide file tree
Showing 21 changed files with 192 additions and 174 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
10 changes: 1 addition & 9 deletions src/specklepy/objects/geometry/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,4 @@
from specklepy.objects.geometry.vector import Vector

# re-export them at the geometry package level
__all__ = [
"Arc",
"Line",
"Mesh",
"Plane",
"Point",
"Polyline",
"Vector"
]
__all__ = ["Arc", "Line", "Mesh", "Plane", "Point", "Polyline", "Vector"]
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))
)
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
17 changes: 9 additions & 8 deletions src/specklepy/objects/geometry/mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class Mesh(
"""
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 +49,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 +64,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 +182,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
17 changes: 6 additions & 11 deletions src/specklepy/objects/geometry/polyline.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class Polyline(Base, IHasUnits, ICurve, speckle_type="Objects.Geometry.Polyline"
"""
a polyline curve, defined by a set of vertices.
"""

value: List[float]

def __repr__(self) -> str:
Expand All @@ -25,26 +26,20 @@ def is_closed(self, tolerance: float = 1e-6) -> bool:

# compare first and last points
start = Point(
x=self.value[0],
y=self.value[1],
z=self.value[2],
units=self.units
x=self.value[0], y=self.value[1], z=self.value[2], units=self.units
)
end = Point(
x=self.value[-3],
y=self.value[-2],
z=self.value[-1],
units=self.units
x=self.value[-3], y=self.value[-2], z=self.value[-1], units=self.units
)
return start.distance_to(end) <= tolerance

@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

def calculate_length(self) -> float:
points = self.get_points()
Expand All @@ -70,7 +65,7 @@ def get_points(self) -> List[Point]:
x=self.value[i],
y=self.value[i + 1],
z=self.value[i + 2],
units=self.units
units=self.units,
)
points.append(point)
return points
6 changes: 4 additions & 2 deletions src/specklepy/objects/geometry/vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@


@dataclass(kw_only=True)
class Vector(Base, IHasUnits, speckle_type="Objects.Geometry.Vector", serialize_ignore = {"length"}):
class Vector(
Base, IHasUnits, speckle_type="Objects.Geometry.Vector", serialize_ignore={"length"}
):
"""
a 3-dimensional vector
"""
Expand All @@ -19,4 +21,4 @@ def __repr__(self) -> str:

@property
def length(self) -> float:
return (self.x ** 2 + self.y ** 2 + self.z ** 2) ** 0.5
return (self.x**2 + self.y**2 + self.z**2) ** 0.5
3 changes: 0 additions & 3 deletions src/specklepy/objects/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ def displayValue(self) -> T:
# field interfaces
@dataclass(kw_only=True)
class IHasUnits(metaclass=ABCMeta):

units: str | Units
_units: str = field(repr=False, init=False)

Expand All @@ -63,7 +62,6 @@ def units(self, value: str | Units):

@dataclass(kw_only=True)
class IHasArea(metaclass=ABCMeta):

_area: float = field(init=False, repr=False)

@property
Expand All @@ -79,7 +77,6 @@ def area(self, value: float):

@dataclass(kw_only=True)
class IHasVolume(metaclass=ABCMeta):

_volume: float = field(init=False, repr=False)

@property
Expand Down
4 changes: 3 additions & 1 deletion src/specklepy/objects/primitive.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@


@dataclass(kw_only=True)
class Interval(Base, speckle_type="Objects.Primitive.Interval", serialize_ignore={"length"}):
class Interval(
Base, speckle_type="Objects.Primitive.Interval", serialize_ignore={"length"}
):
start: float = 0.0
end: float = 0.0

Expand Down
2 changes: 1 addition & 1 deletion src/specklepy/objects/tests/asdasd.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from specklepy.objects.geometry import Point, Line
from specklepy.objects.geometry import Line, Point
from specklepy.objects.models.units import Units

p_1 = Point(x=0, y=0, z=0, units=Units.m)
Expand Down
31 changes: 8 additions & 23 deletions src/specklepy/objects/tests/test_arc.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ def sample_plane():

ydir = Vector(x=0.0, y=1.0, z=0.0, units=Units.m)

plane = Plane(origin=origin, normal=normal,
xdir=xdir, ydir=ydir, units=Units.m)
plane = Plane(origin=origin, normal=normal, xdir=xdir, ydir=ydir, units=Units.m)

return plane

Expand All @@ -37,11 +36,7 @@ def sample_plane():
def sample_arc(sample_points, sample_plane):
start, mid, end = sample_points
arc = Arc(
plane=sample_plane,
startPoint=start,
midPoint=mid,
endPoint=end,
units=Units.m
plane=sample_plane, startPoint=start, midPoint=mid, endPoint=end, units=Units.m
)

return arc
Expand All @@ -50,11 +45,7 @@ def sample_arc(sample_points, sample_plane):
def test_arc_creation(sample_points, sample_plane):
start, mid, end = sample_points
arc = Arc(
plane=sample_plane,
startPoint=start,
midPoint=mid,
endPoint=end,
units=Units.m
plane=sample_plane, startPoint=start, midPoint=mid, endPoint=end, units=Units.m
)

assert arc.startPoint == start
Expand All @@ -71,23 +62,17 @@ def test_arc_domain(sample_arc):


def test_arc_radius(sample_arc):

assert sample_arc.radius == pytest.approx(1.0)


def test_arc_length(sample_arc):

assert sample_arc.length == pytest.approx(math.pi)


def test_arc_units(sample_points, sample_plane):
start, mid, end = sample_points
arc = Arc(
plane=sample_plane,
startPoint=start,
midPoint=mid,
endPoint=end,
units=Units.m
plane=sample_plane, startPoint=start, midPoint=mid, endPoint=end, units=Units.m
)

assert arc.units == Units.m.value
Expand All @@ -105,7 +90,7 @@ def test_arc_invalid_construction(sample_points, sample_plane):
startPoint=start,
midPoint=mid,
endPoint=end,
units=Units.m
units=Units.m,
)

with pytest.raises(Exception):
Expand All @@ -114,7 +99,7 @@ def test_arc_invalid_construction(sample_points, sample_plane):
startPoint="not a point",
midPoint=mid,
endPoint=end,
units=Units.m
units=Units.m,
)

with pytest.raises(Exception):
Expand All @@ -123,7 +108,7 @@ def test_arc_invalid_construction(sample_points, sample_plane):
startPoint=start,
midPoint="not a point",
endPoint=end,
units=Units.m
units=Units.m,
)

with pytest.raises(Exception):
Expand All @@ -132,7 +117,7 @@ def test_arc_invalid_construction(sample_points, sample_plane):
startPoint=start,
midPoint=mid,
endPoint="not a point",
units=Units.m
units=Units.m,
)


Expand Down
7 changes: 0 additions & 7 deletions src/specklepy/objects/tests/test_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,19 @@

@pytest.fixture
def sample_points():

p1 = Point(x=0.0, y=0.0, z=0.0, units=Units.m)
p2 = Point(x=3.0, y=4.0, z=0.0, units=Units.m)
return p1, p2


@pytest.fixture
def sample_line(sample_points):

start, end = sample_points
line = Line(start=start, end=end, units=Units.m)
return line


def test_line_creation(sample_points):

start, end = sample_points
line = Line(start=start, end=end, units=Units.m)

Expand All @@ -33,20 +30,17 @@ def test_line_creation(sample_points):


def test_line_domain(sample_line):

# Domain should be automatically initialized to unit interval by ICurve
assert isinstance(sample_line.domain, Interval)
assert sample_line.domain.start == 0.0
assert sample_line.domain.end == 1.0


def test_line_length(sample_line):

assert sample_line.length == 5.0


def test_line_units(sample_points):

start, end = sample_points
line = Line(start=start, end=end, units=Units.m)

Expand All @@ -58,7 +52,6 @@ def test_line_units(sample_points):


def test_line_serialization(sample_line):

serialized = serialize(sample_line)
deserialized = deserialize(serialized)

Expand Down
Loading

0 comments on commit 06e2115

Please sign in to comment.