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.Point3D; 26 27 private import glib.ConstructionException; 28 private import glib.MemorySlice; 29 private import gobject.ObjectG; 30 private import graphene.Rect; 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 point with three components: X, Y, and Z. 39 * 40 * Since: 1.0 41 */ 42 public final class Point3D 43 { 44 /** the main Gtk struct */ 45 protected graphene_point3d_t* graphene_point3d; 46 protected bool ownedRef; 47 48 /** Get the main Gtk struct */ 49 public graphene_point3d_t* getPoint3DStruct(bool transferOwnership = false) 50 { 51 if (transferOwnership) 52 ownedRef = false; 53 return graphene_point3d; 54 } 55 56 /** the main Gtk struct as a void* */ 57 protected void* getStruct() 58 { 59 return cast(void*)graphene_point3d; 60 } 61 62 /** 63 * Sets our main struct and passes it to the parent class. 64 */ 65 public this (graphene_point3d_t* graphene_point3d, bool ownedRef = false) 66 { 67 this.graphene_point3d = graphene_point3d; 68 this.ownedRef = ownedRef; 69 } 70 71 ~this () 72 { 73 if ( Linker.isLoaded(LIBRARY_GRAPHENE) && ownedRef ) 74 graphene_point3d_free(graphene_point3d); 75 } 76 77 78 /** 79 * the X coordinate 80 */ 81 public @property float x() 82 { 83 return graphene_point3d.x; 84 } 85 86 /** Ditto */ 87 public @property void x(float value) 88 { 89 graphene_point3d.x = value; 90 } 91 92 /** 93 * the Y coordinate 94 */ 95 public @property float y() 96 { 97 return graphene_point3d.y; 98 } 99 100 /** Ditto */ 101 public @property void y(float value) 102 { 103 graphene_point3d.y = value; 104 } 105 106 /** 107 * the Z coordinate 108 */ 109 public @property float z() 110 { 111 return graphene_point3d.z; 112 } 113 114 /** Ditto */ 115 public @property void z(float value) 116 { 117 graphene_point3d.z = value; 118 } 119 120 /** */ 121 public static GType getType() 122 { 123 return graphene_point3d_get_type(); 124 } 125 126 /** 127 * Allocates a #graphene_point3d_t structure. 128 * 129 * Returns: the newly allocated structure. 130 * Use graphene_point3d_free() to free the resources 131 * allocated by this function. 132 * 133 * Since: 1.0 134 * 135 * Throws: ConstructionException GTK+ fails to create the object. 136 */ 137 public this() 138 { 139 auto __p = graphene_point3d_alloc(); 140 141 if(__p is null) 142 { 143 throw new ConstructionException("null returned by alloc"); 144 } 145 146 this(cast(graphene_point3d_t*) __p); 147 } 148 149 /** 150 * Computes the cross product of the two given #graphene_point3d_t. 151 * 152 * Params: 153 * b = a #graphene_point3d_t 154 * res = return location for the cross 155 * product 156 * 157 * Since: 1.0 158 */ 159 public void cross(Point3D b, out Point3D res) 160 { 161 graphene_point3d_t* outres = sliceNew!graphene_point3d_t(); 162 163 graphene_point3d_cross(graphene_point3d, (b is null) ? null : b.getPoint3DStruct(), outres); 164 165 res = ObjectG.getDObject!(Point3D)(outres, true); 166 } 167 168 /** 169 * Computes the distance between the two given #graphene_point3d_t. 170 * 171 * Params: 172 * b = a #graphene_point3d_t 173 * delta = return location for the distance 174 * components on the X, Y, and Z axis 175 * 176 * Returns: the distance between two points 177 * 178 * Since: 1.4 179 */ 180 public float distance(Point3D b, out Vec3 delta) 181 { 182 graphene_vec3_t* outdelta = sliceNew!graphene_vec3_t(); 183 184 auto __p = graphene_point3d_distance(graphene_point3d, (b is null) ? null : b.getPoint3DStruct(), outdelta); 185 186 delta = ObjectG.getDObject!(Vec3)(outdelta, true); 187 188 return __p; 189 } 190 191 /** 192 * Computes the dot product of the two given #graphene_point3d_t. 193 * 194 * Params: 195 * b = a #graphene_point3d_t 196 * 197 * Returns: the value of the dot product 198 * 199 * Since: 1.0 200 */ 201 public float dot(Point3D b) 202 { 203 return graphene_point3d_dot(graphene_point3d, (b is null) ? null : b.getPoint3DStruct()); 204 } 205 206 /** 207 * Checks whether two given points are equal. 208 * 209 * Params: 210 * b = a #graphene_point3d_t 211 * 212 * Returns: `true` if the points are equal 213 * 214 * Since: 1.0 215 */ 216 public bool equal(Point3D b) 217 { 218 return graphene_point3d_equal(graphene_point3d, (b is null) ? null : b.getPoint3DStruct()) != 0; 219 } 220 221 /** 222 * Frees the resources allocated via graphene_point3d_alloc(). 223 * 224 * Since: 1.0 225 */ 226 public void free() 227 { 228 graphene_point3d_free(graphene_point3d); 229 ownedRef = false; 230 } 231 232 /** 233 * Initializes a #graphene_point3d_t with the given coordinates. 234 * 235 * Params: 236 * x = the X coordinate of the point 237 * y = the Y coordinate of the point 238 * z = the Z coordinate of the point 239 * 240 * Returns: the initialized #graphene_point3d_t 241 * 242 * Since: 1.0 243 */ 244 public Point3D init(float x, float y, float z) 245 { 246 auto __p = graphene_point3d_init(graphene_point3d, x, y, z); 247 248 if(__p is null) 249 { 250 return null; 251 } 252 253 return ObjectG.getDObject!(Point3D)(cast(graphene_point3d_t*) __p); 254 } 255 256 /** 257 * Initializes a #graphene_point3d_t using the coordinates of 258 * another #graphene_point3d_t. 259 * 260 * Params: 261 * src = a #graphene_point3d_t 262 * 263 * Returns: the initialized point 264 * 265 * Since: 1.0 266 */ 267 public Point3D initFromPoint(Point3D src) 268 { 269 auto __p = graphene_point3d_init_from_point(graphene_point3d, (src is null) ? null : src.getPoint3DStruct()); 270 271 if(__p is null) 272 { 273 return null; 274 } 275 276 return ObjectG.getDObject!(Point3D)(cast(graphene_point3d_t*) __p); 277 } 278 279 /** 280 * Initializes a #graphene_point3d_t using the components 281 * of a #graphene_vec3_t. 282 * 283 * Params: 284 * v = a #graphene_vec3_t 285 * 286 * Returns: the initialized #graphene_point3d_t 287 * 288 * Since: 1.0 289 */ 290 public Point3D initFromVec3(Vec3 v) 291 { 292 auto __p = graphene_point3d_init_from_vec3(graphene_point3d, (v is null) ? null : v.getVec3Struct()); 293 294 if(__p is null) 295 { 296 return null; 297 } 298 299 return ObjectG.getDObject!(Point3D)(cast(graphene_point3d_t*) __p); 300 } 301 302 /** 303 * Linearly interpolates each component of @a and @b using the 304 * provided @factor, and places the result in @res. 305 * 306 * Params: 307 * b = a #graphene_point3d_t 308 * factor = the interpolation factor 309 * res = the return location for the 310 * interpolated #graphene_point3d_t 311 * 312 * Since: 1.0 313 */ 314 public void interpolate(Point3D b, double factor, out Point3D res) 315 { 316 graphene_point3d_t* outres = sliceNew!graphene_point3d_t(); 317 318 graphene_point3d_interpolate(graphene_point3d, (b is null) ? null : b.getPoint3DStruct(), factor, outres); 319 320 res = ObjectG.getDObject!(Point3D)(outres, true); 321 } 322 323 /** 324 * Computes the length of the vector represented by the 325 * coordinates of the given #graphene_point3d_t. 326 * 327 * Returns: the length of the vector represented by the point 328 * 329 * Since: 1.0 330 */ 331 public float length() 332 { 333 return graphene_point3d_length(graphene_point3d); 334 } 335 336 /** 337 * Checks whether the two points are near each other, within 338 * an @epsilon factor. 339 * 340 * Params: 341 * b = a #graphene_point3d_t 342 * epsilon = fuzzyness factor 343 * 344 * Returns: `true` if the points are near each other 345 * 346 * Since: 1.0 347 */ 348 public bool near(Point3D b, float epsilon) 349 { 350 return graphene_point3d_near(graphene_point3d, (b is null) ? null : b.getPoint3DStruct(), epsilon) != 0; 351 } 352 353 /** 354 * Computes the normalization of the vector represented by the 355 * coordinates of the given #graphene_point3d_t. 356 * 357 * Params: 358 * res = return location for the normalized 359 * #graphene_point3d_t 360 * 361 * Since: 1.0 362 */ 363 public void normalize(out Point3D res) 364 { 365 graphene_point3d_t* outres = sliceNew!graphene_point3d_t(); 366 367 graphene_point3d_normalize(graphene_point3d, outres); 368 369 res = ObjectG.getDObject!(Point3D)(outres, true); 370 } 371 372 /** 373 * Normalizes the coordinates of a #graphene_point3d_t using the 374 * given viewport and clipping planes. 375 * 376 * The coordinates of the resulting #graphene_point3d_t will be 377 * in the [ -1, 1 ] range. 378 * 379 * Params: 380 * viewport = a #graphene_rect_t representing a viewport 381 * zNear = the coordinate of the near clipping plane, or 0 for 382 * the default near clipping plane 383 * zFar = the coordinate of the far clipping plane, or 1 for the 384 * default far clipping plane 385 * res = the return location for the 386 * normalized #graphene_point3d_t 387 * 388 * Since: 1.4 389 */ 390 public void normalizeViewport(Rect viewport, float zNear, float zFar, out Point3D res) 391 { 392 graphene_point3d_t* outres = sliceNew!graphene_point3d_t(); 393 394 graphene_point3d_normalize_viewport(graphene_point3d, (viewport is null) ? null : viewport.getRectStruct(), zNear, zFar, outres); 395 396 res = ObjectG.getDObject!(Point3D)(outres, true); 397 } 398 399 /** 400 * Scales the coordinates of the given #graphene_point3d_t by 401 * the given @factor. 402 * 403 * Params: 404 * factor = the scaling factor 405 * res = return location for the scaled point 406 * 407 * Since: 1.0 408 */ 409 public void scale(float factor, out Point3D res) 410 { 411 graphene_point3d_t* outres = sliceNew!graphene_point3d_t(); 412 413 graphene_point3d_scale(graphene_point3d, factor, outres); 414 415 res = ObjectG.getDObject!(Point3D)(outres, true); 416 } 417 418 /** 419 * Stores the coordinates of a #graphene_point3d_t into a 420 * #graphene_vec3_t. 421 * 422 * Params: 423 * v = return location for a #graphene_vec3_t 424 * 425 * Since: 1.0 426 */ 427 public void toVec3(out Vec3 v) 428 { 429 graphene_vec3_t* outv = sliceNew!graphene_vec3_t(); 430 431 graphene_point3d_to_vec3(graphene_point3d, outv); 432 433 v = ObjectG.getDObject!(Vec3)(outv, true); 434 } 435 436 /** 437 * Retrieves a constant point with all three coordinates set to 0. 438 * 439 * Returns: a zero point 440 * 441 * Since: 1.0 442 */ 443 public static Point3D zero() 444 { 445 auto __p = graphene_point3d_zero(); 446 447 if(__p is null) 448 { 449 return null; 450 } 451 452 return ObjectG.getDObject!(Point3D)(cast(graphene_point3d_t*) __p); 453 } 454 }