Point: Graphene Reference Manual

## Point Point — A point with 2 coordinates |

## Functions

#define | GRAPHENE_POINT_INIT()
graphene_point_t * | graphene_point_alloc ()
void | graphene_point_free ()
graphene_point_t * | graphene_point_init ()
graphene_point_t * | graphene_point_init_from_point ()
bool | graphene_point_equal ()
float | graphene_point_distance ()
bool | graphene_point_near ()
void | graphene_point_interpolate ()
const graphene_point_t * | graphene_point_zero ()

## Types and Values

#define | GRAPHENE_POINT_INIT_ZERO
| graphene_point_t

## Description

graphene_point_t is a data structure capable of describing a point with two coordinates:

- `graphene_point_t.x`

- `graphene_point_t.y`

## Functions

### GRAPHENE_POINT_INIT()

    #define GRAPHENE_POINT_INIT(x,y)        { x, y }

Initializes a graphene_point_t with the given coordinates when declaring it, e.g:

    1
    graphene_point_t p = GRAPHENE_POINT_INIT (10.f, 10.f);

#### Parameters

x | the X coordinate |
y | the Y coordinate |

Since: 1.0

### graphene_point_alloc ()

    graphene_point_t *
    graphene_point_alloc (void);

Allocates a new graphene_point_t structure.

The coordinates of the returned point are (0, 0).

It's possible to chain this function with `graphene_point_init()` or `graphene_point_init_from_point()`, e.g.:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    graphene_point_t *
    point_new (float x, float y)
    {
      return graphene_point_init (graphene_point_alloc (), x, y);
    }

    graphene_point_t *
    point_copy (const graphene_point_t *p)
    {
      return graphene_point_init_from_point (graphene_point_alloc (), p);
    }

[constructor]

#### Returns

the newly allocated graphene_point_t. Use `graphene_point_free()` to free the resources allocated by this function.

[transfer full]

Since: 1.0

### graphene_point_free ()

    void
    graphene_point_free (graphene_point_t *p);

Frees the resources allocated by `graphene_point_alloc()`.

#### Parameters

p | a graphene_point_t |

Since: 1.0

### graphene_point_init ()

    graphene_point_t *
    graphene_point_init (graphene_point_t *p,
                         float x,
                         float y);

Initializes `p` to the given `x` and `y` coordinates.

It's safe to call this function multiple times.

#### Parameters

p | a graphene_point_t |
x | the X coordinate |
y | the Y coordinate |

#### Returns

the initialized point.

[transfer none]

Since: 1.0

### graphene_point_init_from_point ()

    graphene_point_t *
    graphene_point_init_from_point (graphene_point_t *p,
                                    const graphene_point_t *src);

Initializes `p` with the same coordinates of `src` .

#### Parameters

p | a graphene_point_t |
src | the graphene_point_t to use |

#### Returns

the initialized point.

[transfer none]

Since: 1.0

### graphene_point_equal ()

    bool
    graphene_point_equal (const graphene_point_t *a,
                          const graphene_point_t *b);

Checks if the two points `a` and `b` point to the same coordinates.

This function accounts for floating point fluctuations; if you want to control the fuzziness of the match, you can use `graphene_point_near()` instead.

#### Parameters

a | a graphene_point_t |
b | a graphene_point_t |

#### Returns

`true` if the points have the same coordinates

Since: 1.0

### graphene_point_distance ()

    float
    graphene_point_distance (const graphene_point_t *a,
                             const graphene_point_t *b,
                             float *d_x,
                             float *d_y);

Computes the distance between `a` and `b` .

#### Parameters

a | a graphene_point_t |
b | a graphene_point_t |
d_x | distance component on the X axis. | [out][optional]
d_y | distance component on the Y axis. | [out][optional]

#### Returns

the distance between the two points

Since: 1.0

### graphene_point_near ()

    bool
    graphene_point_near (const graphene_point_t *a,
                         const graphene_point_t *b,
                         float epsilon);

Checks whether the two points `a` and `b` are within the threshold of `epsilon` .

#### Parameters

a | a graphene_point_t |
b | a graphene_point_t |
epsilon | threshold between the two points |

#### Returns

`true` if the distance is within `epsilon`

Since: 1.0

### graphene_point_interpolate ()

    void
    graphene_point_interpolate (const graphene_point_t *a,
                                const graphene_point_t *b,
                                double factor,
                                graphene_point_t *res);

Linearly interpolates the coordinates of `a` and `b` using the given `factor` .

#### Parameters

a | a graphene_point_t |
b | a graphene_point_t |
factor | the linear interpolation factor |
res | return location for the interpolated point. | [out caller-allocates]

Since: 1.0

### graphene_point_zero ()

    const graphene_point_t *
    graphene_point_zero (void);

Returns a point fixed at (0, 0).

#### Returns

a fixed point.

[transfer none]

Since: 1.0

## Types and Values

### GRAPHENE_POINT_INIT_ZERO

    #define GRAPHENE_POINT_INIT_ZERO        GRAPHENE_POINT_INIT (0.f, 0.f)

Initializes a graphene_point_t to (0, 0) when declaring it.

Since: 1.0

### graphene_point_t

    typedef struct {
      float x;
      float y;
    } graphene_point_t;

A point with two coordinates.

#### Members

float `x`; | the X coordinate of the point |
float `y`; | the Y coordinate of the point |

Since: 1.0