1 | 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! |
---|
2 | |
---|
3 | == vectr |
---|
4 | |
---|
5 | [[toc:]] |
---|
6 | |
---|
7 | === Author |
---|
8 | |
---|
9 | Andrew Mack |
---|
10 | |
---|
11 | === Requirements |
---|
12 | |
---|
13 | * coops |
---|
14 | |
---|
15 | === Description |
---|
16 | |
---|
17 | 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". |
---|
18 | |
---|
19 | 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. |
---|
20 | |
---|
21 | Currently only 2d vectrs are provided, but 3d vectrs will be provided in the near future. |
---|
22 | |
---|
23 | === API |
---|
24 | |
---|
25 | ==== Types |
---|
26 | |
---|
27 | <type><vectr></type> |
---|
28 | <procedure>(define-vectr tx <number> ty <number> hx <number> hy <number>) => <vectr></procedure> |
---|
29 | <procedure>(define-vectr tail <point> head <point>) => <vectr> </procedure> |
---|
30 | <procedure>(vectr? obj) => <bool> </procedure> |
---|
31 | 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. |
---|
32 | |
---|
33 | <type><point></type> |
---|
34 | <procedure>(point? obj)</procedure> |
---|
35 | 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.'' |
---|
36 | |
---|
37 | ==== Procedures |
---|
38 | |
---|
39 | <procedure>(get-head v <vectr>) => <point></procedure> |
---|
40 | <procedure>(set-head! v <vectr>)</procedure> |
---|
41 | <procedure>(get-tail v <vectr>) => <point></procedure> |
---|
42 | <procedure>(set-tail! v <vectr>)</procedure> |
---|
43 | Getters and setters for the head and tail of ''v''. |
---|
44 | |
---|
45 | <procedure>(vectr-add v1 <vectr> v2 <vectr>) => <vectr></procedure> |
---|
46 | 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 [[http://immersivemath.com/ila/ch02_vectors/ch02.html#fig_vec_vector_addition_triangle_rule|here]]. |
---|
47 | |
---|
48 | <procedure>(vectr-magnitude v <vectr>) => <number></procedure> |
---|
49 | <procedure>(vectr-length v <vectr>) => <number></procedure> |
---|
50 | Returns the magnitude of ''v''. For contexts where "length" has a clearer meaning than "magnitude", use {{vectr-length}} as it just calls {{vectr-magnitude}}. |
---|
51 | |
---|
52 | <procedure>(vectr-scalar v <vectr> s <number>) => <vectr></procedure> |
---|
53 | Returns a vectr equivalent to ''v'' scaled by ''s'', as shown [[http://immersivemath.com/ila/ch02_vectors/ch02.html#fig_vec_scaling|here]]. |
---|
54 | |
---|
55 | <procedure>(vectr-subtract v1 <vectr> v2 <vectr>) => <vectr></procedure> |
---|
56 | Returns a the result of {{(vectr-add (vectr-scalar v1 -1) v2)}}. |
---|
57 | |
---|
58 | <procedure>(pointing-up? v <vectr>) => <bool></procedure> |
---|
59 | <procedure>(pointing-down? v <vectr>) => <bool></procedure> |
---|
60 | <procedure>(pointing-left? v <vectr>) => <bool></procedure> |
---|
61 | <procedure>(pointing-right? v <vectr>) => <bool></procedure> |
---|
62 | <procedure>(horizontal? v <vectr>) => <bool></procedure> |
---|
63 | <procedure>(vertical? v <vectr>) => <bool></procedure> |
---|
64 | 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. |
---|
65 | |
---|
66 | ==== Repository |
---|
67 | The source can be found [[https://gitlab.com/v7x/vectr|here]]. Please feel free to share any issues or contribute, or even check my math :) |
---|
68 | |
---|
69 | ==== License |
---|
70 | [[https://www.gnu.org/licenses/gpl-3.0.txt]] |
---|
71 | |
---|
72 | ==== Version History |
---|
73 | * 0.1: Initial release. |
---|