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.Triangle; 26 27 private import glib.ConstructionException; 28 private import glib.MemorySlice; 29 private import gobject.ObjectG; 30 private import graphene.Box; 31 private import graphene.Plane; 32 private import graphene.Point3D; 33 private import graphene.Vec2; 34 private import graphene.Vec3; 35 private import graphene.c.functions; 36 public import graphene.c.types; 37 private import gtkd.Loader; 38 39 40 /** 41 * A triangle. 42 * 43 * Since: 1.2 44 */ 45 public class Triangle 46 { 47 /** the main Gtk struct */ 48 protected graphene_triangle_t* graphene_triangle; 49 protected bool ownedRef; 50 51 /** Get the main Gtk struct */ 52 public graphene_triangle_t* getTriangleStruct(bool transferOwnership = false) 53 { 54 if (transferOwnership) 55 ownedRef = false; 56 return graphene_triangle; 57 } 58 59 /** the main Gtk struct as a void* */ 60 protected void* getStruct() 61 { 62 return cast(void*)graphene_triangle; 63 } 64 65 /** 66 * Sets our main struct and passes it to the parent class. 67 */ 68 public this (graphene_triangle_t* graphene_triangle, bool ownedRef = false) 69 { 70 this.graphene_triangle = graphene_triangle; 71 this.ownedRef = ownedRef; 72 } 73 74 ~this () 75 { 76 if ( Linker.isLoaded(LIBRARY_GRAPHENE) && ownedRef ) 77 graphene_triangle_free(graphene_triangle); 78 } 79 80 81 /** */ 82 public static GType getType() 83 { 84 return graphene_triangle_get_type(); 85 } 86 87 /** 88 * Allocates a new #graphene_triangle_t. 89 * 90 * The contents of the returned structure are undefined. 91 * 92 * Returns: the newly allocated #graphene_triangle_t 93 * structure. Use graphene_triangle_free() to free the resources 94 * allocated by this function 95 * 96 * Since: 1.2 97 * 98 * Throws: ConstructionException GTK+ fails to create the object. 99 */ 100 public this() 101 { 102 auto __p = graphene_triangle_alloc(); 103 104 if(__p is null) 105 { 106 throw new ConstructionException("null returned by alloc"); 107 } 108 109 this(cast(graphene_triangle_t*) __p); 110 } 111 112 /** 113 * Checks whether the given triangle @t contains the point @p. 114 * 115 * Params: 116 * p = a #graphene_point3d_t 117 * 118 * Returns: `true` if the point is inside the triangle 119 * 120 * Since: 1.2 121 */ 122 public bool containsPoint(Point3D p) 123 { 124 return graphene_triangle_contains_point(graphene_triangle, (p is null) ? null : p.getPoint3DStruct()) != 0; 125 } 126 127 /** 128 * Checks whether the two given #graphene_triangle_t are equal. 129 * 130 * Params: 131 * b = a #graphene_triangle_t 132 * 133 * Returns: `true` if the triangles are equal 134 * 135 * Since: 1.2 136 */ 137 public bool equal(Triangle b) 138 { 139 return graphene_triangle_equal(graphene_triangle, (b is null) ? null : b.getTriangleStruct()) != 0; 140 } 141 142 /** 143 * Frees the resources allocated by graphene_triangle_alloc(). 144 * 145 * Since: 1.2 146 */ 147 public void free() 148 { 149 graphene_triangle_free(graphene_triangle); 150 ownedRef = false; 151 } 152 153 /** 154 * Computes the area of the given #graphene_triangle_t. 155 * 156 * Returns: the area of the triangle 157 * 158 * Since: 1.2 159 */ 160 public float getArea() 161 { 162 return graphene_triangle_get_area(graphene_triangle); 163 } 164 165 /** 166 * Computes the [barycentric coordinates](http://en.wikipedia.org/wiki/Barycentric_coordinate_system) 167 * of the given point @p. 168 * 169 * The point @p must lie on the same plane as the triangle @t; if the 170 * point is not coplanar, the result of this function is undefined. 171 * 172 * If we place the origin in the coordinates of the triangle's A point, 173 * the barycentric coordinates are `u`, which is on the AC vector; and `v` 174 * which is on the AB vector: 175 * 176 * ![](triangle-barycentric.png) 177 * 178 * The returned #graphene_vec2_t contains the following values, in order: 179 * 180 * - `res.x = u` 181 * - `res.y = v` 182 * 183 * Params: 184 * p = a #graphene_point3d_t 185 * res = return location for the vector 186 * with the barycentric coordinates 187 * 188 * Returns: `true` if the barycentric coordinates are valid 189 * 190 * Since: 1.2 191 */ 192 public bool getBarycoords(Point3D p, out Vec2 res) 193 { 194 graphene_vec2_t* outres = sliceNew!graphene_vec2_t(); 195 196 auto __p = graphene_triangle_get_barycoords(graphene_triangle, (p is null) ? null : p.getPoint3DStruct(), outres) != 0; 197 198 res = ObjectG.getDObject!(Vec2)(outres, true); 199 200 return __p; 201 } 202 203 /** 204 * Computes the bounding box of the given #graphene_triangle_t. 205 * 206 * Params: 207 * res = return location for the box 208 * 209 * Since: 1.2 210 */ 211 public void getBoundingBox(out Box res) 212 { 213 graphene_box_t* outres = sliceNew!graphene_box_t(); 214 215 graphene_triangle_get_bounding_box(graphene_triangle, outres); 216 217 res = ObjectG.getDObject!(Box)(outres, true); 218 } 219 220 /** 221 * Computes the coordinates of the midpoint of the given #graphene_triangle_t. 222 * 223 * The midpoint G is the [centroid](https://en.wikipedia.org/wiki/Centroid#Triangle_centroid) 224 * of the triangle, i.e. the intersection of its medians. 225 * 226 * Params: 227 * res = return location for the coordinates of 228 * the midpoint 229 * 230 * Since: 1.2 231 */ 232 public void getMidpoint(out Point3D res) 233 { 234 graphene_point3d_t* outres = sliceNew!graphene_point3d_t(); 235 236 graphene_triangle_get_midpoint(graphene_triangle, outres); 237 238 res = ObjectG.getDObject!(Point3D)(outres, true); 239 } 240 241 /** 242 * Computes the normal vector of the given #graphene_triangle_t. 243 * 244 * Params: 245 * res = return location for the normal vector 246 * 247 * Since: 1.2 248 */ 249 public void getNormal(out Vec3 res) 250 { 251 graphene_vec3_t* outres = sliceNew!graphene_vec3_t(); 252 253 graphene_triangle_get_normal(graphene_triangle, outres); 254 255 res = ObjectG.getDObject!(Vec3)(outres, true); 256 } 257 258 /** 259 * Computes the plane based on the vertices of the given #graphene_triangle_t. 260 * 261 * Params: 262 * res = return location for the plane 263 * 264 * Since: 1.2 265 */ 266 public void getPlane(out Plane res) 267 { 268 graphene_plane_t* outres = sliceNew!graphene_plane_t(); 269 270 graphene_triangle_get_plane(graphene_triangle, outres); 271 272 res = ObjectG.getDObject!(Plane)(outres, true); 273 } 274 275 /** 276 * Retrieves the three vertices of the given #graphene_triangle_t and returns 277 * their coordinates as #graphene_point3d_t. 278 * 279 * Params: 280 * a = return location for the coordinates 281 * of the first vertex 282 * b = return location for the coordinates 283 * of the second vertex 284 * c = return location for the coordinates 285 * of the third vertex 286 * 287 * Since: 1.2 288 */ 289 public void getPoints(out Point3D a, out Point3D b, out Point3D c) 290 { 291 graphene_point3d_t* outa = sliceNew!graphene_point3d_t(); 292 graphene_point3d_t* outb = sliceNew!graphene_point3d_t(); 293 graphene_point3d_t* outc = sliceNew!graphene_point3d_t(); 294 295 graphene_triangle_get_points(graphene_triangle, outa, outb, outc); 296 297 a = ObjectG.getDObject!(Point3D)(outa, true); 298 b = ObjectG.getDObject!(Point3D)(outb, true); 299 c = ObjectG.getDObject!(Point3D)(outc, true); 300 } 301 302 /** 303 * Computes the UV coordinates of the given point @p. 304 * 305 * The point @p must lie on the same plane as the triangle @t; if the point 306 * is not coplanar, the result of this function is undefined. If @p is %NULL, 307 * the point will be set in (0, 0, 0). 308 * 309 * The UV coordinates will be placed in the @res vector: 310 * 311 * - `res.x = u` 312 * - `res.y = v` 313 * 314 * See also: graphene_triangle_get_barycoords() 315 * 316 * Params: 317 * p = a #graphene_point3d_t 318 * uvA = the UV coordinates of the first point 319 * uvB = the UV coordinates of the second point 320 * uvC = the UV coordinates of the third point 321 * res = a vector containing the UV coordinates 322 * of the given point @p 323 * 324 * Returns: `true` if the coordinates are valid 325 * 326 * Since: 1.10 327 */ 328 public bool getUv(Point3D p, Vec2 uvA, Vec2 uvB, Vec2 uvC, out Vec2 res) 329 { 330 graphene_vec2_t* outres = sliceNew!graphene_vec2_t(); 331 332 auto __p = graphene_triangle_get_uv(graphene_triangle, (p is null) ? null : p.getPoint3DStruct(), (uvA is null) ? null : uvA.getVec2Struct(), (uvB is null) ? null : uvB.getVec2Struct(), (uvC is null) ? null : uvC.getVec2Struct(), outres) != 0; 333 334 res = ObjectG.getDObject!(Vec2)(outres, true); 335 336 return __p; 337 } 338 339 /** 340 * Retrieves the three vertices of the given #graphene_triangle_t. 341 * 342 * Params: 343 * a = return location for the first vertex 344 * b = return location for the second vertex 345 * c = return location for the third vertex 346 * 347 * Since: 1.2 348 */ 349 public void getVertices(out Vec3 a, out Vec3 b, out Vec3 c) 350 { 351 graphene_vec3_t* outa = sliceNew!graphene_vec3_t(); 352 graphene_vec3_t* outb = sliceNew!graphene_vec3_t(); 353 graphene_vec3_t* outc = sliceNew!graphene_vec3_t(); 354 355 graphene_triangle_get_vertices(graphene_triangle, outa, outb, outc); 356 357 a = ObjectG.getDObject!(Vec3)(outa, true); 358 b = ObjectG.getDObject!(Vec3)(outb, true); 359 c = ObjectG.getDObject!(Vec3)(outc, true); 360 } 361 362 /** 363 * Initializes a #graphene_triangle_t using the three given arrays 364 * of floating point values, each representing the coordinates of 365 * a point in 3D space. 366 * 367 * Params: 368 * a = an array of 3 floating point values 369 * b = an array of 3 floating point values 370 * c = an array of 3 floating point values 371 * 372 * Returns: the initialized #graphene_triangle_t 373 * 374 * Since: 1.10 375 */ 376 public Triangle initFromFloat(float[3] a, float[3] b, float[3] c) 377 { 378 auto __p = graphene_triangle_init_from_float(graphene_triangle, a.ptr, b.ptr, c.ptr); 379 380 if(__p is null) 381 { 382 return null; 383 } 384 385 return ObjectG.getDObject!(Triangle)(cast(graphene_triangle_t*) __p); 386 } 387 388 /** 389 * Initializes a #graphene_triangle_t using the three given 3D points. 390 * 391 * Params: 392 * a = a #graphene_point3d_t 393 * b = a #graphene_point3d_t 394 * c = a #graphene_point3d_t 395 * 396 * Returns: the initialized #graphene_triangle_t 397 * 398 * Since: 1.2 399 */ 400 public Triangle initFromPoint3d(Point3D a, Point3D b, Point3D c) 401 { 402 auto __p = graphene_triangle_init_from_point3d(graphene_triangle, (a is null) ? null : a.getPoint3DStruct(), (b is null) ? null : b.getPoint3DStruct(), (c is null) ? null : c.getPoint3DStruct()); 403 404 if(__p is null) 405 { 406 return null; 407 } 408 409 return ObjectG.getDObject!(Triangle)(cast(graphene_triangle_t*) __p); 410 } 411 412 /** 413 * Initializes a #graphene_triangle_t using the three given vectors. 414 * 415 * Params: 416 * a = a #graphene_vec3_t 417 * b = a #graphene_vec3_t 418 * c = a #graphene_vec3_t 419 * 420 * Returns: the initialized #graphene_triangle_t 421 * 422 * Since: 1.2 423 */ 424 public Triangle initFromVec3(Vec3 a, Vec3 b, Vec3 c) 425 { 426 auto __p = graphene_triangle_init_from_vec3(graphene_triangle, (a is null) ? null : a.getVec3Struct(), (b is null) ? null : b.getVec3Struct(), (c is null) ? null : c.getVec3Struct()); 427 428 if(__p is null) 429 { 430 return null; 431 } 432 433 return ObjectG.getDObject!(Triangle)(cast(graphene_triangle_t*) __p); 434 } 435 }