Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow use of a two-dimensional pitch in Path2D.rasterize #1162

Merged
merged 2 commits into from
Feb 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions tests/test_raster.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,17 @@ def test_rasterize(self):
fill=True,
width=2.0)

# rasterize with two-dimensional pitch
pitch = p.extents / 600
filled_2dpitch = p.rasterize(origin=origin,
pitch=pitch,
resolution=resolution,
fill=True,
width=None)

# count the number of filled pixels
fill_cnt = g.np.array(filled).sum()
fill_2dpitch_cnt = g.np.array(filled_2dpitch).sum()
both_cnt = g.np.array(both).sum()
outl_cnt = g.np.array(outline).sum()

Expand All @@ -45,6 +54,8 @@ def test_rasterize(self):
assert both_cnt > outl_cnt
# filled+outline should have more than filled
assert both_cnt > fill_cnt
# A different pitch results in a different image
assert fill_2dpitch_cnt != fill_cnt


if __name__ == '__main__':
Expand Down
2 changes: 1 addition & 1 deletion trimesh/path/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -1045,7 +1045,7 @@ def rasterize(self,

Parameters
------------
pitch: float, length in model space of a pixel edge
pitch: float or (2,) float, length(s) in model space of pixel edges
origin: (2,) float, origin position in model space
resolution: (2,) int, resolution in pixel space
fill: bool, if True will return closed regions as filled
Expand Down
6 changes: 3 additions & 3 deletions trimesh/path/raster.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ def rasterize(path,
------------
path : Path2D
Original geometry
pitch : float
Length in model space of a pixel edge
pitch : float or (2,) float
Length(s) in model space of pixel edges
origin : (2,) float
Origin position in model space
resolution : (2,) int
Expand All @@ -51,7 +51,7 @@ def rasterize(path,
"""

# check inputs
pitch = float(pitch)
pitch = np.asanyarray(pitch, dtype=np.float64)
origin = np.asanyarray(origin, dtype=np.float64)

# if resolution is None make it larger than path
Expand Down