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.Box;
26 
27 private import glib.ConstructionException;
28 private import glib.MemorySlice;
29 private import gobject.ObjectG;
30 private import graphene.Point3D;
31 private import graphene.Sphere;
32 private import graphene.Vec3;
33 private import graphene.c.functions;
34 public  import graphene.c.types;
35 private import gtkd.Loader;
36 
37 
38 /**
39  * A 3D box, described as the volume between a minimum and
40  * a maximum vertices.
41  *
42  * Since: 1.2
43  */
44 public class Box
45 {
46 	/** the main Gtk struct */
47 	protected graphene_box_t* graphene_box;
48 	protected bool ownedRef;
49 
50 	/** Get the main Gtk struct */
51 	public graphene_box_t* getBoxStruct(bool transferOwnership = false)
52 	{
53 		if (transferOwnership)
54 			ownedRef = false;
55 		return graphene_box;
56 	}
57 
58 	/** the main Gtk struct as a void* */
59 	protected void* getStruct()
60 	{
61 		return cast(void*)graphene_box;
62 	}
63 
64 	/**
65 	 * Sets our main struct and passes it to the parent class.
66 	 */
67 	public this (graphene_box_t* graphene_box, bool ownedRef = false)
68 	{
69 		this.graphene_box = graphene_box;
70 		this.ownedRef = ownedRef;
71 	}
72 
73 	~this ()
74 	{
75 		if ( Linker.isLoaded(LIBRARY_GRAPHENE) && ownedRef )
76 			graphene_box_free(graphene_box);
77 	}
78 
79 
80 	/** */
81 	public static GType getType()
82 	{
83 		return graphene_box_get_type();
84 	}
85 
86 	/**
87 	 * Allocates a new #graphene_box_t.
88 	 *
89 	 * The contents of the returned structure are undefined.
90 	 *
91 	 * Returns: the newly allocated #graphene_box_t structure.
92 	 *     Use graphene_box_free() to free the resources allocated by this function
93 	 *
94 	 * Since: 1.2
95 	 *
96 	 * Throws: ConstructionException GTK+ fails to create the object.
97 	 */
98 	public this()
99 	{
100 		auto __p = graphene_box_alloc();
101 
102 		if(__p is null)
103 		{
104 			throw new ConstructionException("null returned by alloc");
105 		}
106 
107 		this(cast(graphene_box_t*) __p);
108 	}
109 
110 	/**
111 	 * Checks whether the #graphene_box_t @a contains the given
112 	 * #graphene_box_t @b.
113 	 *
114 	 * Params:
115 	 *     b = a #graphene_box_t
116 	 *
117 	 * Returns: `true` if the box is contained in the given box
118 	 *
119 	 * Since: 1.2
120 	 */
121 	public bool containsBox(Box b)
122 	{
123 		return graphene_box_contains_box(graphene_box, (b is null) ? null : b.getBoxStruct()) != 0;
124 	}
125 
126 	/**
127 	 * Checks whether @box contains the given @point.
128 	 *
129 	 * Params:
130 	 *     point = the coordinates to check
131 	 *
132 	 * Returns: `true` if the point is contained in the given box
133 	 *
134 	 * Since: 1.2
135 	 */
136 	public bool containsPoint(Point3D point)
137 	{
138 		return graphene_box_contains_point(graphene_box, (point is null) ? null : point.getPoint3DStruct()) != 0;
139 	}
140 
141 	/**
142 	 * Checks whether the two given boxes are equal.
143 	 *
144 	 * Params:
145 	 *     b = a #graphene_box_t
146 	 *
147 	 * Returns: `true` if the boxes are equal
148 	 *
149 	 * Since: 1.2
150 	 */
151 	public bool equal(Box b)
152 	{
153 		return graphene_box_equal(graphene_box, (b is null) ? null : b.getBoxStruct()) != 0;
154 	}
155 
156 	/**
157 	 * Expands the dimensions of @box to include the coordinates at @point.
158 	 *
159 	 * Params:
160 	 *     point = the coordinates of the point to include
161 	 *     res = return location for the expanded box
162 	 *
163 	 * Since: 1.2
164 	 */
165 	public void expand(Point3D point, out Box res)
166 	{
167 		graphene_box_t* outres = sliceNew!graphene_box_t();
168 
169 		graphene_box_expand(graphene_box, (point is null) ? null : point.getPoint3DStruct(), outres);
170 
171 		res = ObjectG.getDObject!(Box)(outres, true);
172 	}
173 
174 	/**
175 	 * Expands the dimensions of @box by the given @scalar value.
176 	 *
177 	 * If @scalar is positive, the #graphene_box_t will grow; if @scalar is
178 	 * negative, the #graphene_box_t will shrink.
179 	 *
180 	 * Params:
181 	 *     scalar = a scalar value
182 	 *     res = return location for the expanded box
183 	 *
184 	 * Since: 1.2
185 	 */
186 	public void expandScalar(float scalar, out Box res)
187 	{
188 		graphene_box_t* outres = sliceNew!graphene_box_t();
189 
190 		graphene_box_expand_scalar(graphene_box, scalar, outres);
191 
192 		res = ObjectG.getDObject!(Box)(outres, true);
193 	}
194 
195 	/**
196 	 * Expands the dimensions of @box to include the coordinates of the
197 	 * given vector.
198 	 *
199 	 * Params:
200 	 *     vec = the coordinates of the point to include, as a #graphene_vec3_t
201 	 *     res = return location for the expanded box
202 	 *
203 	 * Since: 1.2
204 	 */
205 	public void expandVec3(Vec3 vec, out Box res)
206 	{
207 		graphene_box_t* outres = sliceNew!graphene_box_t();
208 
209 		graphene_box_expand_vec3(graphene_box, (vec is null) ? null : vec.getVec3Struct(), outres);
210 
211 		res = ObjectG.getDObject!(Box)(outres, true);
212 	}
213 
214 	/**
215 	 * Frees the resources allocated by graphene_box_alloc().
216 	 *
217 	 * Since: 1.2
218 	 */
219 	public void free()
220 	{
221 		graphene_box_free(graphene_box);
222 		ownedRef = false;
223 	}
224 
225 	/**
226 	 * Computes the bounding #graphene_sphere_t capable of containing the given
227 	 * #graphene_box_t.
228 	 *
229 	 * Params:
230 	 *     sphere = return location for the bounding sphere
231 	 *
232 	 * Since: 1.2
233 	 */
234 	public void getBoundingSphere(out Sphere sphere)
235 	{
236 		graphene_sphere_t* outsphere = sliceNew!graphene_sphere_t();
237 
238 		graphene_box_get_bounding_sphere(graphene_box, outsphere);
239 
240 		sphere = ObjectG.getDObject!(Sphere)(outsphere, true);
241 	}
242 
243 	/**
244 	 * Retrieves the coordinates of the center of a #graphene_box_t.
245 	 *
246 	 * Params:
247 	 *     center = return location for the coordinates of
248 	 *         the center
249 	 *
250 	 * Since: 1.2
251 	 */
252 	public void getCenter(out Point3D center)
253 	{
254 		graphene_point3d_t* outcenter = sliceNew!graphene_point3d_t();
255 
256 		graphene_box_get_center(graphene_box, outcenter);
257 
258 		center = ObjectG.getDObject!(Point3D)(outcenter, true);
259 	}
260 
261 	/**
262 	 * Retrieves the size of the @box on the Z axis.
263 	 *
264 	 * Returns: the depth of the box
265 	 *
266 	 * Since: 1.2
267 	 */
268 	public float getDepth()
269 	{
270 		return graphene_box_get_depth(graphene_box);
271 	}
272 
273 	/**
274 	 * Retrieves the size of the @box on the Y axis.
275 	 *
276 	 * Returns: the height of the box
277 	 *
278 	 * Since: 1.2
279 	 */
280 	public float getHeight()
281 	{
282 		return graphene_box_get_height(graphene_box);
283 	}
284 
285 	/**
286 	 * Retrieves the coordinates of the maximum point of the given
287 	 * #graphene_box_t.
288 	 *
289 	 * Params:
290 	 *     max = return location for the maximum point
291 	 *
292 	 * Since: 1.2
293 	 */
294 	public void getMax(out Point3D max)
295 	{
296 		graphene_point3d_t* outmax = sliceNew!graphene_point3d_t();
297 
298 		graphene_box_get_max(graphene_box, outmax);
299 
300 		max = ObjectG.getDObject!(Point3D)(outmax, true);
301 	}
302 
303 	/**
304 	 * Retrieves the coordinates of the minimum point of the given
305 	 * #graphene_box_t.
306 	 *
307 	 * Params:
308 	 *     min = return location for the minimum point
309 	 *
310 	 * Since: 1.2
311 	 */
312 	public void getMin(out Point3D min)
313 	{
314 		graphene_point3d_t* outmin = sliceNew!graphene_point3d_t();
315 
316 		graphene_box_get_min(graphene_box, outmin);
317 
318 		min = ObjectG.getDObject!(Point3D)(outmin, true);
319 	}
320 
321 	/**
322 	 * Retrieves the size of the box on all three axes, and stores
323 	 * it into the given @size vector.
324 	 *
325 	 * Params:
326 	 *     size = return location for the size
327 	 *
328 	 * Since: 1.2
329 	 */
330 	public void getSize(out Vec3 size)
331 	{
332 		graphene_vec3_t* outsize = sliceNew!graphene_vec3_t();
333 
334 		graphene_box_get_size(graphene_box, outsize);
335 
336 		size = ObjectG.getDObject!(Vec3)(outsize, true);
337 	}
338 
339 	/**
340 	 * Computes the vertices of the given #graphene_box_t.
341 	 *
342 	 * Params:
343 	 *     vertices = return location for an array
344 	 *         of 8 #graphene_vec3_t
345 	 *
346 	 * Since: 1.2
347 	 */
348 	public void getVertices(out Vec3[8] vertices)
349 	{
350 		graphene_vec3_t* outvertices = cast(graphene_vec3_t*)sliceAlloc0(graphene_vec3_t.sizeof * 8);
351 
352 		graphene_box_get_vertices(graphene_box, outvertices);
353 
354 		for(size_t i = 0; i < 8; i++)
355 		{
356 			vertices[i] = ObjectG.getDObject!(Vec3)(cast(graphene_vec3_t*) &outvertices[i]);
357 		}
358 	}
359 
360 	/**
361 	 * Retrieves the size of the @box on the X axis.
362 	 *
363 	 * Returns: the width of the box
364 	 *
365 	 * Since: 1.2
366 	 */
367 	public float getWidth()
368 	{
369 		return graphene_box_get_width(graphene_box);
370 	}
371 
372 	/**
373 	 * Initializes the given #graphene_box_t with two vertices.
374 	 *
375 	 * Params:
376 	 *     min = the coordinates of the minimum vertex
377 	 *     max = the coordinates of the maximum vertex
378 	 *
379 	 * Returns: the initialized #graphene_box_t
380 	 *
381 	 * Since: 1.2
382 	 */
383 	public Box init(Point3D min, Point3D max)
384 	{
385 		auto __p = graphene_box_init(graphene_box, (min is null) ? null : min.getPoint3DStruct(), (max is null) ? null : max.getPoint3DStruct());
386 
387 		if(__p is null)
388 		{
389 			return null;
390 		}
391 
392 		return ObjectG.getDObject!(Box)(cast(graphene_box_t*) __p);
393 	}
394 
395 	/**
396 	 * Initializes the given #graphene_box_t with the vertices of
397 	 * another #graphene_box_t.
398 	 *
399 	 * Params:
400 	 *     src = a #graphene_box_t
401 	 *
402 	 * Returns: the initialized #graphene_box_t
403 	 *
404 	 * Since: 1.2
405 	 */
406 	public Box initFromBox(Box src)
407 	{
408 		auto __p = graphene_box_init_from_box(graphene_box, (src is null) ? null : src.getBoxStruct());
409 
410 		if(__p is null)
411 		{
412 			return null;
413 		}
414 
415 		return ObjectG.getDObject!(Box)(cast(graphene_box_t*) __p);
416 	}
417 
418 	/**
419 	 * Initializes the given #graphene_box_t with the given array
420 	 * of vertices.
421 	 *
422 	 * If @n_points is 0, the returned box is initialized with
423 	 * graphene_box_empty().
424 	 *
425 	 * Params:
426 	 *     points = an array of #graphene_point3d_t
427 	 *
428 	 * Returns: the initialized #graphene_box_t
429 	 *
430 	 * Since: 1.2
431 	 */
432 	public Box initFromPoints(Point3D[] points)
433 	{
434 		graphene_point3d_t[] pointsArray = new graphene_point3d_t[points.length];
435 		for ( int i = 0; i < points.length; i++ )
436 		{
437 			pointsArray[i] = *(points[i].getPoint3DStruct());
438 		}
439 
440 		auto __p = graphene_box_init_from_points(graphene_box, cast(uint)points.length, pointsArray.ptr);
441 
442 		if(__p is null)
443 		{
444 			return null;
445 		}
446 
447 		return ObjectG.getDObject!(Box)(cast(graphene_box_t*) __p);
448 	}
449 
450 	/**
451 	 * Initializes the given #graphene_box_t with two vertices
452 	 * stored inside #graphene_vec3_t.
453 	 *
454 	 * Params:
455 	 *     min = the coordinates of the minimum vertex
456 	 *     max = the coordinates of the maximum vertex
457 	 *
458 	 * Returns: the initialized #graphene_box_t
459 	 *
460 	 * Since: 1.2
461 	 */
462 	public Box initFromVec3(Vec3 min, Vec3 max)
463 	{
464 		auto __p = graphene_box_init_from_vec3(graphene_box, (min is null) ? null : min.getVec3Struct(), (max is null) ? null : max.getVec3Struct());
465 
466 		if(__p is null)
467 		{
468 			return null;
469 		}
470 
471 		return ObjectG.getDObject!(Box)(cast(graphene_box_t*) __p);
472 	}
473 
474 	/**
475 	 * Initializes the given #graphene_box_t with the given array
476 	 * of vertices.
477 	 *
478 	 * If @n_vectors is 0, the returned box is initialized with
479 	 * graphene_box_empty().
480 	 *
481 	 * Params:
482 	 *     vectors = an array of #graphene_vec3_t
483 	 *
484 	 * Returns: the initialized #graphene_box_t
485 	 *
486 	 * Since: 1.2
487 	 */
488 	public Box initFromVectors(Vec3[] vectors)
489 	{
490 		graphene_vec3_t[] vectorsArray = new graphene_vec3_t[vectors.length];
491 		for ( int i = 0; i < vectors.length; i++ )
492 		{
493 			vectorsArray[i] = *(vectors[i].getVec3Struct());
494 		}
495 
496 		auto __p = graphene_box_init_from_vectors(graphene_box, cast(uint)vectors.length, vectorsArray.ptr);
497 
498 		if(__p is null)
499 		{
500 			return null;
501 		}
502 
503 		return ObjectG.getDObject!(Box)(cast(graphene_box_t*) __p);
504 	}
505 
506 	/**
507 	 * Intersects the two given #graphene_box_t.
508 	 *
509 	 * If the two boxes do not intersect, @res will contain a degenerate box
510 	 * initialized with graphene_box_empty().
511 	 *
512 	 * Params:
513 	 *     b = a #graphene_box_t
514 	 *     res = return location for the result
515 	 *
516 	 * Returns: true if the two boxes intersect
517 	 *
518 	 * Since: 1.2
519 	 */
520 	public bool intersection(Box b, out Box res)
521 	{
522 		graphene_box_t* outres = sliceNew!graphene_box_t();
523 
524 		auto __p = graphene_box_intersection(graphene_box, (b is null) ? null : b.getBoxStruct(), outres) != 0;
525 
526 		res = ObjectG.getDObject!(Box)(outres, true);
527 
528 		return __p;
529 	}
530 
531 	alias unio = union_;
532 	/**
533 	 * Unions the two given #graphene_box_t.
534 	 *
535 	 * Params:
536 	 *     b = the box to union to @a
537 	 *     res = return location for the result
538 	 *
539 	 * Since: 1.2
540 	 */
541 	public void union_(Box b, out Box res)
542 	{
543 		graphene_box_t* outres = sliceNew!graphene_box_t();
544 
545 		graphene_box_union(graphene_box, (b is null) ? null : b.getBoxStruct(), outres);
546 
547 		res = ObjectG.getDObject!(Box)(outres, true);
548 	}
549 
550 	/**
551 	 * A degenerate #graphene_box_t that can only be expanded.
552 	 *
553 	 * The returned value is owned by Graphene and should not be modified or freed.
554 	 *
555 	 * Returns: a #graphene_box_t
556 	 *
557 	 * Since: 1.2
558 	 */
559 	public static Box empty()
560 	{
561 		auto __p = graphene_box_empty();
562 
563 		if(__p is null)
564 		{
565 			return null;
566 		}
567 
568 		return ObjectG.getDObject!(Box)(cast(graphene_box_t*) __p);
569 	}
570 
571 	/**
572 	 * A degenerate #graphene_box_t that cannot be expanded.
573 	 *
574 	 * The returned value is owned by Graphene and should not be modified or freed.
575 	 *
576 	 * Returns: a #graphene_box_t
577 	 *
578 	 * Since: 1.2
579 	 */
580 	public static Box infinite()
581 	{
582 		auto __p = graphene_box_infinite();
583 
584 		if(__p is null)
585 		{
586 			return null;
587 		}
588 
589 		return ObjectG.getDObject!(Box)(cast(graphene_box_t*) __p);
590 	}
591 
592 	/**
593 	 * A #graphene_box_t with the minimum vertex set at (-1, -1, -1) and the
594 	 * maximum vertex set at (0, 0, 0).
595 	 *
596 	 * The returned value is owned by Graphene and should not be modified or freed.
597 	 *
598 	 * Returns: a #graphene_box_t
599 	 *
600 	 * Since: 1.2
601 	 */
602 	public static Box minusOne()
603 	{
604 		auto __p = graphene_box_minus_one();
605 
606 		if(__p is null)
607 		{
608 			return null;
609 		}
610 
611 		return ObjectG.getDObject!(Box)(cast(graphene_box_t*) __p);
612 	}
613 
614 	/**
615 	 * A #graphene_box_t with the minimum vertex set at (0, 0, 0) and the
616 	 * maximum vertex set at (1, 1, 1).
617 	 *
618 	 * The returned value is owned by Graphene and should not be modified or freed.
619 	 *
620 	 * Returns: a #graphene_box_t
621 	 *
622 	 * Since: 1.2
623 	 */
624 	public static Box one()
625 	{
626 		auto __p = graphene_box_one();
627 
628 		if(__p is null)
629 		{
630 			return null;
631 		}
632 
633 		return ObjectG.getDObject!(Box)(cast(graphene_box_t*) __p);
634 	}
635 
636 	/**
637 	 * A #graphene_box_t with the minimum vertex set at (-1, -1, -1) and the
638 	 * maximum vertex set at (1, 1, 1).
639 	 *
640 	 * The returned value is owned by Graphene and should not be modified or freed.
641 	 *
642 	 * Returns: a #graphene_box_t
643 	 *
644 	 * Since: 1.2
645 	 */
646 	public static Box oneMinusOne()
647 	{
648 		auto __p = graphene_box_one_minus_one();
649 
650 		if(__p is null)
651 		{
652 			return null;
653 		}
654 
655 		return ObjectG.getDObject!(Box)(cast(graphene_box_t*) __p);
656 	}
657 
658 	/**
659 	 * A #graphene_box_t with both the minimum and maximum vertices set at (0, 0, 0).
660 	 *
661 	 * The returned value is owned by Graphene and should not be modified or freed.
662 	 *
663 	 * Returns: a #graphene_box_t
664 	 *
665 	 * Since: 1.2
666 	 */
667 	public static Box zero()
668 	{
669 		auto __p = graphene_box_zero();
670 
671 		if(__p is null)
672 		{
673 			return null;
674 		}
675 
676 		return ObjectG.getDObject!(Box)(cast(graphene_box_t*) __p);
677 	}
678 }