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_type_get_npoints:
40 * Returns the number of points needed to properly specify a close primitive.
41 * This is a bit tricky: the close path primitive can be specified with
42 * a single point but it has an implicit second point, the start point
43 * of the source segment. This means retrieving a second point from a
44 * cairo path is a valid operation and must return the start point of
50 cpml_close_type_get_npoints(void)
57 * @close: the #CpmlPrimitive close data
58 * @pair: the destination pair
59 * @pos: the position value
61 * Given the @close path virtual primitive, finds the coordinates
62 * at position @pos (where 0 is the start and 1 is the end) and
63 * stores the result in @pair.
65 * @pos can be less than 0 or greater than 1, in which case the
66 * coordinates are interpolated.
69 cpml_close_pair_at(const CpmlPrimitive
*close
, CpmlPair
*pair
, double pos
)
71 cairo_path_data_t
*p1
, *p2
;
73 p1
= cpml_primitive_get_point(close
, 0);
74 p2
= cpml_primitive_get_point(close
, -1);
76 pair
->x
= p1
->point
.x
+ (p1
->point
.x
- p1
->point
.x
) * pos
;
77 pair
->y
= p1
->point
.y
+ (p2
->point
.y
- p1
->point
.y
) * pos
;
81 * cpml_close_vector_at:
82 * @close: the #CpmlPrimitive close data
83 * @vector: the destination vector
84 * @pos: the position value
86 * Gets the slope on @close at the position @pos. Being the
87 * close a straight line, the vector is always the same, so
91 cpml_close_vector_at(const CpmlPrimitive
*close
,
92 CpmlVector
*vector
, double pos
)
94 cairo_path_data_t
*p1
, *p2
;
96 p1
= cpml_primitive_get_point(close
, 0);
97 p2
= cpml_primitive_get_point(close
, -1);
99 vector
->x
= p2
->point
.x
- p1
->point
.x
;
100 vector
->y
= p2
->point
.y
- p1
->point
.y
;
105 * @close: the #CpmlPrimitive close data
106 * @offset: distance for the computed parallel close
108 * Given a close segment specified by the @close primitive data,
109 * computes the parallel close distant @offset from the original one
110 * and returns the result by changing @close.
112 * The algorithm is practically the same as the one used for
113 * cpml_line_offset() but using the proper start and end coordinates.
116 cpml_close_offset(CpmlPrimitive
*close
, double offset
)
118 cairo_path_data_t
*p1
, *p2
;
121 p1
= cpml_primitive_get_point(close
, 0);
122 p2
= cpml_primitive_get_point(close
, -1);
124 cpml_close_vector_at(close
, &normal
, 0.);
125 cpml_vector_normal(&normal
);
126 cpml_vector_set_length(&normal
, offset
);
128 p1
->point
.x
+= normal
.x
;
129 p1
->point
.y
+= normal
.y
;
130 p2
->point
.x
+= normal
.x
;
131 p2
->point
.y
+= normal
.y
;