From b2c7a0508a6a9e263c67304da0b22887fbf32fde Mon Sep 17 00:00:00 2001 From: Ian Gulliver Date: Sun, 25 Dec 2016 12:51:23 -0700 Subject: [PATCH] Add model to type system --- fcad/fcad.scad | 2 +- fcad/{struct.scad => model.scad} | 12 ++++++++++-- fcad/types.scad | 4 ++++ 3 files changed, 15 insertions(+), 3 deletions(-) rename fcad/{struct.scad => model.scad} (50%) diff --git a/fcad/fcad.scad b/fcad/fcad.scad index 521f3f8..2098316 100644 --- a/fcad/fcad.scad +++ b/fcad/fcad.scad @@ -2,8 +2,8 @@ include ; include ; include ; include ; +include ; include ; include ; -include ; include ; include ; diff --git a/fcad/struct.scad b/fcad/model.scad similarity index 50% rename from fcad/struct.scad rename to fcad/model.scad index d13e0e1..cbe2b49 100644 --- a/fcad/struct.scad +++ b/fcad/model.scad @@ -1,12 +1,20 @@ /// model: -/// kKeyPoints "points" fPoints(): [ [x, y, z], ... ] -/// kKeyFaces "faces" fFaces(): [ [ pointIdx, ... ], ... ] +/// fKeyType "type" fType(): fTypeModel "model" +/// fKeyPoints "points" fPoints(): [ [x, y, z], ... ] +/// fKeyFaces "faces" fFaces(): [ [ pointIdx, ... ], ... ] + +fTypeModel = "model"; + +function fIsModel(x) = ( + fType(x) == fTypeModel +); fKeyPoints = "points"; fKeyFaces = "faces"; function fModel(points, faces) = ( [ + [fKeyType, fTypeModel], [fKeyPoints, points], [fKeyFaces, faces], ] diff --git a/fcad/types.scad b/fcad/types.scad index 18eed53..c3179b7 100644 --- a/fcad/types.scad +++ b/fcad/types.scad @@ -1,3 +1,5 @@ +fKeyType = "type"; + fTypeUndef = "undef"; fTypeInt = "int"; fTypeFloat = "float"; @@ -12,6 +14,7 @@ function fType(x) = ( : abs(x) + 1 > abs(x) ? fTypeFloat : str(x) == x ? fTypeString : str(x) == "false" || str(x) == "true" ? fTypeBoolean + : fMapLookup(fKeyType, x) ? fMapLookup(fKeyType, x) : (x[0] == x[0]) && len(x) != undef ? fTypeVector : fTypeUnknown ); @@ -40,6 +43,7 @@ function fIsVector(x) = ( fType(x) == fTypeVector ); +// Helpers function fMapLookup(key, model) = ( [for (pair = model) let (iter_key = pair[0],