Note: this egg has not been put in the repo yet, I just wanted the docs done before I did that. If you come back and see this message gone, the egg is available to chicken-install!
vectr provides types and operations relevant to vectors. These vectors are of the linear-algebraic variety, not the container types found in Chicken's base module. This is the reason for the lack of "o" in the name. Throughout the rest of the documentation, they will be referred to by the name "vectr".
The module provides two data types: a vectr (obviously), and a point. The types are defined using coops define-primitive-class procedure, and most functions are defined using coops define-method procedure. This way each structure can be used as a primitive type if so desired.
Currently only 2d vectrs are provided, but 3d vectrs will be provided in the near future.
- define-vectr tx <number> ty <number> hx <number> hy <number>procedure
- define-vectr tail <point> head <point>procedure
- vectr? objprocedure
The main data type, vectr. Vectrs are records containing two slots, a head and a tail. The tail point is the vectr's origin and the head point is where the vectr stops. Vectrs can be created using the define-vectr procedure. This procedure can take arguments of either 4 numbers or 2 points. You may test whether or not an arbitrary piece of data is a vector by passing it to the vectr? procedure.
- point? objprocedure
The observant reader may notice there is no procedure for creating a point. This is because a point is just a pair whose car and cdr both evaluate to #t when passed to the number? predicate. All that is required to create a point is to cons two numbers together. Note: it is possible to use any type which returns #t for the number? predicate in a pair, however the author only plans to support integers, rationals, and real at this time. The option is left for the adventurous to use other numeric types at their own risk.
- get-head v <vectr>procedure
- set-head! v <vectr>procedure
- get-tail v <vectr>procedure
- set-tail! v <vectr>procedure
Getters and setters for the head and tail of v.
- vectr-add v1 <vectr> v2 <vectr>procedure
Returns the vector whose tail is the tail of v2 and whose head is the head of the vectr of the same length and angle as v1 and whose tail is the head of v2, as shown here.
- vectr-magnitude v <vectr>procedure
- vectr-length v <vectr>procedure
- vectr-scalar v <vectr> s <number>procedure
Returns a vectr equivalent to v scaled by s, as shown here.
- vectr-subtract v1 <vectr> v2 <vectr>procedure
Returns a the result of (vectr-add (vectr-scalar v1 -1) v2).
- pointing-up? v <vectr>procedure
- pointing-down? v <vectr>procedure
- pointing-left? v <vectr>procedure
- pointing-right? v <vectr>procedure
- horizontal? v <vectr>procedure
- vertical? v <vectr>procedure
Procedures returning booleans based on the "direction" of v as if it were to be drawn moving from its head to its tail on a standard Cartesian coordinate graph where positive x grows to the left and positive y grows up.
The source can be found here. Please feel free to share any issues or contribute, or even check my math :)
- 0.1: Initial release.