1 /* CPML - Cairo Path Manipulation Library
2 * Copyright (C) 2008, 2009 Nicola Fontana <ntd at entidi.it>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
22 * @title: Closing path lines
23 * @short_description: APIs to manage closing path virtual primitives
25 * The following functions manipulate %CAIRO_PATH_CLOSE_PATH
26 * #CpmlPrimitive. No check is made on the primitive struct, so be
27 * sure the <structname>CpmlPrimitive</structname> is effectively
28 * a close operation before calling these APIs.
30 * This primitive management is almost identical to straight lines,
31 * but taking properly start and end points.
34 #include "cpml-close.h"
35 #include "cpml-pair.h"
38 * cpml_close_get_npoints:
40 * Returns the number of points needed to properly specify a close primitive.
45 cpml_close_get_npoints(void)
52 * @close: the #CpmlPrimitive close data
53 * @pair: the destination pair
54 * @pos: the position value
56 * Given the @close path virtual primitive, finds the coordinates
57 * at position @pos (where 0 is the start and 1 is the end) and
58 * stores the result in @pair.
60 * @pos can be less than 0 or greater than 1, in which case the
61 * coordinates are interpolated.
64 cpml_close_pair_at(CpmlPrimitive
*close
, CpmlPair
*pair
, double pos
)
66 cairo_path_data_t
*p1
, *p2
;
68 p1
= cpml_primitive_get_point(close
, 0);
69 p2
= cpml_primitive_get_point(close
, -1);
71 pair
->x
= p1
->point
.x
+ (p1
->point
.x
- p1
->point
.x
) * pos
;
72 pair
->y
= p1
->point
.y
+ (p2
->point
.y
- p1
->point
.y
) * pos
;
76 * cpml_close_vector_at:
77 * @close: the #CpmlPrimitive close data
78 * @vector: the destination vector
79 * @pos: the position value
81 * Gets the slope on @close at the position @pos. Being the
82 * close a straight line, the vector is always the same, so
86 cpml_close_vector_at(CpmlPrimitive
*close
, CpmlVector
*vector
, double pos
)
88 cairo_path_data_t
*p1
, *p2
;
90 p1
= cpml_primitive_get_point(close
, 0);
91 p2
= cpml_primitive_get_point(close
, -1);
93 vector
->x
= p2
->point
.x
- p1
->point
.x
;
94 vector
->y
= p2
->point
.y
- p1
->point
.y
;
99 * @close: the #CpmlPrimitive close data
100 * @offset: distance for the computed parallel close
102 * Given a close segment specified by the @close primitive data,
103 * computes the parallel close distant @offset from the original one
104 * and returns the result by changing @close.
106 * The algorithm is practically the same as the one used for
107 * cpml_line_offset() but using the proper start and end coordinates.
110 cpml_close_offset(CpmlPrimitive
*close
, double offset
)
112 cairo_path_data_t
*p1
, *p2
;
115 p1
= cpml_primitive_get_point(close
, 0);
116 p2
= cpml_primitive_get_point(close
, -1);
118 cpml_close_vector_at(close
, &normal
, 0.);
119 cpml_vector_normal(&normal
);
120 cpml_vector_set_length(&normal
, offset
);
122 p1
->point
.x
+= normal
.x
;
123 p1
->point
.y
+= normal
.y
;
124 p2
->point
.x
+= normal
.x
;
125 p2
->point
.y
+= normal
.y
;