[docs] Improved CPML doc
[adg.git] / cpml / cpml-close.c
blobdedeb28ac0a2dd9e98c4f638290938db82b8b0bd
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.
20 /**
21 * SECTION:close
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.
32 **/
34 #include "cpml-close.h"
35 #include "cpml-pair.h"
37 /**
38 * cpml_close_get_npoints:
40 * Returns the number of points needed to properly specify a close primitive.
42 * Return value: 1
43 **/
44 int
45 cpml_close_get_npoints(void)
47 return 1;
50 /**
51 * cpml_close_pair_at:
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.
62 **/
63 void
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;
75 /**
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
83 * @pos is not used.
84 **/
85 void
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;
97 /**
98 * cpml_close_offset:
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.
109 void
110 cpml_close_offset(CpmlPrimitive *close, double offset)
112 cairo_path_data_t *p1, *p2;
113 CpmlVector normal;
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;