From 103cbb48005f9b057bc4063e6451b07a64249a3b Mon Sep 17 00:00:00 2001 From: YishiMichael Date: Tue, 17 Oct 2023 03:09:53 -0400 Subject: [PATCH 1/2] typing: initialize module .pyi file --- python/pyclipr/__init__.pyi | 227 ++++++++++++++++++++++++++++++++++++ 1 file changed, 227 insertions(+) create mode 100644 python/pyclipr/__init__.pyi diff --git a/python/pyclipr/__init__.pyi b/python/pyclipr/__init__.pyi new file mode 100644 index 0000000..cee819f --- /dev/null +++ b/python/pyclipr/__init__.pyi @@ -0,0 +1,227 @@ +from typing import Any, Literal, Never, overload + +import numpy as np +import numpy.typing as npt + + +class PathType: ... +Subject: PathType = ... +Clip: PathType = ... + + +class ClipType: ... +Union: ClipType = ... +Difference: ClipType = ... +Intersection: ClipType = ... +Xor: ClipType = ... + + +class FillType: ... +EvenOdd: FillType = ... +NonZero: FillType = ... +Positive: FillType = ... +Negative: FillType = ... + + +class JoinType: ... +Square: JoinType = ... # FIXME +Round: JoinType = ... # FIXME +Miter: JoinType = ... + + +class EndType: ... +Square: EndType = ... # FIXME +Butt: EndType = ... +Joined: EndType = ... +Polygon: EndType = ... +Round: EndType = ... # FIXME + + +clipperVersion: str = ... + + +class PolyPath: + def __init__(self) -> Never: ... + + @property + def level(self) -> int: ... + + @property + def parent(self) -> PolyPath: ... + + +class PolyTree: + def __init__(self) -> Never: ... + + @property + def isHole(self) -> bool: ... + + @property + def area(self) -> float: ... + + @property + def attributes(self) -> npt.NDArray[np.float64]: ... + + @property + def polygon(self) -> npt.NDArray[np.float64]: ... + + @property + def children(self) -> list[PolyTree]: ... + + @property + def count(self) -> int: ... + + def __len__(self) -> int: ... + + +class PolyTreeD: + def __init__(self) -> Never: ... + + @property + def isHole(self) -> bool: ... + + @property + def area(self) -> float: ... + + @property + def attributes(self) -> npt.NDArray[np.float64]: ... + + @property + def polygon(self) -> npt.NDArray[np.float64]: ... + + @property + def children(self) -> list[PolyTreeD]: ... + + @property + def count(self) -> int: ... + + def __len__(self) -> int: ... + + +def polyTreeToPaths64(arg0: PolyTree) -> Any: ... # TODO +def orientation(path: Any, scaleFactor: float) -> bool: ... # TODO +def polyTreeToPaths(arg0: PolyTree) -> Any: ... # TODO +def simplifyPath(path: Any, epsilon: float, isOpenPath: bool = ...) -> Any: ... # TODO +def simplifyPaths(paths: Any, epsilon: float, isOpenPath: bool = ...) -> Any: ... # TODO + + +class Clipper: + scaleFactor: float + preserveCollinear: bool + + def addPath( + self, + path: npt.NDArray[np.float64], + pathType: PathType, + isOpen: bool = ... + ) -> None: ... + + def addPaths( + self, + paths: list[npt.NDArray[np.float64]], + pathType: PathType, + isOpen: bool = ... + ) -> None: ... + + @overload + def execute( + self, + clipType: ClipType, + fillType: FillType = ..., + *, + returnOpenPaths: Literal[False] = ..., + returnZ: Literal[False] = ... + ) -> list[npt.NDArray[np.float64]]: ... + + @overload + def execute( + self, + clipType: ClipType, + fillType: FillType = ..., + *, + returnOpenPaths: Literal[False] = ..., + returnZ: Literal[True] = ... + ) -> tuple[ + list[npt.NDArray[np.float64]], + list[npt.NDArray[np.float64]], + list[npt.NDArray[np.float64]] + ]: ... + + @overload + def execute( + self, + clipType: ClipType, + fillType: FillType = ..., + *, + returnOpenPaths: Literal[True] = ..., + returnZ: bool = ... + ) -> tuple[ + list[npt.NDArray[np.float64]], + list[npt.NDArray[np.float64]], + list[npt.NDArray[np.float64]], + list[npt.NDArray[np.float64]] + ]: ... + + @overload + def execute2( + self, + clipType: ClipType, + fillType: FillType = ..., + *, + returnOpenPaths: Literal[False] = ..., + returnZ: bool = ... + ) -> PolyTreeD: ... + + @overload + def execute2( + self, + clipType: ClipType, + fillType: FillType = ..., + *, + returnOpenPaths: Literal[True] = ..., + returnZ: bool = ... + ) -> tuple[ + PolyTreeD, + list[npt.NDArray[np.float64]], + list[npt.NDArray[np.float64]] + ]: ... + + def clear(self) -> None: ... + + def cleanUp(self) -> None: ... + + +class ClipperOffset: + scaleFactor: float + arcTolerance: float + miterLimit: float + preserveCollinear: bool + + def addPath( + self, + path: npt.NDArray[np.float64], + joinType: JoinType, + endType: EndType = ... + ) -> None: ... + + def addPaths( + self, + paths: list[npt.NDArray[np.float64]], + joinType: JoinType, + endType: EndType = ... + ) -> None: ... + + def execute( + self, + delta: float + ) -> list[npt.NDArray[np.float64]]: ... + + def execute2( + self, + delta: float + ) -> PolyTreeD: ... + + def clear(self) -> None: ... + + +__version__: str = ... From 34203eeae1e0df4b06a5ad997327014cf0fba5e6 Mon Sep 17 00:00:00 2001 From: YishiMichael Date: Tue, 17 Oct 2023 03:21:40 -0400 Subject: [PATCH 2/2] typing: add enum variables --- python/pyclipr/__init__.pyi | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/python/pyclipr/__init__.pyi b/python/pyclipr/__init__.pyi index cee819f..bb8d7d9 100644 --- a/python/pyclipr/__init__.pyi +++ b/python/pyclipr/__init__.pyi @@ -4,32 +4,55 @@ import numpy as np import numpy.typing as npt -class PathType: ... +class PathType: + Subject: PathType = ... + Clip: PathType = ... + Subject: PathType = ... Clip: PathType = ... -class ClipType: ... +class ClipType: + Union: ClipType = ... + Difference: ClipType = ... + Intersection: ClipType = ... + Xor: ClipType = ... + Union: ClipType = ... Difference: ClipType = ... Intersection: ClipType = ... Xor: ClipType = ... -class FillType: ... +class FillType: + EvenOdd: FillType = ... + NonZero: FillType = ... + Positive: FillType = ... + Negative: FillType = ... + EvenOdd: FillType = ... NonZero: FillType = ... Positive: FillType = ... Negative: FillType = ... -class JoinType: ... +class JoinType: + Square: JoinType = ... + Round: JoinType = ... + Miter: JoinType = ... + Square: JoinType = ... # FIXME Round: JoinType = ... # FIXME Miter: JoinType = ... -class EndType: ... +class EndType: + Square: EndType = ... + Butt: EndType = ... + Joined: EndType = ... + Polygon: EndType = ... + Round: EndType = ... + Square: EndType = ... # FIXME Butt: EndType = ... Joined: EndType = ...