![]() |
![]() |
![]() |
CPML reference manual |
![]() |
---|---|---|---|---|
Top | Description |
struct CpmlPair; typedef CpmlVector;void cpml_pair_copy (CpmlPair *pair
,const CpmlPair *src
);double cpml_pair_distance (const CpmlPair *from
,const CpmlPair *to
);int cpml_pair_equal (const CpmlPair *pair
,const CpmlPair *src
);void cpml_pair_from_cairo (CpmlPair *pair
,const
);cairo_path_data_t *path_datadouble cpml_pair_squared_distance (const CpmlPair *from
,const CpmlPair *to
);void cpml_pair_to_cairo (const CpmlPair *pair
,);
cairo_path_data_t *path_datavoid cpml_pair_transform (CpmlPair *pair
,const
);cairo_matrix_t *matrixdouble cpml_vector_angle (const CpmlVector *vector
);void cpml_vector_from_angle (CpmlVector *vector
,);
double anglevoid cpml_vector_normal (CpmlVector *vector
);void cpml_vector_set_length (CpmlVector *vector
,);
double lengthvoid cpml_vector_transform (CpmlVector *vector
,const
);cairo_matrix_t *matrix
The CpmlPair is a generic 2D structure. It can be used to represent coordinates, sizes, offsets or whatever have two components.
The name comes from MetaFont.
typedef struct _CpmlPair CpmlVector;
Another name for CpmlPair. It is used to clarify when a function expects a generic pair (usually coordinates) or a vector.
A vector represents a line starting from the origin (0,0) and ending to the given coordinates pair. Vectors are useful to define direction and length at once. Keep in mind the cairo default coordinates system is not problably what you expect: the x axis increases at right (as usual) but the y axis increases at down (the reverse of a usual cartesian plan). An angle of 0 is at V=(1; 0) (middle right).
Since 1.0
void cpml_pair_copy (CpmlPair *pair
,const CpmlPair *src
);
Copies src
in pair
.
Since 1.0
double cpml_pair_distance (const CpmlPair *from
,const CpmlPair *to
);
Gets the distance between from
and to
. If you need this value only
for comparation purpose, you could use cpm_pair_squared_distance()
from
or to
could be NULL
The algorithm used is adapted from: "Replacing Square Roots by Pythagorean Sums" by Clave Moler and Donald Morrison (1983) IBM Journal of Research and Development 27 (6): 577–581 http://www.research.ibm.com/journal/rd/276/ibmrd2706P.pdf
Since 1.0
int cpml_pair_equal (const CpmlPair *pair
,const CpmlPair *src
);
Compares pair
to src
and returns 1 if the pairs are equals.
Two NULL
|
the first pair to compare |
|
the second pair to compare |
Returns : |
1 pair is equal to src ,
0 |
Since 1.0
void cpml_pair_from_cairo (CpmlPair *pair
,const
);cairo_path_data_t *path_data
Sets pair
from a path_data
should contains
a point data: it is up to the caller to be sure path_data
is valid.
|
the destination CpmlPair. [out] |
|
the original path data point. [in][type gpointer] |
Since 1.0
double cpml_pair_squared_distance (const CpmlPair *from
,const CpmlPair *to
);
Gets the squared distance between from
and to
. This value is useful
for comparation purpose: if you need to get the real distance, use
cpml_pair_distance()
.
from
or to
could be NULL
Since 1.0
void cpml_pair_to_cairo (const CpmlPair *pair
,);
cairo_path_data_t *path_data
Sets a pair
. This is exactly the reverse
operation of cpml_pair_from_cairo()
.
Since 1.0
void cpml_pair_transform (CpmlPair *pair
,const
);cairo_matrix_t *matrix
Shortcut to apply a specific transformation matrix to pair
.
Since 1.0
double cpml_vector_angle (const CpmlVector *vector
);
Gets the angle of vector
, in radians. If vector
is (0, 0),
0 is returned.
|
the source CpmlVector |
Returns : |
the angle in radians, a value between -M_PI and M_PI |
Since 1.0
void cpml_vector_from_angle (CpmlVector *vector
,);
double angle
Calculates the coordinates of the point far 1
angle
direction. The result is stored in vector
.
|
the destination CpmlVector. [out] |
|
angle of direction, in radians. [in] |
Since 1.0
void cpml_vector_normal (CpmlVector *vector
);
Stores in vector
a vector normal to the original vector
.
The length is retained.
The algorithm is really quick because no trigonometry is involved.
|
the subject CpmlVector. [inout] |
Since 1.0
void cpml_vector_set_length (CpmlVector *vector
,);
double length
Imposes the specified length
to vector
. If the old length is 0
length
is 0
vector
is set to (0, 0).
The length
parameter can be negative, in which case the vector
is inverted.
|
a CpmlVector. [inout] |
|
the new length. [in] |
Since 1.0
void cpml_vector_transform (CpmlVector *vector
,const
);cairo_matrix_t *matrix
Shortcut to apply a specific transformation matrix to vector
.
It works in a similar way of cpml_pair_transform()
but uses
cairo_matrix_transform_distance()
cairo_matrix_transform_point()
Since 1.0