Skip to content

Commit 8aa2b4a

Browse files
committed
Reformat and sort out typing issues
1 parent 1afbd1d commit 8aa2b4a

File tree

3 files changed

+58
-39
lines changed

3 files changed

+58
-39
lines changed

src/classy_blocks/__init__.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,14 @@
99
from .construct.flat.sketches.disk import FourCoreDisk, HalfDisk, OneCoreDisk, Oval, WrappedDisk
1010
from .construct.flat.sketches.grid import Grid
1111
from .construct.flat.sketches.mapped import MappedSketch
12-
from .construct.flat.sketches.spline_round import QuarterSplineDisk, HalfSplineDisk, SplineDisk
13-
from .construct.flat.sketches.spline_round import QuarterSplineRing, HalfSplineRing, SplineRing
12+
from .construct.flat.sketches.spline_round import (
13+
HalfSplineDisk,
14+
HalfSplineRing,
15+
QuarterSplineDisk,
16+
QuarterSplineRing,
17+
SplineDisk,
18+
SplineRing,
19+
)
1420
from .construct.operations.box import Box
1521
from .construct.operations.connector import Connector
1622
from .construct.operations.extrude import Extrude

src/classy_blocks/construct/flat/sketches/mapped.py

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
from typing import List, Union, TypeVar
1+
from typing import List, Union
22

33
import numpy as np
44

55
from classy_blocks.construct.flat.face import Face
66
from classy_blocks.construct.flat.sketch import Sketch
77
from classy_blocks.types import IndexType, NPPointListType, NPPointType, PointListType
8-
from classy_blocks.util import functions as f
98
from classy_blocks.util import constants
10-
11-
MappedSketchT = TypeVar("MappedSketchT", bound="MappedSketch")
9+
from classy_blocks.util import functions as f
1210

1311

1412
class MappedSketch(Sketch):
@@ -61,37 +59,48 @@ def positions(self) -> NPPointListType:
6159

6260
return np.array([all_points[indexes.index(i)] for i in range(max_index + 1)])
6361

64-
def merge(self, other: Union[List[MappedSketchT], MappedSketchT]):
62+
def merge(self, other: Union[List["MappedSketch"], "MappedSketch"]):
6563
"""Adds a sketch or list of sketches to itself.
6664
New faces and indexes are appended and all duplicate points are removed."""
67-
def merge_two_sketches(sketch_1: MappedSketchT, sketch_2: MappedSketchT) -> None:
65+
66+
def merge_two_sketches(sketch_1: MappedSketch, sketch_2: MappedSketch) -> None:
6867
"""Add sketch_2 to sketch_1"""
6968

7069
# Check planes are oriented the same
7170
if not abs(f.angle_between(sketch_1.normal, sketch_2.normal)) < constants.TOL:
72-
print(f.angle_between(sketch_1.normal, sketch_2.normal)/np.pi, sketch_1.normal, sketch_2.normal)
73-
raise Warning(f"Sketch {sketch_2} with normal {sketch_2.normal} is not oriented as "
74-
f"sketch {sketch_1} with normal {sketch_1.normal}")
71+
print(f.angle_between(sketch_1.normal, sketch_2.normal) / np.pi, sketch_1.normal, sketch_2.normal)
72+
raise Warning(
73+
f"Sketch {sketch_2} with normal {sketch_2.normal} is not oriented as "
74+
f"sketch {sketch_1} with normal {sketch_1.normal}"
75+
)
7576

7677
# All unique points
7778
sketch_1_pos = sketch_1.positions
78-
all_pos = np.asarray([*sketch_1_pos.tolist(),
79-
*[pos for pos in sketch_2.positions if
80-
all(np.linalg.norm(sketch_1_pos - pos.reshape((1, 3)), axis=1) >= constants.TOL)]])
79+
all_pos = np.asarray(
80+
[
81+
*sketch_1_pos.tolist(),
82+
*[
83+
pos
84+
for pos in sketch_2.positions
85+
if all(np.linalg.norm(sketch_1_pos - pos.reshape((1, 3)), axis=1) >= constants.TOL)
86+
],
87+
]
88+
)
8189

