Skip to content

Commit

Permalink
Improving pylint
Browse files Browse the repository at this point in the history
  • Loading branch information
gumyr committed Jan 1, 2025
1 parent de1edda commit 835433d
Showing 1 changed file with 23 additions and 24 deletions.
47 changes: 23 additions & 24 deletions src/build123d/topology.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,11 @@
Geom_Line,
)
from OCP.GeomAdaptor import GeomAdaptor_Curve
from OCP.GeomAPI import GeomAPI_ProjectPointOnSurf, GeomAPI_IntCS
from OCP.Geom2d import Geom2d_Curve, Geom2d_Line, Geom2d_TrimmedCurve
from OCP.Geom2dAPI import Geom2dAPI_InterCurveCurve
from OCP.GeomAbs import GeomAbs_C0, GeomAbs_Intersection, GeomAbs_JoinType
from OCP.GeomAPI import (
GeomAPI_IntCS,
GeomAPI_Interpolate,
GeomAPI_PointsToBSpline,
GeomAPI_PointsToBSplineSurface,
Expand Down Expand Up @@ -589,8 +589,7 @@ def is_manifold(self) -> bool:
# Extract one or more (if a Compound) shape from self
if self.wrapped is None:
return False
else:
shape_stack = get_top_level_topods_shapes(self.wrapped)
shape_stack = get_top_level_topods_shapes(self.wrapped)

while shape_stack:
shape = shape_stack.pop(0)
Expand Down Expand Up @@ -890,9 +889,11 @@ def __rmul__(self, other):
)
return [loc * self for loc in other]

@abstractmethod
def center(self, *args, **kwargs) -> Vector:
"""All of the derived classes from Shape need a center method"""
# Actually creating the abstract method causes the subclass to pass center_of
# even when not required - possibly this could be improved.
# @abstractmethod
# def center(self, center_of: CenterOf) -> Vector:
# """Compute the center with a specific type of calculation."""

def clean(self) -> Self:
"""clean
Expand Down Expand Up @@ -1768,7 +1769,7 @@ def _to_face(plane: Plane) -> Face:
shape_intersections = self._bool_op((self,), objs, intersect_op)
if isinstance(shape_intersections, ShapeList) and not shape_intersections:
return None
elif (
if (
not isinstance(shape_intersections, ShapeList)
and shape_intersections.is_null()
):
Expand Down Expand Up @@ -2929,7 +2930,7 @@ def group_for(self, shape: T):
return self.group(self.key_f(shape))


class Mixin1D(Shape):
class Mixin1D(Shape, ABC):
"""Methods to add to the Edge and Wire classes"""

def __add__(
Expand Down Expand Up @@ -3818,7 +3819,7 @@ def extract_edges(compound):
return (visible_edges, hidden_edges)


class Mixin2D(Shape):
class Mixin2D(Shape, ABC):
"""Additional methods to add to Face and Shell class"""

project_to_viewport = Mixin1D.project_to_viewport
Expand Down Expand Up @@ -3924,7 +3925,7 @@ def find_intersection_points(
return result


class Mixin3D(Shape):
class Mixin3D(Shape, ABC):
"""Additional methods to add to 3D Shape classes"""

project_to_viewport = Mixin1D.project_to_viewport
Expand Down Expand Up @@ -5310,7 +5311,7 @@ def intersect(

# Find edge intersections
if (edge_plane := edge.common_plane()) is not None: # is a 2D edge
if edge_plane.z_dir == plane.z_dir or -edge_plane.z_dir == plane.z_dir:
if plane.z_dir in (edge_plane.z_dir, -edge_plane.z_dir):
edges_common_to_planes.append(edge)

edges.extend(edges_common_to_planes)
Expand Down Expand Up @@ -6286,7 +6287,7 @@ def location_at(
pln = Plane(origin, x_dir=Vector(x_dir), z_dir=self.normal_at(origin))
return Location(pln)

def center(self, center_of=CenterOf.GEOMETRY) -> Vector:
def center(self, center_of: CenterOf = CenterOf.GEOMETRY) -> Vector:
"""Center of Face
Return the center based on center_of
Expand Down Expand Up @@ -7992,7 +7993,7 @@ def to_tuple(self) -> tuple[float, float, float]:
geom_point = BRep_Tool.Pnt_s(self.wrapped)
return (geom_point.X(), geom_point.Y(), geom_point.Z())

def center(self, *args, **kwargs) -> Vector:
def center(self) -> Vector:
"""The center of a vertex is itself!"""
return Vector(self)

Expand Down Expand Up @@ -8457,33 +8458,33 @@ def trim(self: Wire, start: float, end: float) -> Wire:

edges_uv_values.append((u, v, edge))

new_edges = []
trimmed_edges = []
for u, v, edge in edges_uv_values:
if v < start or u > end: # Edge not needed
continue

if start <= u and v <= end: # keep whole Edge
new_edges.append(edge)
trimmed_edges.append(edge)

elif start >= u and end <= v: # Wire trimmed to single Edge
u_edge = edge.param_at_point(self.position_at(start))
v_edge = edge.param_at_point(self.position_at(end))
u_edge, v_edge = (
(v_edge, u_edge) if u_edge > v_edge else (u_edge, v_edge)
)
new_edges.append(edge.trim(u_edge, v_edge))
trimmed_edges.append(edge.trim(u_edge, v_edge))

elif start <= u: # keep start of Edge
u_edge = edge.param_at_point(self.position_at(end))
if u_edge != 0:
new_edges.append(edge.trim(0, u_edge))
trimmed_edges.append(edge.trim(0, u_edge))

else: # v <= end keep end of Edge
v_edge = edge.param_at_point(self.position_at(start))
if v_edge != 1:
new_edges.append(edge.trim(v_edge, 1))
trimmed_edges.append(edge.trim(v_edge, 1))

return Wire(new_edges)
return Wire(trimmed_edges)

def order_edges(self) -> ShapeList[Edge]:
"""Return the edges in self ordered by wire direction and orientation"""
Expand Down Expand Up @@ -8743,12 +8744,10 @@ def order_chamfer_edges(
edge1, edge2 = edges
if edge1 == reference_edge:
return edge1, edge2
elif edge2 == reference_edge:
if edge2 == reference_edge:
return edge2, edge1
else:
raise ValueError("reference edge not in edges")
else:
return edges
raise ValueError("reference edge not in edges")
return edges

@classmethod
def make_rect(
Expand Down

0 comments on commit 835433d

Please sign in to comment.