diff --git a/fcad/coord.scad b/fcad/coord.scad new file mode 100644 index 0000000..86287bf --- /dev/null +++ b/fcad/coord.scad @@ -0,0 +1,35 @@ +// Short for "coordinate system", including translation, rotation, and scale +// coord: +// fKeyType "type" fType(): fTypeCoord "coord" +// fKeyTranslation "translation" fCoordTranslation(): + +fTypeCoord = "coord"; + +function fIsCoord(x) = ( + fType(x) == fTypeCoord +); + +fKeyTranslation = "translation"; +fKeyRotation = "rotation"; +fKeyScale = "scale"; + +function fCoord(translation=[0, 0, 0], rotation=[0, 0, 0], scale=[1, 1, 1]) = ( + [ + [fKeyType, fTypeCoord], + [fKeyTranslation, translation], + [fKeyRotation, rotation], + [fKeyScale, scale], + ] +); + +function fCoordTranslation(coord) = ( + fMapLookup(fKeyTranslation, coord) +); + +function fCoordRotation(coord) = ( + fMapLookup(fKeyRotation, coord) +); + +function fCoordScale(coord) = ( + fMapLookup(fKeyScale, coord) +); diff --git a/fcad/draw.scad b/fcad/draw.scad index 02d0ec5..fd216f4 100644 --- a/fcad/draw.scad +++ b/fcad/draw.scad @@ -1,10 +1,10 @@ module fDraw(model) { - polyhedron(points=fPoints(model), faces=fFaces(model)); + polyhedron(points=fModelPoints(model), faces=fModelFaces(model)); } module fDrawN(model, scales) { fDraw(model); - points = fPoints(model); + points = fModelPoints(model); model_max = fMaxPoint(model); translation = [for (axis = [0 : 2]) diff --git a/fcad/fcad.scad b/fcad/fcad.scad index 2098316..5014736 100644 --- a/fcad/fcad.scad +++ b/fcad/fcad.scad @@ -1,9 +1,10 @@ +include ; include ; include ; include ; include ; include ; -include ; +include ; include ; include ; include ; diff --git a/fcad/model.scad b/fcad/model.scad index cbe2b49..38ee1ae 100644 --- a/fcad/model.scad +++ b/fcad/model.scad @@ -1,7 +1,7 @@ /// model: /// fKeyType "type" fType(): fTypeModel "model" -/// fKeyPoints "points" fPoints(): [ [x, y, z], ... ] -/// fKeyFaces "faces" fFaces(): [ [ pointIdx, ... ], ... ] +/// fKeyPoints "points" fModelPoints(): [ [x, y, z], ... ] +/// fKeyFaces "faces" fModelFaces(): [ [ pointIdx, ... ], ... ] fTypeModel = "model"; @@ -20,10 +20,10 @@ function fModel(points, faces) = ( ] ); -function fPoints(model) = ( +function fModelPoints(model) = ( fMapLookup(fKeyPoints, model) ); -function fFaces(model) = ( +function fModelFaces(model) = ( fMapLookup(fKeyFaces, model) ); diff --git a/fcad/obj_util.scad b/fcad/model_util.scad similarity index 77% rename from fcad/obj_util.scad rename to fcad/model_util.scad index 917d647..6d19dce 100644 --- a/fcad/obj_util.scad +++ b/fcad/model_util.scad @@ -1,11 +1,11 @@ function fMinPoint(model) = ( [for (axis = [0 : 2]) - min([for (point = fPoints(model)) point[axis]])] + min([for (point = fModelPoints(model)) point[axis]])] ); function fMaxPoint(model) = ( [for (axis = [0 : 2]) - max([for (point = fPoints(model)) point[axis]])] + max([for (point = fModelPoints(model)) point[axis]])] ); function fCenterPoint(model) = ( diff --git a/fcad/translate.scad b/fcad/translate.scad index d0cee27..797387a 100644 --- a/fcad/translate.scad +++ b/fcad/translate.scad @@ -1,13 +1,12 @@ function fTranslate(model, translation) = ( - [ - [fKeyPoints, - [for (point = fPoints(model)) + fModel( + points= + [for (point = fModelPoints(model)) [for (axis = [0 : 2]) point[axis] + translation[axis]] - ] - ], - [fKeyFaces, fFaces(model)], - ] + ], + faces=fModelFaces(model) + ) ); function fZeroN(model, scales) = ( diff --git a/fcad/types.scad b/fcad/types.scad index c3179b7..0976d25 100644 --- a/fcad/types.scad +++ b/fcad/types.scad @@ -44,8 +44,8 @@ function fIsVector(x) = ( ); // Helpers -function fMapLookup(key, model) = ( - [for (pair = model) +function fMapLookup(key, map) = ( + [for (pair = map) let (iter_key = pair[0], iter_value = pair[1]) if (key == iter_key) diff --git a/test.scad b/test.scad index 21960c1..f331ef9 100644 --- a/test.scad +++ b/test.scad @@ -2,4 +2,4 @@ use ; fDrawX(fCylinder(10, r1=5, r2=2)) fDrawX(fSphere(10)) -fDrawX(fCube(10)); +fDrawX(fCube(10)); \ No newline at end of file