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.Vec2; 26 27 private import glib.ConstructionException; 28 private import glib.MemorySlice; 29 private import gobject.ObjectG; 30 private import graphene.c.functions; 31 public import graphene.c.types; 32 private import gtkd.Loader; 33 34 35 /** 36 * A structure capable of holding a vector with two dimensions, x and y. 37 * 38 * The contents of the #graphene_vec2_t structure are private and should 39 * never be accessed directly. 40 */ 41 public class Vec2 42 { 43 /** the main Gtk struct */ 44 protected graphene_vec2_t* graphene_vec2; 45 protected bool ownedRef; 46 47 /** Get the main Gtk struct */ 48 public graphene_vec2_t* getVec2Struct(bool transferOwnership = false) 49 { 50 if (transferOwnership) 51 ownedRef = false; 52 return graphene_vec2; 53 } 54 55 /** the main Gtk struct as a void* */ 56 protected void* getStruct() 57 { 58 return cast(void*)graphene_vec2; 59 } 60 61 /** 62 * Sets our main struct and passes it to the parent class. 63 */ 64 public this (graphene_vec2_t* graphene_vec2, bool ownedRef = false) 65 { 66 this.graphene_vec2 = graphene_vec2; 67 this.ownedRef = ownedRef; 68 } 69 70 ~this () 71 { 72 if ( Linker.isLoaded(LIBRARY_GRAPHENE) && ownedRef ) 73 graphene_vec2_free(graphene_vec2); 74 } 75 76 77 /** */ 78 public static GType getType() 79 { 80 return graphene_vec2_get_type(); 81 } 82 83 /** 84 * Allocates a new #graphene_vec2_t structure. 85 * 86 * The contents of the returned structure are undefined. 87 * 88 * Use graphene_vec2_init() to initialize the vector. 89 * 90 * Returns: the newly allocated #graphene_vec2_t 91 * structure. Use graphene_vec2_free() to free the resources allocated 92 * by this function. 93 * 94 * Since: 1.0 95 * 96 * Throws: ConstructionException GTK+ fails to create the object. 97 */ 98 public this() 99 { 100 auto __p = graphene_vec2_alloc(); 101 102 if(__p is null) 103 { 104 throw new ConstructionException("null returned by alloc"); 105 } 106 107 this(cast(graphene_vec2_t*) __p); 108 } 109 110 /** 111 * Adds each component of the two passed vectors and places 112 * each result into the components of @res. 113 * 114 * Params: 115 * b = a #graphene_vec2_t 116 * res = return location for the result 117 * 118 * Since: 1.0 119 */ 120 public void add(Vec2 b, out Vec2 res) 121 { 122 graphene_vec2_t* outres = sliceNew!graphene_vec2_t(); 123 124 graphene_vec2_add(graphene_vec2, (b is null) ? null : b.getVec2Struct(), outres); 125 126 res = ObjectG.getDObject!(Vec2)(outres, true); 127 } 128 129 /** 130 * Divides each component of the first operand @a by the corresponding 131 * component of the second operand @b, and places the results into the 132 * vector @res. 133 * 134 * Params: 135 * b = a #graphene_vec2_t 136 * res = return location for the result 137 * 138 * Since: 1.0 139 */ 140 public void divide(Vec2 b, out Vec2 res) 141 { 142 graphene_vec2_t* outres = sliceNew!graphene_vec2_t(); 143 144 graphene_vec2_divide(graphene_vec2, (b is null) ? null : b.getVec2Struct(), outres); 145 146 res = ObjectG.getDObject!(Vec2)(outres, true); 147 } 148 149 /** 150 * Computes the dot product of the two given vectors. 151 * 152 * Params: 153 * b = a #graphene_vec2_t 154 * 155 * Returns: the dot product of the vectors 156 * 157 * Since: 1.0 158 */ 159 public float dot(Vec2 b) 160 { 161 return graphene_vec2_dot(graphene_vec2, (b is null) ? null : b.getVec2Struct()); 162 } 163 164 /** 165 * Checks whether the two given #graphene_vec2_t are equal. 166 * 167 * Params: 168 * v2 = a #graphene_vec2_t 169 * 170 * Returns: `true` if the two vectors are equal, and false otherwise 171 * 172 * Since: 1.2 173 */ 174 public bool equal(Vec2 v2) 175 { 176 return graphene_vec2_equal(graphene_vec2, (v2 is null) ? null : v2.getVec2Struct()) != 0; 177 } 178 179 /** 180 * Frees the resources allocated by @v 181 * 182 * Since: 1.0 183 */ 184 public void free() 185 { 186 graphene_vec2_free(graphene_vec2); 187 ownedRef = false; 188 } 189 190 /** 191 * Retrieves the X component of the #graphene_vec2_t. 192 * 193 * Returns: the value of the X component 194 * 195 * Since: 1.0 196 */ 197 public float getX() 198 { 199 return graphene_vec2_get_x(graphene_vec2); 200 } 201 202 /** 203 * Retrieves the Y component of the #graphene_vec2_t. 204 * 205 * Returns: the value of the Y component 206 * 207 * Since: 1.0 208 */ 209 public float getY() 210 { 211 return graphene_vec2_get_y(graphene_vec2); 212 } 213 214 /** 215 * Initializes a #graphene_vec2_t using the given values. 216 * 217 * This function can be called multiple times. 218 * 219 * Params: 220 * x = the X field of the vector 221 * y = the Y field of the vector 222 * 223 * Returns: the initialized vector 224 * 225 * Since: 1.0 226 */ 227 public Vec2 init(float x, float y) 228 { 229 auto __p = graphene_vec2_init(graphene_vec2, x, y); 230 231 if(__p is null) 232 { 233 return null; 234 } 235 236 return ObjectG.getDObject!(Vec2)(cast(graphene_vec2_t*) __p); 237 } 238 239 /** 240 * Initializes @v with the contents of the given array. 241 * 242 * Params: 243 * src = an array of floating point values 244 * with at least two elements 245 * 246 * Returns: the initialized vector 247 * 248 * Since: 1.0 249 */ 250 public Vec2 initFromFloat(float[2] src) 251 { 252 auto __p = graphene_vec2_init_from_float(graphene_vec2, src.ptr); 253 254 if(__p is null) 255 { 256 return null; 257 } 258 259 return ObjectG.getDObject!(Vec2)(cast(graphene_vec2_t*) __p); 260 } 261 262 /** 263 * Copies the contents of @src into @v. 264 * 265 * Params: 266 * src = a #graphene_vec2_t 267 * 268 * Returns: the initialized vector 269 * 270 * Since: 1.0 271 */ 272 public Vec2 initFromVec2(Vec2 src) 273 { 274 auto __p = graphene_vec2_init_from_vec2(graphene_vec2, (src is null) ? null : src.getVec2Struct()); 275 276 if(__p is null) 277 { 278 return null; 279 } 280 281 return ObjectG.getDObject!(Vec2)(cast(graphene_vec2_t*) __p); 282 } 283 284 /** 285 * Linearly interpolates @v1 and @v2 using the given @factor. 286 * 287 * Params: 288 * v2 = a #graphene_vec2_t 289 * factor = the interpolation factor 290 * res = the interpolated vector 291 * 292 * Since: 1.10 293 */ 294 public void interpolate(Vec2 v2, double factor, out Vec2 res) 295 { 296 graphene_vec2_t* outres = sliceNew!graphene_vec2_t(); 297 298 graphene_vec2_interpolate(graphene_vec2, (v2 is null) ? null : v2.getVec2Struct(), factor, outres); 299 300 res = ObjectG.getDObject!(Vec2)(outres, true); 301 } 302 303 /** 304 * Computes the length of the given vector. 305 * 306 * Returns: the length of the vector 307 * 308 * Since: 1.0 309 */ 310 public float length() 311 { 312 return graphene_vec2_length(graphene_vec2); 313 } 314 315 /** 316 * Compares the two given vectors and places the maximum 317 * values of each component into @res. 318 * 319 * Params: 320 * b = a #graphene_vec2_t 321 * res = the resulting vector 322 * 323 * Since: 1.0 324 */ 325 public void max(Vec2 b, out Vec2 res) 326 { 327 graphene_vec2_t* outres = sliceNew!graphene_vec2_t(); 328 329 graphene_vec2_max(graphene_vec2, (b is null) ? null : b.getVec2Struct(), outres); 330 331 res = ObjectG.getDObject!(Vec2)(outres, true); 332 } 333 334 /** 335 * Compares the two given vectors and places the minimum 336 * values of each component into @res. 337 * 338 * Params: 339 * b = a #graphene_vec2_t 340 * res = the resulting vector 341 * 342 * Since: 1.0 343 */ 344 public void min(Vec2 b, out Vec2 res) 345 { 346 graphene_vec2_t* outres = sliceNew!graphene_vec2_t(); 347 348 graphene_vec2_min(graphene_vec2, (b is null) ? null : b.getVec2Struct(), outres); 349 350 res = ObjectG.getDObject!(Vec2)(outres, true); 351 } 352 353 /** 354 * Multiplies each component of the two passed vectors and places 355 * each result into the components of @res. 356 * 357 * Params: 358 * b = a #graphene_vec2_t 359 * res = return location for the result 360 * 361 * Since: 1.0 362 */ 363 public void multiply(Vec2 b, out Vec2 res) 364 { 365 graphene_vec2_t* outres = sliceNew!graphene_vec2_t(); 366 367 graphene_vec2_multiply(graphene_vec2, (b is null) ? null : b.getVec2Struct(), outres); 368 369 res = ObjectG.getDObject!(Vec2)(outres, true); 370 } 371 372 /** 373 * Compares the two given #graphene_vec2_t vectors and checks 374 * whether their values are within the given @epsilon. 375 * 376 * Params: 377 * v2 = a #graphene_vec2_t 378 * epsilon = the threshold between the two vectors 379 * 380 * Returns: `true` if the two vectors are near each other 381 * 382 * Since: 1.2 383 */ 384 public bool near(Vec2 v2, float epsilon) 385 { 386 return graphene_vec2_near(graphene_vec2, (v2 is null) ? null : v2.getVec2Struct(), epsilon) != 0; 387 } 388 389 /** 390 * Negates the given #graphene_vec2_t. 391 * 392 * Params: 393 * res = return location for the result vector 394 * 395 * Since: 1.2 396 */ 397 public void negate(out Vec2 res) 398 { 399 graphene_vec2_t* outres = sliceNew!graphene_vec2_t(); 400 401 graphene_vec2_negate(graphene_vec2, outres); 402 403 res = ObjectG.getDObject!(Vec2)(outres, true); 404 } 405 406 /** 407 * Computes the normalized vector for the given vector @v. 408 * 409 * Params: 410 * res = return location for the 411 * normalized vector 412 * 413 * Since: 1.0 414 */ 415 public void normalize(out Vec2 res) 416 { 417 graphene_vec2_t* outres = sliceNew!graphene_vec2_t(); 418 419 graphene_vec2_normalize(graphene_vec2, outres); 420 421 res = ObjectG.getDObject!(Vec2)(outres, true); 422 } 423 424 /** 425 * Multiplies all components of the given vector with the given scalar @factor. 426 * 427 * Params: 428 * factor = the scalar factor 429 * res = return location for the result vector 430 * 431 * Since: 1.2 432 */ 433 public void scale(float factor, out Vec2 res) 434 { 435 graphene_vec2_t* outres = sliceNew!graphene_vec2_t(); 436 437 graphene_vec2_scale(graphene_vec2, factor, outres); 438 439 res = ObjectG.getDObject!(Vec2)(outres, true); 440 } 441 442 /** 443 * Subtracts from each component of the first operand @a the 444 * corresponding component of the second operand @b and places 445 * each result into the components of @res. 446 * 447 * Params: 448 * b = a #graphene_vec2_t 449 * res = return location for the result 450 * 451 * Since: 1.0 452 */ 453 public void subtract(Vec2 b, out Vec2 res) 454 { 455 graphene_vec2_t* outres = sliceNew!graphene_vec2_t(); 456 457 graphene_vec2_subtract(graphene_vec2, (b is null) ? null : b.getVec2Struct(), outres); 458 459 res = ObjectG.getDObject!(Vec2)(outres, true); 460 } 461 462 /** 463 * Stores the components of @v into an array. 464 * 465 * Params: 466 * dest = return location 467 * for an array of floating point values with at least 2 elements 468 * 469 * Since: 1.0 470 */ 471 public void toFloat(out float[2] dest) 472 { 473 float[2] outdest; 474 475 graphene_vec2_to_float(graphene_vec2, outdest.ptr); 476 477 dest = outdest[0 .. 2]; 478 } 479 480 /** 481 * Retrieves a constant vector with (1, 1) components. 482 * 483 * Returns: the one vector 484 * 485 * Since: 1.0 486 */ 487 public static Vec2 one() 488 { 489 auto __p = graphene_vec2_one(); 490 491 if(__p is null) 492 { 493 return null; 494 } 495 496 return ObjectG.getDObject!(Vec2)(cast(graphene_vec2_t*) __p); 497 } 498 499 /** 500 * Retrieves a constant vector with (1, 0) components. 501 * 502 * Returns: the X axis vector 503 * 504 * Since: 1.0 505 */ 506 public static Vec2 xAxis() 507 { 508 auto __p = graphene_vec2_x_axis(); 509 510 if(__p is null) 511 { 512 return null; 513 } 514 515 return ObjectG.getDObject!(Vec2)(cast(graphene_vec2_t*) __p); 516 } 517 518 /** 519 * Retrieves a constant vector with (0, 1) components. 520 * 521 * Returns: the Y axis vector 522 * 523 * Since: 1.0 524 */ 525 public static Vec2 yAxis() 526 { 527 auto __p = graphene_vec2_y_axis(); 528 529 if(__p is null) 530 { 531 return null; 532 } 533 534 return ObjectG.getDObject!(Vec2)(cast(graphene_vec2_t*) __p); 535 } 536 537 /** 538 * Retrieves a constant vector with (0, 0) components. 539 * 540 * Returns: the zero vector 541 * 542 * Since: 1.0 543 */ 544 public static Vec2 zero() 545 { 546 auto __p = graphene_vec2_zero(); 547 548 if(__p is null) 549 { 550 return null; 551 } 552 553 return ObjectG.getDObject!(Vec2)(cast(graphene_vec2_t*) __p); 554 } 555 }