From b792878c3d5a17866315a282b3623efaf2bf50b8 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Mon, 6 Nov 2017 13:24:45 +0000 Subject: [PATCH] break ScadObject out (nfc) Signed-off-by: Ian Jackson --- genscad | 42 +----------------------------------------- scad.py | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 41 deletions(-) create mode 100644 scad.py diff --git a/genscad b/genscad index ca24c9b..6e8bfd9 100755 --- a/genscad +++ b/genscad @@ -6,6 +6,7 @@ import signal signal.signal(signal.SIGINT, signal.SIG_DFL) from moebius import * +from scad import * nomsize = 30; thick = 2.000; @@ -17,47 +18,6 @@ nw = 80 m = Moebius(nv, nw) - -class ScadObject: - def __init__(so): - so._points = [] - so._point_indices = {} - so._triangles = [] - - def writeout(so, objname, scalefactor=1): - print('module %s(){ scale(%s) polyhedron(points=[' % - (objname, scalefactor)) - for p in so._points: print(p, ',') - print('],faces=[') - for t in so._triangles: print(repr(t), ',') - print('],convexity=10); }') - so._points = None - - def _point(so, p): - l = list(p) - s = repr(l) - try: - ix = so._point_indices[s] - except KeyError: - ix = len(so._points) - so._points.append(s) - so._point_indices[s] = ix - return ix - - def triangle(so, a,b,c): - ''' a b c are clockwise from inside ''' - so._triangles.append([ so._point(p) for p in (a,b,c) ]) - - def quad(so, cnrs): - ''' cnrs[0] [1] [3] [2] are clockwise from inside ''' - so.triangle(cnrs[0], cnrs[1], cnrs[3]) - so.triangle(cnrs[0], cnrs[3], cnrs[2]) - - def rquad(so, cnrs): - ''' cnrs[0] [1] [3] [2] are anticlockwise from inside ''' - so.triangle(cnrs[0], cnrs[3], cnrs[1]) - so.triangle(cnrs[0], cnrs[2], cnrs[3]) - relthick = thick/(nomsize*2) def make_moebius(objname): diff --git a/scad.py b/scad.py new file mode 100644 index 0000000..889818c --- /dev/null +++ b/scad.py @@ -0,0 +1,43 @@ + +from __future__ import print_function + +class ScadObject: + def __init__(so): + so._points = [] + so._point_indices = {} + so._triangles = [] + + def writeout(so, objname, scalefactor=1): + print('module %s(){ scale(%s) polyhedron(points=[' % + (objname, scalefactor)) + for p in so._points: print(p, ',') + print('],faces=[') + for t in so._triangles: print(repr(t), ',') + print('],convexity=10); }') + so._points = None + + def _point(so, p): + l = list(p) + s = repr(l) + try: + ix = so._point_indices[s] + except KeyError: + ix = len(so._points) + so._points.append(s) + so._point_indices[s] = ix + return ix + + def triangle(so, a,b,c): + ''' a b c are clockwise from inside ''' + so._triangles.append([ so._point(p) for p in (a,b,c) ]) + + def quad(so, cnrs): + ''' cnrs[0] [1] [3] [2] are clockwise from inside ''' + so.triangle(cnrs[0], cnrs[1], cnrs[3]) + so.triangle(cnrs[0], cnrs[3], cnrs[2]) + + def rquad(so, cnrs): + ''' cnrs[0] [1] [3] [2] are anticlockwise from inside ''' + so.triangle(cnrs[0], cnrs[3], cnrs[1]) + so.triangle(cnrs[0], cnrs[2], cnrs[3]) + -- 2.30.2