[boolean] Add basic boolean functionality (boolean() and Polygon.boolean())
This commit is contained in:
parent
5d040061f4
commit
7ad59d6b89
8 changed files with 430 additions and 4 deletions
|
|
@ -1,4 +1,4 @@
|
|||
from typing import Any, cast, TYPE_CHECKING, Self
|
||||
from typing import Any, cast, TYPE_CHECKING, Self, Literal
|
||||
import copy
|
||||
import functools
|
||||
|
||||
|
|
@ -462,3 +462,23 @@ class Polygon(Shape):
|
|||
def __repr__(self) -> str:
|
||||
centroid = self.vertices.mean(axis=0)
|
||||
return f'<Polygon centroid {centroid} v{len(self.vertices)}>'
|
||||
|
||||
def boolean(
|
||||
self,
|
||||
other: Any,
|
||||
operation: Literal['union', 'intersection', 'difference', 'xor'] = 'union',
|
||||
scale: float = 1e6,
|
||||
) -> list['Polygon']:
|
||||
"""
|
||||
Perform a boolean operation using this polygon as the subject.
|
||||
|
||||
Args:
|
||||
other: Polygon, Iterable[Polygon], or raw vertices acting as the CLIP.
|
||||
operation: 'union', 'intersection', 'difference', 'xor'.
|
||||
scale: Scaling factor for integer conversion.
|
||||
|
||||
Returns:
|
||||
A list of resulting Polygons.
|
||||
"""
|
||||
from ..utils.boolean import boolean
|
||||
return boolean([self], other, operation=operation, scale=scale)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue