openscad/MCAD — pull request #22 by ahmedtd (2014-08-23 07:18:11+00:00)
Title: Add functions to express dimensioned quantities.

Previously, MCAD libraries that dealt with absolutely-sized
artifacts (for example, nuts_and_bolts.scad) either implicitly worked in
millimeters or used a set of multiplicative constants defined in
units.scad (and one constant in constants.scad).

This change introduces a set of scaled functions in units.scad that help
creating objects that are specified in mixed dimensions:

mm(q): millimeters
cm(q): centimeters
dm(q): decimeters
m(q): meters
inch(q): inches
mil(q): mils (0.001 inch)

These functions convert from the indicated quantity to OpenSCAD's
internal units. By default, they are set up so that

1 /*OpenSCAD unit*/ == mm(1),

but, this can be switched by setting the variable MCAD_BASE_UNIT before
including units.scad. MCAD_BASE_UNIT is a multiplicative scale factor
that determines the correspondence between MCAD millimeters and OpenSCAD
units. For example:

// a.scad
include
echo(cm(1)); // Outputs 10

// b.scad
include
MCAD_BASE_UNIT = MCAD_BASE_UNIT_MIL;
echo(cm(1)); // Outputs 1

Every place in MCAD that was previously using the scale constants from
units.scad and constants.scad has been converted to use the new scale
functions, including the definition of MCAD_EPSILON (now 0.01 mm).

The scale constants have been kept for backwards-compatibility, but are
now defined in terms of the scale functions.

A small suite of tests has been added in the test/ subdirectory of the
project root. The test suite can be invoked using `make test` from the
top project directory.

If you want to omit the tests or translate them into the python testing
framework, that's fine.