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.Vec4;
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.Vec3;
32 private import graphene.c.functions;
33 public  import graphene.c.types;
34 private import gtkd.Loader;
35 
36 
37 /**
38  * A structure capable of holding a vector with four dimensions: x, y, z, and w.
39  * 
40  * The contents of the #graphene_vec4_t structure are private and should
41  * never be accessed directly.
42  */
43 public class Vec4
44 {
45 	/** the main Gtk struct */
46 	protected graphene_vec4_t* graphene_vec4;
47 	protected bool ownedRef;
48 
49 	/** Get the main Gtk struct */
50 	public graphene_vec4_t* getVec4Struct(bool transferOwnership = false)
51 	{
52 		if (transferOwnership)
53 			ownedRef = false;
54 		return graphene_vec4;
55 	}
56 
57 	/** the main Gtk struct as a void* */
58 	protected void* getStruct()
59 	{
60 		return cast(void*)graphene_vec4;
61 	}
62 
63 	/**
64 	 * Sets our main struct and passes it to the parent class.
65 	 */
66 	public this (graphene_vec4_t* graphene_vec4, bool ownedRef = false)
67 	{
68 		this.graphene_vec4 = graphene_vec4;
69 		this.ownedRef = ownedRef;
70 	}
71 
72 	~this ()
73 	{
74 		if ( Linker.isLoaded(LIBRARY_GRAPHENE) && ownedRef )
75 			graphene_vec4_free(graphene_vec4);
76 	}
77 
78 
79 	/** */
80 	public static GType getType()
81 	{
82 		return graphene_vec4_get_type();
83 	}
84 
85 	/**
86 	 * Allocates a new #graphene_vec4_t structure.
87 	 *
88 	 * The contents of the returned structure are undefined.
89 	 *
90 	 * Use graphene_vec4_init() to initialize the vector.
91 	 *
92 	 * Returns: the newly allocated #graphene_vec4_t
93 	 *     structure. Use graphene_vec4_free() to free the resources allocated
94 	 *     by this function.
95 	 *
96 	 * Since: 1.0
97 	 *
98 	 * Throws: ConstructionException GTK+ fails to create the object.
99 	 */
100 	public this()
101 	{
102 		auto __p = graphene_vec4_alloc();
103 
104 		if(__p is null)
105 		{
106 			throw new ConstructionException("null returned by alloc");
107 		}
108 
109 		this(cast(graphene_vec4_t*) __p);
110 	}
111 
112 	/**
113 	 * Adds each component of the two given vectors.
114 	 *
115 	 * Params:
116 	 *     b = a #graphene_vec4_t
117 	 *     res = return location for the resulting vector
118 	 *
119 	 * Since: 1.0
120 	 */
121 	public void add(Vec4 b, out Vec4 res)
122 	{
123 		graphene_vec4_t* outres = sliceNew!graphene_vec4_t();
124 
125 		graphene_vec4_add(graphene_vec4, (b is null) ? null : b.getVec4Struct(), outres);
126 
127 		res = ObjectG.getDObject!(Vec4)(outres, true);
128 	}
129 
130 	/**
131 	 * Divides each component of the first operand @a by the corresponding
132 	 * component of the second operand @b, and places the results into the
133 	 * vector @res.
134 	 *
135 	 * Params:
136 	 *     b = a #graphene_vec4_t
137 	 *     res = return location for the resulting vector
138 	 *
139 	 * Since: 1.0
140 	 */
141 	public void divide(Vec4 b, out Vec4 res)
142 	{
143 		graphene_vec4_t* outres = sliceNew!graphene_vec4_t();
144 
145 		graphene_vec4_divide(graphene_vec4, (b is null) ? null : b.getVec4Struct(), outres);
146 
147 		res = ObjectG.getDObject!(Vec4)(outres, true);
148 	}
149 
150 	/**
151 	 * Computes the dot product of the two given vectors.
152 	 *
153 	 * Params:
154 	 *     b = a #graphene_vec4_t
155 	 *
156 	 * Returns: the value of the dot product
157 	 *
158 	 * Since: 1.0
159 	 */
160 	public float dot(Vec4 b)
161 	{
162 		return graphene_vec4_dot(graphene_vec4, (b is null) ? null : b.getVec4Struct());
163 	}
164 
165 	/**
166 	 * Checks whether the two given #graphene_vec4_t are equal.
167 	 *
168 	 * Params:
169 	 *     v2 = a #graphene_vec4_t
170 	 *
171 	 * Returns: `true` if the two vectors are equal, and false otherwise
172 	 *
173 	 * Since: 1.2
174 	 */
175 	public bool equal(Vec4 v2)
176 	{
177 		return graphene_vec4_equal(graphene_vec4, (v2 is null) ? null : v2.getVec4Struct()) != 0;
178 	}
179 
180 	/**
181 	 * Frees the resources allocated by @v
182 	 *
183 	 * Since: 1.0
184 	 */
185 	public void free()
186 	{
187 		graphene_vec4_free(graphene_vec4);
188 		ownedRef = false;
189 	}
190 
191 	/**
192 	 * Retrieves the value of the fourth component of the given #graphene_vec4_t.
193 	 *
194 	 * Returns: the value of the fourth component
195 	 *
196 	 * Since: 1.0
197 	 */
198 	public float getW()
199 	{
200 		return graphene_vec4_get_w(graphene_vec4);
201 	}
202 
203 	/**
204 	 * Retrieves the value of the first component of the given #graphene_vec4_t.
205 	 *
206 	 * Returns: the value of the first component
207 	 *
208 	 * Since: 1.0
209 	 */
210 	public float getX()
211 	{
212 		return graphene_vec4_get_x(graphene_vec4);
213 	}
214 
215 	/**
216 	 * Creates a #graphene_vec2_t that contains the first two components
217 	 * of the given #graphene_vec4_t.
218 	 *
219 	 * Params:
220 	 *     res = return location for a #graphene_vec2_t
221 	 *
222 	 * Since: 1.0
223 	 */
224 	public void getXy(out Vec2 res)
225 	{
226 		graphene_vec2_t* outres = sliceNew!graphene_vec2_t();
227 
228 		graphene_vec4_get_xy(graphene_vec4, outres);
229 
230 		res = ObjectG.getDObject!(Vec2)(outres, true);
231 	}
232 
233 	/**
234 	 * Creates a #graphene_vec3_t that contains the first three components
235 	 * of the given #graphene_vec4_t.
236 	 *
237 	 * Params:
238 	 *     res = return location for a graphene_vec3_t
239 	 *
240 	 * Since: 1.0
241 	 */
242 	public void getXyz(out Vec3 res)
243 	{
244 		graphene_vec3_t* outres = sliceNew!graphene_vec3_t();
245 
246 		graphene_vec4_get_xyz(graphene_vec4, outres);
247 
248 		res = ObjectG.getDObject!(Vec3)(outres, true);
249 	}
250 
251 	/**
252 	 * Retrieves the value of the second component of the given #graphene_vec4_t.
253 	 *
254 	 * Returns: the value of the second component
255 	 *
256 	 * Since: 1.0
257 	 */
258 	public float getY()
259 	{
260 		return graphene_vec4_get_y(graphene_vec4);
261 	}
262 
263 	/**
264 	 * Retrieves the value of the third component of the given #graphene_vec4_t.
265 	 *
266 	 * Returns: the value of the third component
267 	 *
268 	 * Since: 1.0
269 	 */
270 	public float getZ()
271 	{
272 		return graphene_vec4_get_z(graphene_vec4);
273 	}
274 
275 	/**
276 	 * Initializes a #graphene_vec4_t using the given values.
277 	 *
278 	 * This function can be called multiple times.
279 	 *
280 	 * Params:
281 	 *     x = the X field of the vector
282 	 *     y = the Y field of the vector
283 	 *     z = the Z field of the vector
284 	 *     w = the W field of the vector
285 	 *
286 	 * Returns: a pointer to the initialized
287 	 *     vector
288 	 *
289 	 * Since: 1.0
290 	 */
291 	public Vec4 init(float x, float y, float z, float w)
292 	{
293 		auto __p = graphene_vec4_init(graphene_vec4, x, y, z, w);
294 
295 		if(__p is null)
296 		{
297 			return null;
298 		}
299 
300 		return ObjectG.getDObject!(Vec4)(cast(graphene_vec4_t*) __p);
301 	}
302 
303 	/**
304 	 * Initializes a #graphene_vec4_t with the values inside the given array.
305 	 *
306 	 * Params:
307 	 *     src = an array of four floating point values
308 	 *
309 	 * Returns: the initialized vector
310 	 *
311 	 * Since: 1.0
312 	 */
313 	public Vec4 initFromFloat(float[4] src)
314 	{
315 		auto __p = graphene_vec4_init_from_float(graphene_vec4, src.ptr);
316 
317 		if(__p is null)
318 		{
319 			return null;
320 		}
321 
322 		return ObjectG.getDObject!(Vec4)(cast(graphene_vec4_t*) __p);
323 	}
324 
325 	/**
326 	 * Initializes a #graphene_vec4_t using the components of a
327 	 * #graphene_vec2_t and the values of @z and @w.
328 	 *
329 	 * Params:
330 	 *     src = a #graphene_vec2_t
331 	 *     z = the value for the third component of @v
332 	 *     w = the value for the fourth component of @v
333 	 *
334 	 * Returns: the initialized vector
335 	 *
336 	 * Since: 1.0
337 	 */
338 	public Vec4 initFromVec2(Vec2 src, float z, float w)
339 	{
340 		auto __p = graphene_vec4_init_from_vec2(graphene_vec4, (src is null) ? null : src.getVec2Struct(), z, w);
341 
342 		if(__p is null)
343 		{
344 			return null;
345 		}
346 
347 		return ObjectG.getDObject!(Vec4)(cast(graphene_vec4_t*) __p);
348 	}
349 
350 	/**
351 	 * Initializes a #graphene_vec4_t using the components of a
352 	 * #graphene_vec3_t and the value of @w.
353 	 *
354 	 * Params:
355 	 *     src = a #graphene_vec3_t
356 	 *     w = the value for the fourth component of @v
357 	 *
358 	 * Returns: the initialized vector
359 	 *
360 	 * Since: 1.0
361 	 */
362 	public Vec4 initFromVec3(Vec3 src, float w)
363 	{
364 		auto __p = graphene_vec4_init_from_vec3(graphene_vec4, (src is null) ? null : src.getVec3Struct(), w);
365 
366 		if(__p is null)
367 		{
368 			return null;
369 		}
370 
371 		return ObjectG.getDObject!(Vec4)(cast(graphene_vec4_t*) __p);
372 	}
373 
374 	/**
375 	 * Initializes a #graphene_vec4_t using the components of
376 	 * another #graphene_vec4_t.
377 	 *
378 	 * Params:
379 	 *     src = a #graphene_vec4_t
380 	 *
381 	 * Returns: the initialized vector
382 	 *
383 	 * Since: 1.0
384 	 */
385 	public Vec4 initFromVec4(Vec4 src)
386 	{
387 		auto __p = graphene_vec4_init_from_vec4(graphene_vec4, (src is null) ? null : src.getVec4Struct());
388 
389 		if(__p is null)
390 		{
391 			return null;
392 		}
393 
394 		return ObjectG.getDObject!(Vec4)(cast(graphene_vec4_t*) __p);
395 	}
396 
397 	/**
398 	 * Linearly interpolates @v1 and @v2 using the given @factor.
399 	 *
400 	 * Params:
401 	 *     v2 = a #graphene_vec4_t
402 	 *     factor = the interpolation factor
403 	 *     res = the interpolated vector
404 	 *
405 	 * Since: 1.10
406 	 */
407 	public void interpolate(Vec4 v2, double factor, out Vec4 res)
408 	{
409 		graphene_vec4_t* outres = sliceNew!graphene_vec4_t();
410 
411 		graphene_vec4_interpolate(graphene_vec4, (v2 is null) ? null : v2.getVec4Struct(), factor, outres);
412 
413 		res = ObjectG.getDObject!(Vec4)(outres, true);
414 	}
415 
416 	/**
417 	 * Computes the length of the given #graphene_vec4_t.
418 	 *
419 	 * Returns: the length of the vector
420 	 *
421 	 * Since: 1.0
422 	 */
423 	public float length()
424 	{
425 		return graphene_vec4_length(graphene_vec4);
426 	}
427 
428 	/**
429 	 * Compares each component of the two given vectors and creates a
430 	 * vector that contains the maximum values.
431 	 *
432 	 * Params:
433 	 *     b = a #graphene_vec4_t
434 	 *     res = return location for the result vector
435 	 *
436 	 * Since: 1.0
437 	 */
438 	public void max(Vec4 b, out Vec4 res)
439 	{
440 		graphene_vec4_t* outres = sliceNew!graphene_vec4_t();
441 
442 		graphene_vec4_max(graphene_vec4, (b is null) ? null : b.getVec4Struct(), outres);
443 
444 		res = ObjectG.getDObject!(Vec4)(outres, true);
445 	}
446 
447 	/**
448 	 * Compares each component of the two given vectors and creates a
449 	 * vector that contains the minimum values.
450 	 *
451 	 * Params:
452 	 *     b = a #graphene_vec4_t
453 	 *     res = return location for the result vector
454 	 *
455 	 * Since: 1.0
456 	 */
457 	public void min(Vec4 b, out Vec4 res)
458 	{
459 		graphene_vec4_t* outres = sliceNew!graphene_vec4_t();
460 
461 		graphene_vec4_min(graphene_vec4, (b is null) ? null : b.getVec4Struct(), outres);
462 
463 		res = ObjectG.getDObject!(Vec4)(outres, true);
464 	}
465 
466 	/**
467 	 * Multiplies each component of the two given vectors.
468 	 *
469 	 * Params:
470 	 *     b = a #graphene_vec4_t
471 	 *     res = return location for the resulting vector
472 	 *
473 	 * Since: 1.0
474 	 */
475 	public void multiply(Vec4 b, out Vec4 res)
476 	{
477 		graphene_vec4_t* outres = sliceNew!graphene_vec4_t();
478 
479 		graphene_vec4_multiply(graphene_vec4, (b is null) ? null : b.getVec4Struct(), outres);
480 
481 		res = ObjectG.getDObject!(Vec4)(outres, true);
482 	}
483 
484 	/**
485 	 * Compares the two given #graphene_vec4_t vectors and checks
486 	 * whether their values are within the given @epsilon.
487 	 *
488 	 * Params:
489 	 *     v2 = a #graphene_vec4_t
490 	 *     epsilon = the threshold between the two vectors
491 	 *
492 	 * Returns: `true` if the two vectors are near each other
493 	 *
494 	 * Since: 1.2
495 	 */
496 	public bool near(Vec4 v2, float epsilon)
497 	{
498 		return graphene_vec4_near(graphene_vec4, (v2 is null) ? null : v2.getVec4Struct(), epsilon) != 0;
499 	}
500 
501 	/**
502 	 * Negates the given #graphene_vec4_t.
503 	 *
504 	 * Params:
505 	 *     res = return location for the result vector
506 	 *
507 	 * Since: 1.2
508 	 */
509 	public void negate(out Vec4 res)
510 	{
511 		graphene_vec4_t* outres = sliceNew!graphene_vec4_t();
512 
513 		graphene_vec4_negate(graphene_vec4, outres);
514 
515 		res = ObjectG.getDObject!(Vec4)(outres, true);
516 	}
517 
518 	/**
519 	 * Normalizes the given #graphene_vec4_t.
520 	 *
521 	 * Params:
522 	 *     res = return location for the normalized
523 	 *         vector
524 	 *
525 	 * Since: 1.0
526 	 */
527 	public void normalize(out Vec4 res)
528 	{
529 		graphene_vec4_t* outres = sliceNew!graphene_vec4_t();
530 
531 		graphene_vec4_normalize(graphene_vec4, outres);
532 
533 		res = ObjectG.getDObject!(Vec4)(outres, true);
534 	}
535 
536 	/**
537 	 * Multiplies all components of the given vector with the given scalar @factor.
538 	 *
539 	 * Params:
540 	 *     factor = the scalar factor
541 	 *     res = return location for the result vector
542 	 *
543 	 * Since: 1.2
544 	 */
545 	public void scale(float factor, out Vec4 res)
546 	{
547 		graphene_vec4_t* outres = sliceNew!graphene_vec4_t();
548 
549 		graphene_vec4_scale(graphene_vec4, factor, outres);
550 
551 		res = ObjectG.getDObject!(Vec4)(outres, true);
552 	}
553 
554 	/**
555 	 * Subtracts from each component of the first operand @a the
556 	 * corresponding component of the second operand @b and places
557 	 * each result into the components of @res.
558 	 *
559 	 * Params:
560 	 *     b = a #graphene_vec4_t
561 	 *     res = return location for the resulting vector
562 	 *
563 	 * Since: 1.0
564 	 */
565 	public void subtract(Vec4 b, out Vec4 res)
566 	{
567 		graphene_vec4_t* outres = sliceNew!graphene_vec4_t();
568 
569 		graphene_vec4_subtract(graphene_vec4, (b is null) ? null : b.getVec4Struct(), outres);
570 
571 		res = ObjectG.getDObject!(Vec4)(outres, true);
572 	}
573 
574 	/**
575 	 * Stores the components of the given #graphene_vec4_t into an array
576 	 * of floating point values.
577 	 *
578 	 * Params:
579 	 *     dest = return location for
580 	 *         an array of floating point values
581 	 *
582 	 * Since: 1.0
583 	 */
584 	public void toFloat(out float[4] dest)
585 	{
586 		float[4] outdest;
587 
588 		graphene_vec4_to_float(graphene_vec4, outdest.ptr);
589 
590 		dest = outdest[0 .. 4];
591 	}
592 
593 	/**
594 	 * Retrieves a pointer to a #graphene_vec4_t with all its
595 	 * components set to 1.
596 	 *
597 	 * Returns: a constant vector
598 	 *
599 	 * Since: 1.0
600 	 */
601 	public static Vec4 one()
602 	{
603 		auto __p = graphene_vec4_one();
604 
605 		if(__p is null)
606 		{
607 			return null;
608 		}
609 
610 		return ObjectG.getDObject!(Vec4)(cast(graphene_vec4_t*) __p);
611 	}
612 
613 	/**
614 	 * Retrieves a pointer to a #graphene_vec4_t with its
615 	 * components set to (0, 0, 0, 1).
616 	 *
617 	 * Returns: a constant vector
618 	 *
619 	 * Since: 1.0
620 	 */
621 	public static Vec4 wAxis()
622 	{
623 		auto __p = graphene_vec4_w_axis();
624 
625 		if(__p is null)
626 		{
627 			return null;
628 		}
629 
630 		return ObjectG.getDObject!(Vec4)(cast(graphene_vec4_t*) __p);
631 	}
632 
633 	/**
634 	 * Retrieves a pointer to a #graphene_vec4_t with its
635 	 * components set to (1, 0, 0, 0).
636 	 *
637 	 * Returns: a constant vector
638 	 *
639 	 * Since: 1.0
640 	 */
641 	public static Vec4 xAxis()
642 	{
643 		auto __p = graphene_vec4_x_axis();
644 
645 		if(__p is null)
646 		{
647 			return null;
648 		}
649 
650 		return ObjectG.getDObject!(Vec4)(cast(graphene_vec4_t*) __p);
651 	}
652 
653 	/**
654 	 * Retrieves a pointer to a #graphene_vec4_t with its
655 	 * components set to (0, 1, 0, 0).
656 	 *
657 	 * Returns: a constant vector
658 	 *
659 	 * Since: 1.0
660 	 */
661 	public static Vec4 yAxis()
662 	{
663 		auto __p = graphene_vec4_y_axis();
664 
665 		if(__p is null)
666 		{
667 			return null;
668 		}
669 
670 		return ObjectG.getDObject!(Vec4)(cast(graphene_vec4_t*) __p);
671 	}
672 
673 	/**
674 	 * Retrieves a pointer to a #graphene_vec4_t with its
675 	 * components set to (0, 0, 1, 0).
676 	 *
677 	 * Returns: a constant vector
678 	 *
679 	 * Since: 1.0
680 	 */
681 	public static Vec4 zAxis()
682 	{
683 		auto __p = graphene_vec4_z_axis();
684 
685 		if(__p is null)
686 		{
687 			return null;
688 		}
689 
690 		return ObjectG.getDObject!(Vec4)(cast(graphene_vec4_t*) __p);
691 	}
692 
693 	/**
694 	 * Retrieves a pointer to a #graphene_vec4_t with all its
695 	 * components set to 0.
696 	 *
697 	 * Returns: a constant vector
698 	 *
699 	 * Since: 1.0
700 	 */
701 	public static Vec4 zero()
702 	{
703 		auto __p = graphene_vec4_zero();
704 
705 		if(__p is null)
706 		{
707 			return null;
708 		}
709 
710 		return ObjectG.getDObject!(Vec4)(cast(graphene_vec4_t*) __p);
711 	}
712 }