1.15 <GrapheneVec2>

Structure: <GrapheneVec2>

A structure capable of holding a vector with two dimensions, x and y.

The contents of the <GrapheneVec2> structure are private and should never be accessed directly.

Procedures

Method: vec2:add! self b res ⇒ res
Method: add! self b res ⇒ res

Adds each component of the two passed vectors and places each result into the components of res.

self

Passed: a <GrapheneVec2>.

a <GrapheneVec2>

b

Passed: a <GrapheneVec2>.

a <GrapheneVec2>

res

Passed, filled in, and returned: a <GrapheneVec2>.

return location for the result

Procedure: vec2:alloc ⇒ %return

Allocates a new <GrapheneVec2> structure.

The contents of the returned structure are undefined.

Use vec2:init to initialize the vector.

%return

Returned: a <GrapheneVec2>.

the newly allocated <GrapheneVec2> structure. Use vec2:free to free the resources allocated by this function.

Method: vec2:divide! self b res ⇒ res
Method: divide! self b res ⇒ res

Divides each component of the first operand self by the corresponding component of the second operand b, and places the results into the vector res.

self

Passed: a <GrapheneVec2>.

a <GrapheneVec2>

b

Passed: a <GrapheneVec2>.

a <GrapheneVec2>

res

Passed, filled in, and returned: a <GrapheneVec2>.

return location for the result

Method: vec2:dot self b ⇒ %return
Method: dot self b ⇒ %return

Computes the dot product of the two given vectors.

self

Passed: a <GrapheneVec2>.

a <GrapheneVec2>

b

Passed: a <GrapheneVec2>.

a <GrapheneVec2>

%return

Returned: a real number.

the dot product of the vectors

Method: vec2:equal? self v2 ⇒ %return
Method: equal? self v2 ⇒ %return

Checks whether the two given <GrapheneVec2> are equal.

self

Passed: a <GrapheneVec2>.

a <GrapheneVec2>

v2

Passed: a <GrapheneVec2>.

a <GrapheneVec2>

%return

Returned: a boolean.

true if the two vectors are equal, and false otherwise

Method: vec2:free self
Method: free self

Frees the resources allocated by self

self

Passed: a <GrapheneVec2>.

a <GrapheneVec2>

Method: vec2:get-x self ⇒ %return
Method: get-x self ⇒ %return

Retrieves the X component of the <GrapheneVec2>.

self

Passed: a <GrapheneVec2>.

a <GrapheneVec2>

%return

Returned: a real number.

the value of the X component

Method: vec2:get-y self ⇒ %return
Method: get-y self ⇒ %return

Retrieves the Y component of the <GrapheneVec2>.

self

Passed: a <GrapheneVec2>.

a <GrapheneVec2>

%return

Returned: a real number.

the value of the Y component

Method: vec2:init self x y ⇒ %return
Method: init self x y ⇒ %return

Initializes a <GrapheneVec2> using the given values.

This function can be called multiple times.

self

Passed: a <GrapheneVec2>.

a <GrapheneVec2>

x

Passed: a real number.

the X field of the vector

y

Passed: a real number.

the Y field of the vector

%return

Returned: a <GrapheneVec2>.

the initialized vector

Method: vec2:init-from-float self src ⇒ %return
Method: init-from-float self src ⇒ %return

Initializes self with the contents of the given array.

self

Passed: a <GrapheneVec2>.

a <GrapheneVec2>

src

Passed: a f32vector, or a list or vector, each a real number.

an array of floating point values with at least two elements

%return

Returned: a <GrapheneVec2>.

the initialized vector

Method: vec2:init-from-vec2 self src ⇒ %return
Method: init-from-vec2 self src ⇒ %return

Copies the contents of src into self.

self

Passed: a <GrapheneVec2>.

a <GrapheneVec2>

src

Passed: a <GrapheneVec2>.

a <GrapheneVec2>

%return

Returned: a <GrapheneVec2>.

the initialized vector

Method: vec2:interpolate! self v2 factor res ⇒ res
Method: interpolate! self v2 factor res ⇒ res

Linearly interpolates self and v2 using the given factor.

self

Passed: a <GrapheneVec2>.

a <GrapheneVec2>

v2

Passed: a <GrapheneVec2>.

a <GrapheneVec2>

factor

Passed: a real number.

the interpolation factor

res

Passed, filled in, and returned: a <GrapheneVec2>.

