KicadModTree fixes and extensions
This MR contains several fixes and extensions on the KicadModTree
.
In particular the changes are:
Circle.py
- implement cutting of circles by re-using cutting of arcs (see also
geometric_util.py
below)
Node.py
Node.remove()
got two additional arguments:
-
traverse
(defaultFalse
) which traverses through the complete hierarchy of nodes to check if it can be found and eventually removes it -
virtual
(defaultFalse
) allows to also remove virtual nodes; this will make the internal node information of nodes which have virtual nodes (e.g. PolygonLines) inconsistent, but in certain circumstances this may be required (e.g., if you want to cut the basic Silk shapes by the mask layer).
For this it was convenient to implement several iterators:
- implement a default iterator
Node.__iter__()
to iterate through all (normal + virtual) nodes - implement iterators
Node.normalChildItems()
to iterate through normal children andNode.virtualChildItems()
for virtual children andNode.allChildItems()
to iterate through all children (similar toNode.__iter__()
)
Polygon.py
- an obvious fix of an obviously never executed piece of code
PolygoneLine.py
- implement
isPointInsideSelf()
to check if a point is contained inside a polygon based on computing the winding number - implement
cut()
to cut a polygon-line with any other geometric shape
Vector2D.py
Implementation of convenience functions:
-
scalar * Vector2D
(so far onlyVector2D * scalar
which was annoying) -
norm()
andarg()
to get the cartesian norm and the angle argument separately (not just via to_polar) -
inner()
to calculate the inner product (aka. scalar product) of two vectors -
is_nullvec()
to check if a Vector2D is (close) to the null vector -
normalize()
to scale a vector by its length into a unit-vector
geometric_util.py
- implement
normalize_angle()
to re-project an arbitrary angle to the interval [-180, 180) degrees or [-pi, pi) radians - fix
geometricLine.isPointOnSelf
which sometimes failed if the line was pointing close to 180 degrees - fix constructor of
geometricCircle.__init()
to acceptgeometry
keyword do we can easily go betweenCircle
andgeometricCircle
(was only used inCircle
so far) - implement
getMidPoint
(to get the middle point of the contour) andisPointInsideSelf
(to check if a point is inside or at the contour) for all geometric shapes - implement
geometricCircle.cut()
by re-usinggeometricArc.cut()
; the result is in both cases a list of arcs. - extend
BaseNodeIntersection.intersectTwoNodes()
to handle intersection of iterable compound objects (e.g. PolygoneLine, RectLine, etc)
These changes are a preparation for !832 (merged) (the cleaned up version of !817 (closed)).
TODO:
-
unittest for Node changes -
unittest for Vector2D changes -
unittest for Circle-Circle intersection -
unittest for PolygoneLine intersection extension
Edited by Armin Schoisswohl