Skip to content
Open
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
16 changes: 16 additions & 0 deletions axi/drawing.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,22 @@ def rotate_and_scale_to_fit(self, width, height, padding=0, step=5):
scale, drawing = max(drawings)
return drawing.scale(scale, scale).center(width, height)

def crop(self, width, height):
paths = []
for path in self.paths:
ok = True
new_path = []
for x, y in path:
if x < 0 or y < 0 or x > width or y > height:
if new_path:
paths.append(new_path)
new_path = []
else:
new_path.append((x,y))
if new_path:
paths.append(new_path)
return Drawing(paths)

def remove_paths_outside(self, width, height):
paths = []
for path in self.paths:
Expand Down