Point

Point — A point with 2 coordinates

Types and Values

Includes

#include <graphene.h>

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)      (graphene_point_t) { .x = (_x), .y = (_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

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_init_from_vec2 ()

graphene_point_t *
graphene_point_init_from_vec2 (graphene_point_t *p,
                               const graphene_vec2_t *src);

Initializes p with the coordinates inside the given graphene_vec2_t.

Parameters

p

the graphene_point_t to initialize

 

src

a graphene_vec2_t

 

Returns

the initialized point.

[transfer none]

Since: 1.4


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

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_to_vec2 ()

void
graphene_point_to_vec2 (const graphene_point_t *p,
                        graphene_vec2_t *v);

Stores the coordinates of the given graphene_point_t into a graphene_vec2_t.

Parameters

p

a graphene_point_t

 

v

return location for the vertex.

[out caller-allocates]

Since: 1.4


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