Initial coords for Cube

This commit is contained in:
Ian Gulliver
2016-12-25 12:57:32 -08:00
parent f667b1385d
commit 9f68fb41dc
3 changed files with 34 additions and 2 deletions

View File

@@ -1,7 +1,9 @@
// Short for "coordinate system", including translation, rotation, and scale
// coord:
// fKeyType "type" fType(): fTypeCoord "coord"
// fKeyTranslation "translation" fCoordTranslation():
// fKeyTranslation "translation" fCoordTranslation(): [ x, y, z ]
// fKeyRotation "rotation" fCoordRotation(): [ x, y, z ]
// fKeyScale "scale" fCoordScale(): [ x, y, z ]
fTypeCoord = "coord";

View File

@@ -11,6 +11,10 @@ function fCube(dims) = (
[4, 5, 7, 6], // +x
[2, 6, 7, 3], // +y
[1, 3, 7, 5], // +z
],
coords=[
[ "/x+,/y+,-z+", fCoord(translation=[x / 2, y / 2, 0]) ],
[ "/x+,/y+,+z+", fCoord(translation=[x / 2, y / 2, z]) ],
]
)
);

View File

@@ -2,6 +2,14 @@
/// fKeyType "type" fType(): fTypeModel "model"
/// fKeyPoints "points" fModelPoints(): [ [x, y, z], ... ]
/// fKeyFaces "faces" fModelFaces(): [ [ pointIdx, ... ], ... ]
/// fKeyCoords "coords" fModelCoords(): [ [ name, coord ], ... ]
/// Standard model coords names:
///
/// [-/+] edge ("/" is midpoint)
/// [xyz] axis
/// [-+] direction
/// [-/+]x[-+],[-/+]y[-+],[-/+]z[-+]
fTypeModel = "model";
@@ -11,12 +19,14 @@ function fIsModel(x) = (
fKeyPoints = "points";
fKeyFaces = "faces";
fKeyCoords = "coords";
function fModel(points, faces) = (
function fModel(points, faces, coords=[]) = (
[
[fKeyType, fTypeModel],
[fKeyPoints, points],
[fKeyFaces, faces],
[fKeyCoords, coords],
]
);
@@ -27,3 +37,19 @@ function fModelPoints(model) = (
function fModelFaces(model) = (
fMapLookup(fKeyFaces, model)
);
fCoordAliases = [
[ "bottom", "/x+,/y+,-z+" ],
[ "top", "/x+,/y+,+z+" ],
[ "center", "/x+,/y+,/z+" ],
];
function fModelCoords(model) = (
fMapLookup(fKeyCoords, model)
);
function fModelCoord(model, name) = (
let(alias = fMapLookup(name, fCoordAliases),
realName = alias ? alias : name)
fMapLookup(realName, fModelCoords(model))
);