diff options
author | Michael Schwarz <michi.schwarz@gmail.com> | 2014-12-12 18:07:28 +0100 |
---|---|---|
committer | Michael Schwarz <michi.schwarz@gmail.com> | 2014-12-12 18:07:28 +0100 |
commit | 88fef813b0d1013e90c9aa4156cbc836481377a3 (patch) | |
tree | 128b26f48b4a5abfbb803d85ecae48237cb0a238 /support/dxf_export/cspsubdiv.py | |
parent | c02392b65243b3842e273cec36468e21ee376787 (diff) | |
parent | b69003800917a93c5c2b240ede6f83b80f1095cc (diff) | |
download | pogojig-88fef813b0d1013e90c9aa4156cbc836481377a3.tar.gz pogojig-88fef813b0d1013e90c9aa4156cbc836481377a3.tar.bz2 pogojig-88fef813b0d1013e90c9aa4156cbc836481377a3.zip |
Merge branch 'master' into no-examples
Diffstat (limited to 'support/dxf_export/cspsubdiv.py')
-rwxr-xr-x | support/dxf_export/cspsubdiv.py | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/support/dxf_export/cspsubdiv.py b/support/dxf_export/cspsubdiv.py new file mode 100755 index 0000000..c34236a --- /dev/null +++ b/support/dxf_export/cspsubdiv.py @@ -0,0 +1,37 @@ +#!/usr/bin/env python +from bezmisc import * +from ffgeom import * + +def maxdist(((p0x,p0y),(p1x,p1y),(p2x,p2y),(p3x,p3y))): + 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 |