Skip to content

Commit 33f72d2

Browse files
dovadam-urbanczyk
andauthored
Add support for closed path fillet to Wire.fillet() (#1573)
* Add support for closed path fillet to Wire.fillet() * Precalculate n_{edges,vertices} * Black fix * Add conda list * Get rid of typing_extensions in shapes.py * black fix * Get rid of typing_extensions in sketch.py * Remove typing_extensions from sketch_solver.py --------- Co-authored-by: AU <[email protected]>
1 parent bf47f12 commit 33f72d2

File tree

5 files changed

+30
-8
lines changed

5 files changed

+30
-8
lines changed

appveyor.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ init:
2828
install:
2929
- mamba env create -f environment.yml
3030
- conda activate cadquery
31+
- conda list
3132

3233
build: false
3334

cadquery/occ_impl/shapes.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@
1111
overload,
1212
TypeVar,
1313
cast as tcast,
14+
Literal,
15+
Protocol,
1416
)
15-
from typing_extensions import Literal, Protocol
1617

1718
from io import BytesIO
1819

@@ -2507,13 +2508,18 @@ def fillet(
25072508

25082509
edges = list(self)
25092510
all_vertices = self.Vertices()
2511+
n_edges = len(edges)
2512+
n_vertices = len(all_vertices)
2513+
25102514
newEdges = []
25112515
currentEdge = edges[0]
25122516

25132517
verticesSet = set(vertices) if vertices else set()
25142518

2515-
for i in range(len(edges) - 1):
2516-
nextEdge = edges[i + 1]
2519+
for i in range(n_edges):
2520+
if i == n_edges - 1 and not self.IsClosed():
2521+
break
2522+
nextEdge = edges[(i + 1) % n_edges]
25172523

25182524
# Create a plane that is spanned by currentEdge and nextEdge
25192525
currentDir = currentEdge.tangentAt(1)
@@ -2524,7 +2530,8 @@ def fillet(
25242530
# 1. The edges are parallel
25252531
# 2. The vertex is not in the vertices white list
25262532
if normalDir.Length == 0 or (
2527-
all_vertices[i + 1] not in verticesSet and bool(verticesSet)
2533+
all_vertices[(i + 1) % n_vertices] not in verticesSet
2534+
and bool(verticesSet)
25282535
):
25292536
newEdges.append(currentEdge)
25302537
currentEdge = nextEdge
@@ -2553,8 +2560,11 @@ def fillet(
25532560

25542561
currentEdge = nextEdge
25552562

2556-
# Add the last edge
2557-
newEdges.append(currentEdge)
2563+
# Add the last edge unless we are closed, since then
2564+
# currentEdge is the first edge, which was already added
2565+
# (and clipped)
2566+
if not self.IsClosed():
2567+
newEdges.append(currentEdge)
25582568

25592569
return Wire.assembleEdges(newEdges)
25602570

cadquery/occ_impl/sketch_solver.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from typing import Tuple, Union, Any, Callable, List, Optional, Iterable, Dict, Sequence
2-
from typing_extensions import Literal
2+
from typing import Literal
33
from nptyping import NDArray as Array
44
from nptyping import Float
55
from itertools import accumulate, chain

cadquery/sketch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
Sequence,
1212
TypeVar,
1313
cast as tcast,
14+
Literal,
1415
)
15-
from typing_extensions import Literal
1616
from math import tan, sin, cos, pi, radians, remainder
1717
from itertools import product, chain
1818
from multimethod import multimethod

tests/test_cad_objects.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -780,6 +780,17 @@ def testWireFillet(self):
780780
with self.assertRaises(ValueError):
781781
wfillet = wire.fillet(radius=1.0)
782782

783+
# Test a closed fillet
784+
points = [[0, 0, 0], [5, 4, 0], [8, 3, 1], [10, 0, 0]]
785+
786+
wire = Wire.makePolygon(points, close=True)
787+
wfillet = wire.fillet(radius=0.5)
788+
assert len(wfillet.Edges()) == 2 * len(points)
789+
790+
# Fillet a single vertex
791+
wfillet = wire.fillet(radius=0.5, vertices=wire.Vertices()[0:1])
792+
assert len(wfillet.Edges()) == len(points) + 1
793+
783794

784795
@pytest.mark.parametrize(
785796
"points, close, expected_edges",

0 commit comments

Comments
 (0)