Common Lisp Package: SB-CGA

Computer graphics algebra package for SBCL.

README:

FUNCTION

Public

%ADJUST-VEC (RESULT POINT DIRECTION DISTANCE)

Multiply VEC DIRECTION by single-float DISTANCE adding the result to VEC POINT. Store result in RESULT, and return it.

%COPY-VEC (RESULT VEC)

Copy contents of VEC into RESULT, return RESULT. Unsafe.

%HADAMARD-PRODUCT (RESULT A B)

Compute hadamard product (elementwise product) of VEC A and VEC B, store result in VEC RESULT. Return RESULT. Unsafe.

%NORMALIZE (RESULT A)

Normalize VEC A, store result into VEC RESULT. Return RESULT. Unsafe.

%TRANSFORM-DIRECTION (RESULT VEC MATRIX)

Apply transformation MATRIX to VEC, store result in RESULT. Return RESULT. Unsafe.

%TRANSFORM-POINT (RESULT VEC MATRIX)

Apply transformation MATRIX to VEC, store result in RESULT. Return RESULT. Unsafe.

%VEC* (RESULT A F)

Multiply VEC A with single-float F, store result in VEC RESULT. Return RESULT. Unsafe.

%VEC+ (RESULT A B)

Add VEC A and B, store result in VEC RESULT. Return RESULT. Unsafe

%VEC- (RESULT A B)

Substract VEC B from VEC A, store result in VEC RESULT. Return RESULT. Unsafe.

%VEC-LERP (RESULT A B F)

Linear interpolate VEC A and VEC B using single-float F as the interpolation factor, store result in VEC RESULT. Return RESULT. Unsafe.

%VEC-MAX (RESULT A B)

Elementwise maximum of VEC A and VEC B, store result in VEC RESULT.

%VEC-MIN (RESULT A B)

Elementwise minimum of VEC A and VEC B, store result in VEC RESULT.

%VEC/ (RESULT A F)

Divide VEC A by single-float F, store result in VEC RESULT. Return RESULT. Unsafe.

ADJUST-VEC (POINT DIRECTION DISTANCE)

Multiply VEC DIRECTION by single-float DISTANCE adding the result to VEC POINT. Return result as a freshly allocated VEC.

ALLOC-VEC

Allocate a zero-initialized VEC.

CBRT (FLOAT)

Cube root of FLOAT.

COPY-VEC (VEC)

Allocate a fresh copy of VEC.

CROSS-PRODUCT (A B)

Cross product of 3D vector A and 3D vector B, return result as a freshly allocated VEC.

CUBIC-ROOTS (A B C D)

Real-valued roots for Ax^2+Bx+C. Smallest real root is returned as primary value, and the others as the successive values. NaN indicates lack of a real-valued root.

CUBIC-ROOTS-ABOVE (LIMIT A B C D)

Real-valued roots greater than LIMIT for Ax^3+Bx^2+Cx+D. Smallest positive root is returned as primary value, and others in increasing order. LIMIT indicates lack of a real-valued root above LIMIT.

DOT-PRODUCT (A B)

Compute dot product VEC A and VEC B.

HADAMARD-PRODUCT (A B)

Compute hadamard product (elementwise product) of VEC A and VEC B, return result as a freshly allocated VEC.

IDENTITY-MATRIX

Construct an identity matrix.

INVERSE-MATRIX (MATRIX)

Inverse of MATRIX. Signals an error if there is no inverse.

MATRIX (M11 M12 M13 M14 M21 M22 M23 M24 M31 M32 M33 M34 M41 M42 M43 M44)

Construct MATRIX with the given elements (arguments are provided in row major order.)

MATRIX* (&REST MATRICES)

Multiply MATRICES. The result might not be freshly allocated if all, or all but one multiplicant is an identity matrix.

MATRIX-DETERMINANT (MATRIX)

Determinant of MATRIX.

MATRIX= (M1 M2)

Return true if MATRIX M1 is elementwise equal to MATRIX M1.

MATRIXP (OBJECT)

Return true of OBJECT is a matrix.

MATRIX~ (M1 M2 &OPTIONAL (EPSILON +DEFAULT-EPSILON+))

Return true if MATRIX M1 and MATRIX M2 are elementwise within EPSILON of each other. EPSILON defaults to +DEFAULT-EPSILON+

MREF (MATRIX ROW COLUMN)

Accessor for value in the specificed ROW and COLUMN in MATRIX.

NORMALIZE (A)

Normalize VEC A, return result as a freshly allocated VEC.

QUADRATIC-ROOTS (A B C)

Real-valued roots for Ax^2+Bx+C. Smallest real root is returned as primary value, and the other as the secondary. In case of a double root both the primary and secondary values are the same. NaN indicates lack of a real-valued root.

QUADRATIC-ROOTS-ABOVE (LIMIT A B C)

Real-valued roots greater than LIMIT for Ax^2+Bx+C. Smallest positive root is returned as primary value, and the other as secondary. LIMIT indicates lack of a real-valued root above LIMIT.

REORIENT (V1 V2)

Construct a transformation matrix to reorient V1 with V2.

ROTATE (VEC)

Construct a rotation matrix using first three elements of VEC as the rotation factors.

ROTATE* (X Y Z)

Construct a rotation matrix from rotation factors X, Y, Z.

ROTATE-AROUND (V RADIANS)

Construct a rotation matrix that rotates by RADIANS around VEC V. 4th element of V is ignored.

SCALE (VEC)

Construct a scaling matrix using first threee elements of VEC as the scaling factors.

SCALE* (X Y Z)

Construct a scaling matrix from scaling factors X, Y, and Z.

