Add model to type system

This commit is contained in:
Ian Gulliver
2016-12-25 12:51:23 -07:00
parent f79cd76e98
commit b2c7a0508a
3 changed files with 15 additions and 3 deletions

View File

@@ -2,8 +2,8 @@ include <cube.scad>;
include <cylinder.scad>;
include <draw.scad>;
include <math.scad>;
include <model.scad>;
include <obj_util.scad>;
include <sphere.scad>;
include <struct.scad>;
include <translate.scad>;
include <types.scad>;

View File

@@ -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],
]

View File

@@ -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],