Package: graphene

Macro graphene:with-point

Lambda List

graphene:with-point ((var &rest args) &body body)

Syntax

(graphene:with-point (p) body) => result
(graphene:with-point (p p1) body) => result
(graphene:with-point (p (v graphene:vec2-t)) body) => result
(graphene:with-point (p x y) body) => result

Arguments

p -- a graphene:point-t instance to create and initialize
p1 -- a graphene:point-t instance to use for initialization
v -- a graphene:vec2-t instance to use for initialization
x -- a number coerced to a float for the x component of the point
y -- a number coerced to a float for the y component of the point

Details

The graphene:with-point macro allocates a new graphene:point-t instance, initializes the point with the given values and executes the body that uses the point. After execution of the body the allocated memory for the point is released.

When no argument is given the components of the point are initialized to zero. The initialization with two single floats uses the graphene:point-init function. The initialization from another point is done with the graphene:point-init-from-point function. That is the default when no type specifier for the value is given. If the value has the type specifier graphene:vec2-t the point is initialized with the graphene:point-init-from-vec2 function.

Note

The memory is allocated with the graphene:point-alloc function and released with the graphene:point-free function.

Examples

Initialize a point with no value and two single floats.
(graphene:with-point (p)
  (list (graphene:point-x p) (graphene:point-y p)))
=> (0.0 0.0)
(graphene:with-point (p 1.5 1.7)
  (list (graphene:point-x p) (graphene:point-y p)))
=> (1.5 1.7)    
Use a vector for initialization of the point.
(graphene:with-vec2 (v 3.5 4.5)
  (graphene:with-point (p (v graphene:vec2-t))
    (list (graphene:point-x p) (graphene:point-y p))))
=> (3.5 4.5)    
 

See also

2024-1-20