the interpolated vector

Method: vec2:length self ⇒ %return
Method: length self ⇒ %return

Computes the length of the given vector.

self

Passed: a <GrapheneVec2>.

a <GrapheneVec2>

%return

Returned: a real number.

the length of the vector

Method: vec2:max! self b res ⇒ res
Method: max! self b res ⇒ res

Compares the two given vectors and places the maximum values of each component into res.

self

Passed: a <GrapheneVec2>.

a <GrapheneVec2>

b

Passed: a <GrapheneVec2>.

a <GrapheneVec2>

res

Passed, filled in, and returned: a <GrapheneVec2>.

the resulting vector

Method: vec2:min! self b res ⇒ res
Method: min! self b res ⇒ res

Compares the two given vectors and places the minimum values of each component into res.

self

Passed: a <GrapheneVec2>.

a <GrapheneVec2>

b

Passed: a <GrapheneVec2>.

a <GrapheneVec2>

res

Passed, filled in, and returned: a <GrapheneVec2>.

the resulting vector

Method: vec2:multiply! self b res ⇒ res
Method: multiply! self b res ⇒ res

Multiplies each component of the two passed vectors and places each result into the components of res.

self

Passed: a <GrapheneVec2>.

a <GrapheneVec2>

b

Passed: a <GrapheneVec2>.

a <GrapheneVec2>

res

Passed, filled in, and returned: a <GrapheneVec2>.

return location for the result

Method: vec2:near? self v2 epsilon ⇒ %return
Method: near? self v2 epsilon ⇒ %return

Compares the two given <GrapheneVec2> vectors and checks whether their values are within the given epsilon.

self

Passed: a <GrapheneVec2>.

a <GrapheneVec2>

v2

Passed: a <GrapheneVec2>.

a <GrapheneVec2>

epsilon

Passed: a real number.

the threshold between the two vectors

%return

Returned: a boolean.

true if the two vectors are near each other

Method: vec2:negate! self res ⇒ res
Method: negate! self res ⇒ res

Negates the given <GrapheneVec2>.

self

Passed: a <GrapheneVec2>.

a <GrapheneVec2>

res

Passed, filled in, and returned: a <GrapheneVec2>.

return location for the result vector

Method: vec2:normalize! self res ⇒ res
Method: normalize! self res ⇒ res

Computes the normalized vector for the given vector self.

self

Passed: a <GrapheneVec2>.

a <GrapheneVec2>

res

Passed, filled in, and returned: a <GrapheneVec2>.

return location for the normalized vector

Procedure: vec2:one ⇒ %return

Retrieves a constant vector with (1, 1) components.

%return

Returned: a <GrapheneVec2>.

the one vector

Method: vec2:scale! self factor res ⇒ res
Method: scale! self factor res ⇒ res

Multiplies all components of the given vector with the given scalar factor.

self

Passed: a <GrapheneVec2>.

a <GrapheneVec2>

factor

Passed: a real number.

the scalar factor

res

Passed, filled in, and returned: a <GrapheneVec2>.

return location for the result vector

Method: vec2:subtract! self b res ⇒ res
Method: subtract! self b res ⇒ res

Subtracts from each component of the first operand self the corresponding component of the second operand b and places each result into the components of res.

self

Passed: a <GrapheneVec2>.

a <GrapheneVec2>

b

Passed: a <GrapheneVec2>.

a <GrapheneVec2>

res

Passed, filled in, and returned: a <GrapheneVec2>.

return location for the result

Method: vec2:to-float! self dest ⇒ dest
Method: to-float! self dest ⇒ dest

Stores the components of self into an array.

self

Passed: a <GrapheneVec2>.

a <GrapheneVec2>

dest

Passed: a f32vector, or a list or vector, each a real number. It is filled in, and returned: a f32vector.

return location for an array of floating point values with at least 2 elements

Procedure: vec2:x-axis ⇒ %return

Retrieves a constant vector with (1, 0) components.

%return

Returned: a <GrapheneVec2>.

the X axis vector

Procedure: vec2:y-axis ⇒ %return

Retrieves a constant vector with (0, 1) components.

%return

Returned: a <GrapheneVec2>.

the Y axis vector

Procedure: vec2:zero ⇒ %return

Retrieves a constant vector with (0, 0) components.

%return

Returned: a <GrapheneVec2>.

the zero vector