8290
sketch_2_ind = np.asarray(sketch_2.indexes)
8391
# Change sketch_2 indexes to new position list.
8492
for i, face in enumerate(sketch_2.faces):
8593
for j, pos in enumerate(face.point_array):
86-
sketch_2_ind[i, j] = np.argwhere(np.linalg.norm(all_pos - pos.reshape((1, 3)),
87-
axis=1 < constants.TOL))[0][0]
94+
sketch_2_ind[i, j] = np.argwhere(
95+
np.linalg.norm(all_pos - pos.reshape((1, 3)), axis=1 < constants.TOL)
96+
)[0][0]
8897

8998
# Append indexes and faces to sketch_1
9099
sketch_1.indexes = [*list(sketch_1.indexes), *sketch_2_ind.tolist()]
91100
sketch_1._faces = [*sketch_1.faces, *sketch_2.faces]
92101

93102
# If list of sketches
94-
if hasattr(other, '__iter__'):
103+
if isinstance(other, list):
95104
for o in other:
96105
merge_two_sketches(self, o)
97106
else:

src/classy_blocks/construct/flat/sketches/spline_round.py

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
from typing import ClassVar, List, Optional
2-
import inspect
2+
33
import numpy as np
44

5+
from classy_blocks.base import transforms as tr
56
from classy_blocks.construct.edges import Origin, Spline
67
from classy_blocks.construct.flat.face import Face
78
from classy_blocks.construct.flat.sketches.disk import DiskBase
@@ -10,7 +11,6 @@
1011
from classy_blocks.types import NPPointType, NPVectorType, PointType
1112
from classy_blocks.util import constants
1213
from classy_blocks.util import functions as f
13-
from classy_blocks.base import transforms as tr
1414

1515

1616
class SplineRound(MappedSketch):
@@ -30,12 +30,7 @@ class SplineRound(MappedSketch):
3030
[1, 2], # axis 1
3131
]
3232

33-
def __init__(
34-
self,
35-
side_1: float,
36-
side_2: float,
37-
**kwargs
38-
):
33+
def __init__(self, side_1: float, side_2: float, **kwargs):
3934
"""
4035
With a normal in x direction corner 1 will be in the y direction and corner 2 the z direction.
4136
note the vectors from the center to corner 1 and 2 should be perpendicular.
@@ -49,8 +44,8 @@ def __init__(
4944
self.side_1 = side_1
5045
self.side_2 = side_2
5146

52-
self.n_outer_spline_points = kwargs.get('n_outer_spline_points', self.n_outer_spline_points)
53-
self.n_straight_spline_points = kwargs.get('n_straight_spline_points', self.n_straight_spline_points)
47+
self.n_outer_spline_points = kwargs.get("n_outer_spline_points", self.n_outer_spline_points)
48+
self.n_straight_spline_points = kwargs.get("n_straight_spline_points", self.n_straight_spline_points)
5449

5550
@property
5651
def center(self):
@@ -120,7 +115,7 @@ def __init__(
120115
corner_2_point: PointType,
121116
side_1: float,
122117
side_2: float,
123-
**kwargs
118+
**kwargs,
124119
) -> None:
125120
"""
126121
With a normal in x direction corner 1 will be in the y direction and corner 2 the z direction.
@@ -264,6 +259,7 @@ def add_edges(self) -> None:
264259

