diff options
author | jaseg <git@jaseg.net> | 2019-09-26 19:45:54 +0200 |
---|---|---|
committer | jaseg <git@jaseg.net> | 2019-09-26 19:45:54 +0200 |
commit | b2eb56076d47af08a11e10fa53446a00b849a13c (patch) | |
tree | 4537c06e2e9bc5b78a731231e6c049c8cd5f376c /support/pogojig/inkscape/cspsubdiv.py | |
parent | 82b88f920a85487372cc6e0b46633e4aa328eb69 (diff) | |
download | pogojig-b2eb56076d47af08a11e10fa53446a00b849a13c.tar.gz pogojig-b2eb56076d47af08a11e10fa53446a00b849a13c.tar.bz2 pogojig-b2eb56076d47af08a11e10fa53446a00b849a13c.zip |
Pogojig mostly done: KiCAD export works
Diffstat (limited to 'support/pogojig/inkscape/cspsubdiv.py')
-rw-r--r-- | support/pogojig/inkscape/cspsubdiv.py | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/support/pogojig/inkscape/cspsubdiv.py b/support/pogojig/inkscape/cspsubdiv.py new file mode 100644 index 0000000..72da473 --- /dev/null +++ b/support/pogojig/inkscape/cspsubdiv.py @@ -0,0 +1,38 @@ +#!/usr/bin/env python +from .bezmisc import * +from .ffgeom import * + +def maxdist(points): + ((p0x,p0y),(p1x,p1y),(p2x,p2y),(p3x,p3y)) = points + p0 = Point(p0x,p0y) + p1 = Point(p1x,p1y) + p2 = Point(p2x,p2y) + p3 = Point(p3x,p3y) + + s1 = Segment(p0,p3) + return max(s1.distanceToPoint(p1),s1.distanceToPoint(p2)) + + +def cspsubdiv(csp,flat): + for sp in csp: + subdiv(sp,flat) + +def subdiv(sp,flat,i=1): + while i < len(sp): + p0 = sp[i-1][1] + p1 = sp[i-1][2] + p2 = sp[i][0] + p3 = sp[i][1] + + b = (p0,p1,p2,p3) + m = maxdist(b) + if m <= flat: + i += 1 + else: + one, two = beziersplitatt(b,0.5) + sp[i-1][2] = one[1] + sp[i][0] = two[2] + p = [one[2],one[3],two[1]] + sp[i:1] = [p] + +# vim: expandtab shiftwidth=4 tabstop=8 softtabstop=4 fileencoding=utf-8 textwidth=99 |