The global constants and variables described in this chapter are found in pspglb.web. Others, of types defined in 3DLDF, are described in subsequent chapters.
Set to 0 or 1 to match the values of the preprocessor macros
LDF_REAL_FLOAT
andLDF_REAL_DOUBLE
. The latter are used for conditional compilation and determine whetherreal
is “typedeffed” tofloat
ordouble
, i.e., whetherreal
is made to be a synonym offloat
ordouble
usingtypedef
.
ldf_real_float
andldf_real_double
can be used to control conditional expressions in non-conditionally compiled code.
The value of
PI
is calculated as 4.0 * arctan(1.0). I believe that a preprocessor macro “PI
” was available when I compiled 3DLDF using the DEC C++ compiler, and that it wasn't, when I used GNU CC under Linux, but I'm no longer sure.
Contains four elements, all 0. Used for resetting the sets of coordinates belonging to
Points
, but only when the DEC C++compiler is used. This doesn't work when GCC is used.
Actually,
INVALID_REAL
is the largest possiblereal
value (i.e.,float
ordouble
) on a given machine. So, from the point of view of the compiler, it's not invalid at all. However, 3DLDF uses it to indicate failure of some kind. For example, the return value of a function returningreal
can be compared withINVALID_REAL
to check whether the function succeeded or failed.An alternative approach would be to use the exception handling facilities of C++ . I do use these, but only in a couple of places, so far.
The largest
real
value permitted in the the elements ofTransforms
and the coordinates ofPoints
. It is the second largestreal
value (i.e.,float
ordouble
) on a given machine (INVALID_REAL
is the largest).
MAX_REAL
is a variable, but it should be used like a constant. In other words, users should never reset its value. It can't be declaredconst
because its value must be calculated using function calls, which can't be done before the entry point of the program, i.e.,main()
. Therefore, the value ofMAX_REAL
is calculated at the beginning ofmain()
.
The square root of
MAX_REAL
.
MAX_REAL_SQRT
is a variable, but it should be used like a constant. In other words, users should never reset its value. It can't be declaredconst
because its value is calculated using thesqrt()
function, which can't be done before the entry point of the program, i.e.,main()
. Therefore, the value ofMAX_REAL_SQRT
is set afterMAX_REAL
is calculated, at the beginning ofmain()
.
MAX_REAL_SQRT
is used inPoint::magnitude()
(see Vector Operations). The magnitude of aPoint
is found by using the formula \sqrtx^2 + y^2 + z^2. x, y, and z are all tested againstMAX_REAL_SQRT
to ensure that x^2, y^2, and z^2 will all be less than or equal toMAX_REAL
before trying to calculate them.Metafont implements an operation called Pythagorean addition, notated as “
++
”which can be used to calculate distances without first squaring and then taking square roots: 1 a++b == \sqrt(a^2 + b^2) and a++b++c == \sqrt(a^2 + b^2 + c^2). This makes it possible to calculate distances for greater values of a, b, and c, that would otherwise cause floating point errors. Metafont also implements the inverse operation Pythagorean subtraction, notated as “+-+
”: a+-+b == \sqrt(a^2 - b^2). Unfortunately, 3DLDF implements neither Pythagorean addition nor subtraction as yet, but it's on my list of “things to do”.