TRANSFORM-BOUNDS (V1 V2 MATRIX)

Transform the axis-aligned bounding box specified by its extreme corners V1 and V2 using MATRIX. Return new extreme corners (minimum and maximum coordinates) as freshly allocted VECs, as the primary and secondary value.

TRANSFORM-DIRECTION (VEC MATRIX)

Apply transformation MATRIX to VEC ignoring the translation component, return result as a freshly allocated VEC.

TRANSFORM-POINT (VEC MATRIX)

Apply transformation MATRIX to VEC, return result as a freshly allocated VEC.

TRANSLATE (VEC)

Construct a translation matrix using first three elements of VEC as the translation factors.

TRANSLATE* (X Y Z)

Construct a translation matrix from translation factors X, Y and Z.

TRANSPOSE-MATRIX (MATRIX)

Transpose of MATRIX.

VEC (X Y Z)

Allocate a 3d vector [X, Y, Z].

VEC* (A F)

Multiply VEC A with single-float F, return result as a freshly allocated VEC.

VEC+ (A B)

Add VEC A and VEC B, return result as a freshly allocated VEC.

VEC- (A B)

Substract VEC B from VEC A, return result as a freshly allocated VEC.

VEC-LENGTH (A)

Length of VEC A.

VEC-LERP (A B F)

Linear interpolate VEC A and VEC B using single-float F as the interpolation factor, return result as a freshly allocated VEC.

VEC-MAX (VEC &REST VECS)

Elementwise maximum of VEC and VECS, return result as a freshly allocated VEC.

VEC-MIN (VEC &REST VECS)

Elementwise minimum of VEC and VECS, return result as a freshly allocated VEC.

VEC/ (A F)

Divide VEC A by single-float F, return result as a freshly allocated VEC.

VEC= (A B)

Return true if VEC A and VEC B are elementwise identical.

VEC~ (A B &OPTIONAL (EPSILON +DEFAULT-EPSILON+))

Return true if VEC A and VEC B are elementwise within EPSILON of each other. EPSILON defaults to +DEFAULT-EPSILON+.

ZERO-MATRIX

Construct a zero matrix.

Undocumented

%CROSS-PRODUCT (RESULT A B)

SETFMREF (VALUE MATRIX ROW COLUMN)

SXHASH-VEC (VEC)

Private

SUBMATRIX-DETERMINANT (MATRIX)

Determinant of the upper left 3x3 submatrix of MATRIX.

SYMBOLICATE (&REST THINGS)

Concatenate together the names of some strings and symbols, producing a symbol in the current package.

~ (A B &OPTIONAL (EPSILON +DEFAULT-EPSILON+))

Return true if A and B are within EPSILON of each other. EPSILON defaults to +DEFAULT-EPSILON+.

Undocumented

%%ADJUST-VEC/1 (POINT DIRECTION DISTANCE)

%%ADJUST-VEC/2 (POINT DIRECTION DISTANCE)

%%COPY-VEC/1 (VEC)

%%HADAMARD-PRODUCT/1 (A B)

%%HADAMARD-PRODUCT/2 (A B)

%%NORMALIZE/1 (A)

%%NORMALIZED-VEC (RESULT X Y Z)

%%TRANSFORM-DIRECTION/1 (VEC MATRIX)

%%TRANSFORM-POINT/1 (VEC MATRIX)

%%VEC*/1 (A F)

%%VEC+/1 (A B)

%%VEC+/2 (A B)

%%VEC-/1 (A B)

%%VEC-/2 (A B)

%%VEC-LERP/1 (A B F)

%%VEC-LERP/2 (A B F)

%%VEC//1 (A F)

%CUBIC-ROOTS/NORMAL (A B C REPLACEMENT)

%DOT-PRODUCT (A B)

%NORMALIZED-CROSS-PRODUCT (RESULT A B)

%VEC-LENGTH (A)

%VEC= (A B)

CBRT/DOUBLE (DOUBLE)

CBRT/SINGLE (FLOAT)

DOUBLE-FLOAT-QUIET-NAN

FLOAT-NAN-P (X)

GENERIC-INVERSE-MATRIX (MATRIX)

IS-ZERO (X)

NOTE-OPTIMIZABLE-FUN (NAME NAME/1 &OPTIONAL NAME/2)

OPTIMIZE-VEC-ALLOCATION (FORM)

PPRINT-MATRIX (STREAM MATRIX)

SINGLE-FLOAT-QUIET-NAN

MACRO

Private

Undocumented

DEFINE-ALLOC-FUN (NAME LAMBDA-LIST &BODY BODY)

DEFINE-OPT-FUN (NAME LAMBDA-LIST DOC &KEY NO-COMPILER-MACRO)

DEFINE-OPT-FUN2 (NAME LAMBDA-LIST DOC)

DEFINE-VM-FUN (NAME LAMBDA-LIST &BODY GENERIC-BODY)

EA-FOR-DATA (VECTOR INDEX)

EA-FOR-SLICE (VECTOR &OPTIONAL (INDEX 0))

FILL-XMM (TARGET SOURCE &OPTIONAL (INDEX 0))

LOAD-SLICE (XMM VECTOR &OPTIONAL (INDEX 0))

STORE-SLICE (XMM VECTOR &OPTIONAL (INDEX 0))

VARIABLE

Private

Undocumented

*ALLOC-FUNS*

*OPTIMIZABLE-FUNS*

CONSTANT

Public

+DEFAULT-EPSILON+

Used as a liminal value to work around floating point inaccuracy.

+IDENTITY-MATRIX+

Constant identity matrix.

Private

+PI+

Single-float PI.

Undocumented

+EQN-EPS+