1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19 
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 
25 module graphene.Point;
26 
27 private import glib.ConstructionException;
28 private import glib.MemorySlice;
29 private import gobject.ObjectG;
30 private import graphene.Vec2;
31 private import graphene.c.functions;
32 public  import graphene.c.types;
33 private import gtkd.Loader;
34 
35 
36 /**
37  * A point with two coordinates.
38  *
39  * Since: 1.0
40  */
41 public final class Point
42 {
43 	/** the main Gtk struct */
44 	protected graphene_point_t* graphene_point;
45 	protected bool ownedRef;
46 
47 	/** Get the main Gtk struct */
48 	public graphene_point_t* getPointStruct(bool transferOwnership = false)
49 	{
50 		if (transferOwnership)
51 			ownedRef = false;
52 		return graphene_point;
53 	}
54 
55 	/** the main Gtk struct as a void* */
56 	protected void* getStruct()
57 	{
58 		return cast(void*)graphene_point;
59 	}
60 
61 	/**
62 	 * Sets our main struct and passes it to the parent class.
63 	 */
64 	public this (graphene_point_t* graphene_point, bool ownedRef = false)
65 	{
66 		this.graphene_point = graphene_point;
67 		this.ownedRef = ownedRef;
68 	}
69 
70 	~this ()
71 	{
72 		if ( Linker.isLoaded(LIBRARY_GRAPHENE) && ownedRef )
73 			graphene_point_free(graphene_point);
74 	}
75 
76 
77 	/**
78 	 * the X coordinate of the point
79 	 */
80 	public @property float x()
81 	{
82 		return graphene_point.x;
83 	}
84 
85 	/** Ditto */
86 	public @property void x(float value)
87 	{
88 		graphene_point.x = value;
89 	}
90 
91 	/**
92 	 * the Y coordinate of the point
93 	 */
94 	public @property float y()
95 	{
96 		return graphene_point.y;
97 	}
98 
99 	/** Ditto */
100 	public @property void y(float value)
101 	{
102 		graphene_point.y = value;
103 	}
104 
105 	/** */
106 	public static GType getType()
107 	{
108 		return graphene_point_get_type();
109 	}
110 
111 	/**
112 	 * Allocates a new #graphene_point_t structure.
113 	 *
114 	 * The coordinates of the returned point are (0, 0).
115 	 *
116 	 * It's possible to chain this function with graphene_point_init()
117 	 * or graphene_point_init_from_point(), e.g.:
118 	 *
119 	 * |[<!-- language="C" -->
120 	 * graphene_point_t *
121 	 * point_new (float x, float y)
122 	 * {
123 	 * return graphene_point_init (graphene_point_alloc (), x, y);
124 	 * }
125 	 *
126 	 * graphene_point_t *
127 	 * point_copy (const graphene_point_t *p)
128 	 * {
129 	 * return graphene_point_init_from_point (graphene_point_alloc (), p);
130 	 * }
131 	 * ]|
132 	 *
133 	 * Returns: the newly allocated #graphene_point_t.
134 	 *     Use graphene_point_free() to free the resources allocated by
135 	 *     this function.
136 	 *
137 	 * Since: 1.0
138 	 *
139 	 * Throws: ConstructionException GTK+ fails to create the object.
140 	 */
141 	public this()
142 	{
143 		auto __p = graphene_point_alloc();
144 
145 		if(__p is null)
146 		{
147 			throw new ConstructionException("null returned by alloc");
148 		}
149 
150 		this(cast(graphene_point_t*) __p);
151 	}
152 
153 	/**
154 	 * Computes the distance between @a and @b.
155 	 *
156 	 * Params:
157 	 *     b = a #graphene_point_t
158 	 *     dX = distance component on the X axis
159 	 *     dY = distance component on the Y axis
160 	 *
161 	 * Returns: the distance between the two points
162 	 *
163 	 * Since: 1.0
164 	 */
165 	public float distance(Point b, out float dX, out float dY)
166 	{
167 		return graphene_point_distance(graphene_point, (b is null) ? null : b.getPointStruct(), &dX, &dY);
168 	}
169 
170 	/**
171 	 * Checks if the two points @a and @b point to the same
172 	 * coordinates.
173 	 *
174 	 * This function accounts for floating point fluctuations; if
175 	 * you want to control the fuzziness of the match, you can use
176 	 * graphene_point_near() instead.
177 	 *
178 	 * Params:
179 	 *     b = a #graphene_point_t
180 	 *
181 	 * Returns: `true` if the points have the same coordinates
182 	 *
183 	 * Since: 1.0
184 	 */
185 	public bool equal(Point b)
186 	{
187 		return graphene_point_equal(graphene_point, (b is null) ? null : b.getPointStruct()) != 0;
188 	}
189 
190 	/**
191 	 * Frees the resources allocated by graphene_point_alloc().
192 	 *
193 	 * Since: 1.0
194 	 */
195 	public void free()
196 	{
197 		graphene_point_free(graphene_point);
198 		ownedRef = false;
199 	}
200 
201 	/**
202 	 * Initializes @p to the given @x and @y coordinates.
203 	 *
204 	 * It's safe to call this function multiple times.
205 	 *
206 	 * Params:
207 	 *     x = the X coordinate
208 	 *     y = the Y coordinate
209 	 *
210 	 * Returns: the initialized point
211 	 *
212 	 * Since: 1.0
213 	 */
214 	public Point init(float x, float y)
215 	{
216 		auto __p = graphene_point_init(graphene_point, x, y);
217 
218 		if(__p is null)
219 		{
220 			return null;
221 		}
222 
223 		return ObjectG.getDObject!(Point)(cast(graphene_point_t*) __p);
224 	}
225 
226 	/**
227 	 * Initializes @p with the same coordinates of @src.
228 	 *
229 	 * Params:
230 	 *     src = the #graphene_point_t to use
231 	 *
232 	 * Returns: the initialized point
233 	 *
234 	 * Since: 1.0
235 	 */
236 	public Point initFromPoint(Point src)
237 	{
238 		auto __p = graphene_point_init_from_point(graphene_point, (src is null) ? null : src.getPointStruct());
239 
240 		if(__p is null)
241 		{
242 			return null;
243 		}
244 
245 		return ObjectG.getDObject!(Point)(cast(graphene_point_t*) __p);
246 	}
247 
248 	/**
249 	 * Initializes @p with the coordinates inside the given #graphene_vec2_t.
250 	 *
251 	 * Params:
252 	 *     src = a #graphene_vec2_t
253 	 *
254 	 * Returns: the initialized point
255 	 *
256 	 * Since: 1.4
257 	 */
258 	public Point initFromVec2(Vec2 src)
259 	{
260 		auto __p = graphene_point_init_from_vec2(graphene_point, (src is null) ? null : src.getVec2Struct());
261 
262 		if(__p is null)
263 		{
264 			return null;
265 		}
266 
267 		return ObjectG.getDObject!(Point)(cast(graphene_point_t*) __p);
268 	}
269 
270 	/**
271 	 * Linearly interpolates the coordinates of @a and @b using the
272 	 * given @factor.
273 	 *
274 	 * Params:
275 	 *     b = a #graphene_point_t
276 	 *     factor = the linear interpolation factor
277 	 *     res = return location for the interpolated
278 	 *         point
279 	 *
280 	 * Since: 1.0
281 	 */
282 	public void interpolate(Point b, double factor, out Point res)
283 	{
284 		graphene_point_t* outres = sliceNew!graphene_point_t();
285 
286 		graphene_point_interpolate(graphene_point, (b is null) ? null : b.getPointStruct(), factor, outres);
287 
288 		res = ObjectG.getDObject!(Point)(outres, true);
289 	}
290 
291 	/**
292 	 * Checks whether the two points @a and @b are within
293 	 * the threshold of @epsilon.
294 	 *
295 	 * Params:
296 	 *     b = a #graphene_point_t
297 	 *     epsilon = threshold between the two points
298 	 *
299 	 * Returns: `true` if the distance is within @epsilon
300 	 *
301 	 * Since: 1.0
302 	 */
303 	public bool near(Point b, float epsilon)
304 	{
305 		return graphene_point_near(graphene_point, (b is null) ? null : b.getPointStruct(), epsilon) != 0;
306 	}
307 
308 	/**
309 	 * Stores the coordinates of the given #graphene_point_t into a
310 	 * #graphene_vec2_t.
311 	 *
312 	 * Params:
313 	 *     v = return location for the vertex
314 	 *
315 	 * Since: 1.4
316 	 */
317 	public void toVec2(out Vec2 v)
318 	{
319 		graphene_vec2_t* outv = sliceNew!graphene_vec2_t();
320 
321 		graphene_point_to_vec2(graphene_point, outv);
322 
323 		v = ObjectG.getDObject!(Vec2)(outv, true);
324 	}
325 
326 	/**
327 	 * Returns a point fixed at (0, 0).
328 	 *
329 	 * Returns: a fixed point
330 	 *
331 	 * Since: 1.0
332 	 */
333 	public static Point zero()
334 	{
335 		auto __p = graphene_point_zero();
336 
337 		if(__p is null)
338 		{
339 			return null;
340 		}
341 
342 		return ObjectG.getDObject!(Point)(cast(graphene_point_t*) __p);
343 	}
344 }