265260
class HalfSplineDisk(QuarterSplineDisk):
266261
"""Sketch for Half oval, elliptical and circular shapes"""
262+
267263
chops: ClassVar = [
268264
[1], # axis 0
269265
[1, 2, 5], # axis 1
@@ -276,7 +272,7 @@ def __init__(
276272
corner_2_point: PointType,
277273
side_1: float,
278274
side_2: float,
279-
**kwargs
275+
**kwargs,
280276
) -> None:
281277
"""
282278
With a normal in x direction corner 1 will be in the y direction and corner 2 the z direction.
@@ -291,8 +287,9 @@ def __init__(
291287

292288
super().__init__(center_point, corner_1_point, corner_2_point, side_1, side_2, **kwargs)
293289
# Create quarter mirrored arround u_1
294-
other_quarter = QuarterSplineDisk(self.center, self.corner_2, 2 * self.center - self.corner_1,
295-
side_2, side_1, **kwargs)
290+
other_quarter = QuarterSplineDisk(
291+
self.center, self.corner_2, 2 * self.center - self.corner_1, side_2, side_1, **kwargs
292+
)
296293
# Merge other_quarter to this quarter.
297294
self.merge(other_quarter)
298295

@@ -306,18 +303,20 @@ def grid(self) -> List[List[Face]]:
306303

307304
class SplineDisk(HalfSplineDisk):
308305
"""Sketch for full oval, elliptical and circular shapes"""
306+
309307
chops: ClassVar = [
310308
[1], # axis 0
311309
[1, 2, 5, 7, 8, 11], # axis 1
312310
]
311+
313312
def __init__(
314313
self,
315314
center_point: PointType,
316315
corner_1_point: PointType,
317316
corner_2_point: PointType,
318317
side_1: float,
319318
side_2: float,
320-
**kwargs
319+
**kwargs,
321320
) -> None:
322321
"""
323322
With a normal in x direction corner 1 will be in the y direction and corner 2 the z direction.
@@ -359,9 +358,8 @@ def __init__(
359358
side_2: float,
360359
width_1: float,
361360
width_2: float,
362-
**kwargs
361+
**kwargs,
363362
):
364-
365363
"""
366364
With a normal in x direction corner 1 will be in the y direction and corner 2 the z direction.
367365
Note the vectors from the center to corner 1 and 2 should be perpendicular.
@@ -401,7 +399,9 @@ def __init__(
401399
p5 = corner_1
402400
p5_2 = corner_1 + self.width_1 * u_1
403401
p6 = center + (self.side_1 + 2 ** (-1 / 2) * r_1) * u_1 + (self.side_2 + 2 ** (-1 / 2) * r_2) * u_2
404-
p6_2 = center + (self.side_1 + 2 ** (-1 / 2) * r_1_outer) * u_1 + (self.side_2 + 2 ** (-1 / 2) * r_2_outer) * u_2
402+
p6_2 = (
403+
center + (self.side_1 + 2 ** (-1 / 2) * r_1_outer) * u_1 + (self.side_2 + 2 ** (-1 / 2) * r_2_outer) * u_2
404+
)
405405

406406
quad_map = [
407407
[2, 3, 1, 0],
@@ -542,8 +542,10 @@ def add_edges(self) -> None:
542542
self.shell[0].add_edge(3, Origin(self.center))
543543
self.shell[1].add_edge(3, Origin(self.center))
544544

545+
545546
class HalfSplineRing(QuarterSplineRing):
546547
"""Sketch for Half oval, elliptical and circular ring"""
548+
547549
chops: ClassVar = [
548550
[0], # axis 0
549551
[0, 1, 2, 3], # axis 1
@@ -558,7 +560,7 @@ def __init__(
558560
side_2: float,
559561
width_1: float,
560562
width_2: float,
561-
**kwargs
563+
**kwargs,
562564
) -> None:
563565
"""
564566
With a normal in x direction corner 1 will be in the y direction and corner 2 the z direction.
@@ -574,13 +576,15 @@ def __init__(
574576
"""
575577

576578
super().__init__(center_point, corner_1_point, corner_2_point, side_1, side_2, width_1, width_2, **kwargs)
577-
other_quarter = QuarterSplineRing(self.center, self.corner_2, 2 * self.center - self.corner_1,
578-
side_2, side_1, width_2, width_1, **kwargs)
579+
other_quarter = QuarterSplineRing(
580+
self.center, self.corner_2, 2 * self.center - self.corner_1, side_2, side_1, width_2, width_1, **kwargs
581+
)
579582
self.merge(other_quarter)
580583

581584

582585
class SplineRing(HalfSplineRing):
583586
"""Sketch for full oval, elliptical and circular shapes"""
587+
584588
chops: ClassVar = [
585589
[0], # axis 0
586590
[0, 1, 2, 3, 4, 5, 6, 7], # axis 1
@@ -595,7 +599,7 @@ def __init__(
595599
side_2: float,
596600
width_1: float,
597601
width_2: float,
598-
**kwargs
602+
**kwargs,
599603
) -> None:
600604
"""
601605
With a normal in x direction corner 1 will be in the y direction and corner 2 the z direction.

0 commit comments

Comments
 (0)