Skip to content

Commit

Permalink
set jiggle_offset to True in all use cases, except tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mozman committed Oct 14, 2023
1 parent 91be62d commit 860dd34
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 22 deletions.
26 changes: 6 additions & 20 deletions exploration/hatching.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ def polygon_hatching(filename: str):
hole = list(forms.circle(16, radius=4))
hole1 = Vec2.list(forms.translate(hole, (-2, -2)))
hole2 = Vec2.list(forms.translate(hole, (2, 2)))
baseline = hatching.HatchBaseLine(
Vec2(), direction=Vec2(1, 1), offset=Vec2(-1, 1)
)
baseline = hatching.HatchBaseLine(Vec2(), direction=Vec2(1, 1), offset=Vec2(-1, 1))
render_hatch(msp, baseline, polygon, [hole1, hole2])
doc.saveas(CWD / filename)

Expand Down Expand Up @@ -75,16 +73,8 @@ def render_hatch(msp, baseline, polygon, holes=None, offset=Vec2()):
list(forms.turtle("5 r 2 l 5 l 12 l 5 r 2 l 5")),
list(forms.turtle("5 l 2 r 5 l 10 l 5 l 2 r 5")),
list(forms.turtle("2 l 2 r 2 r 2 l 6 " "l 10 l 2 l 2 r 2 r 2 l 6")),
list(
forms.turtle(
"2 l 2 r 2 l 2 r 2 r 4 l 4 l 10 l 2 l 2 r 2 l 2 r 2 r 4 l 4"
)
),
list(
forms.turtle(
"2 r 2 l 2 r 2 l 2 l 4 r 4 l 10 l 2 r 2 l 2 r 2 l 2 l 4 r 4"
)
),
list(forms.turtle("2 l 2 r 2 l 2 r 2 r 4 l 4 l 10 l 2 l 2 r 2 l 2 r 2 r 4 l 4")),
list(forms.turtle("2 r 2 l 2 r 2 l 2 l 4 r 4 l 10 l 2 r 2 l 2 r 2 l 2 l 4 r 4")),
list(
forms.turtle(
"2 l 2 r 2 r 2 l 2 l 4 r 2 r 4 l 2 l 10 l 2 r 2 l 2 l 2 r 2 r 4 l 2 l 4 r 2"
Expand Down Expand Up @@ -146,9 +136,7 @@ def hatch_circular_path(filename: str, size=10, angle=0):
circle = path.unit_circle(segments=8, transform=m)
direction = Vec2.from_deg_angle(angle)
offset = direction.orthogonal() * 0.1
baseline = hatching.HatchBaseLine(
Vec2(0, 0), direction=direction, offset=offset
)
baseline = hatching.HatchBaseLine(Vec2(0, 0), direction=direction, offset=offset)
msp.add_lwpolyline(
circle.flattening(0.1), close=True, dxfattribs={"layer": "POLYGON"}
)
Expand All @@ -173,9 +161,7 @@ def hole_examples(filename: str, size=10, dx=13, angle=0):
]
direction = Vec2.from_deg_angle(angle)
offset = direction.orthogonal() * 0.1
baseline = hatching.HatchBaseLine(
Vec2(0, 0), direction=direction, offset=offset
)
baseline = hatching.HatchBaseLine(Vec2(0, 0), direction=direction, offset=offset)
render_hatch(msp, baseline, forms.square(size), holes)
# adjacent holes
holes = [
Expand Down Expand Up @@ -262,7 +248,7 @@ def debug_hatch():
is_closed=1,
flags=3,
)
for start, end in hatching.hatch_entity(e, 1): # type: ignore
for start, end in hatching.hatch_entity(e, 1, jiggle_origin=True): # type: ignore
msp.add_line(start, end)


Expand Down
2 changes: 1 addition & 1 deletion src/ezdxf/render/hatching.py
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ def _line_segments(vertices: list[Intersection], distance: float) -> Iterator[Li
def hatch_entity(
polygon: DXFPolygon,
filter_text_boxes=True,
jiggle_origin: bool = False,
jiggle_origin: bool = True,
) -> Iterator[tuple[Vec3, Vec3]]:
"""Yields the hatch pattern of the given HATCH or MPOLYGON entity as 3D lines.
Each line is a pair of :class:`~ezdxf.math.Vec3` instances as start- and end
Expand Down
3 changes: 2 additions & 1 deletion tests/test_07_render/test_715_hatching.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,8 @@ def test_explode_earth1_pattern():
is_closed=1,
flags=3,
)
lines = list(hatching.hatch_entity(hatch))
# jiggle_origin=True has random behavior, which is not good for a test!
lines = list(hatching.hatch_entity(hatch, jiggle_origin=False))
assert len(lines) == 139


Expand Down

0 comments on commit 860dd34

Please sign in to comment.