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.Sphere; 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.Point3D; 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 sphere, represented by its center and radius. 40 * 41 * Since: 1.2 42 */ 43 public class Sphere 44 { 45 /** the main Gtk struct */ 46 protected graphene_sphere_t* graphene_sphere; 47 protected bool ownedRef; 48 49 /** Get the main Gtk struct */ 50 public graphene_sphere_t* getSphereStruct(bool transferOwnership = false) 51 { 52 if (transferOwnership) 53 ownedRef = false; 54 return graphene_sphere; 55 } 56 57 /** the main Gtk struct as a void* */ 58 protected void* getStruct() 59 { 60 return cast(void*)graphene_sphere; 61 } 62 63 /** 64 * Sets our main struct and passes it to the parent class. 65 */ 66 public this (graphene_sphere_t* graphene_sphere, bool ownedRef = false) 67 { 68 this.graphene_sphere = graphene_sphere; 69 this.ownedRef = ownedRef; 70 } 71 72 ~this () 73 { 74 if ( Linker.isLoaded(LIBRARY_GRAPHENE) && ownedRef ) 75 graphene_sphere_free(graphene_sphere); 76 } 77 78 79 /** */ 80 public static GType getType() 81 { 82 return graphene_sphere_get_type(); 83 } 84 85 /** 86 * Allocates a new #graphene_sphere_t. 87 * 88 * The contents of the newly allocated structure are undefined. 89 * 90 * Returns: the newly allocated #graphene_sphere_t. Use 91 * graphene_sphere_free() to free the resources allocated by this function 92 * 93 * Since: 1.2 94 * 95 * Throws: ConstructionException GTK+ fails to create the object. 96 */ 97 public this() 98 { 99 auto __p = graphene_sphere_alloc(); 100 101 if(__p is null) 102 { 103 throw new ConstructionException("null returned by alloc"); 104 } 105 106 this(cast(graphene_sphere_t*) __p); 107 } 108 109 /** 110 * Checks whether the given @point is contained in the volume 111 * of a #graphene_sphere_t. 112 * 113 * Params: 114 * point = a #graphene_point3d_t 115 * 116 * Returns: `true` if the sphere contains the point 117 * 118 * Since: 1.2 119 */ 120 public bool containsPoint(Point3D point) 121 { 122 return graphene_sphere_contains_point(graphene_sphere, (point is null) ? null : point.getPoint3DStruct()) != 0; 123 } 124 125 /** 126 * Computes the distance of the given @point from the surface of 127 * a #graphene_sphere_t. 128 * 129 * Params: 130 * point = a #graphene_point3d_t 131 * 132 * Returns: the distance of the point 133 * 134 * Since: 1.2 135 */ 136 public float distance(Point3D point) 137 { 138 return graphene_sphere_distance(graphene_sphere, (point is null) ? null : point.getPoint3DStruct()); 139 } 140 141 /** 142 * Checks whether two #graphene_sphere_t are equal. 143 * 144 * Params: 145 * b = a #graphene_sphere_t 146 * 147 * Returns: `true` if the spheres are equal 148 * 149 * Since: 1.2 150 */ 151 public bool equal(Sphere b) 152 { 153 return graphene_sphere_equal(graphene_sphere, (b is null) ? null : b.getSphereStruct()) != 0; 154 } 155 156 /** 157 * Frees the resources allocated by graphene_sphere_alloc(). 158 * 159 * Since: 1.2 160 */ 161 public void free() 162 { 163 graphene_sphere_free(graphene_sphere); 164 ownedRef = false; 165 } 166 167 /** 168 * Computes the bounding box capable of containing the 169 * given #graphene_sphere_t. 170 * 171 * Params: 172 * box = return location for the bounding box 173 * 174 * Since: 1.2 175 */ 176 public void getBoundingBox(out Box box) 177 { 178 graphene_box_t* outbox = sliceNew!graphene_box_t(); 179 180 graphene_sphere_get_bounding_box(graphene_sphere, outbox); 181 182 box = ObjectG.getDObject!(Box)(outbox, true); 183 } 184 185 /** 186 * Retrieves the coordinates of the center of a #graphene_sphere_t. 187 * 188 * Params: 189 * center = return location for the coordinates of 190 * the center 191 * 192 * Since: 1.2 193 */ 194 public void getCenter(out Point3D center) 195 { 196 graphene_point3d_t* outcenter = sliceNew!graphene_point3d_t(); 197 198 graphene_sphere_get_center(graphene_sphere, outcenter); 199 200 center = ObjectG.getDObject!(Point3D)(outcenter, true); 201 } 202 203 /** 204 * Retrieves the radius of a #graphene_sphere_t. 205 * 206 * Since: 1.2 207 */ 208 public float getRadius() 209 { 210 return graphene_sphere_get_radius(graphene_sphere); 211 } 212 213 /** 214 * Initializes the given #graphene_sphere_t with the given @center and @radius. 215 * 216 * Params: 217 * center = the coordinates of the center of the sphere, or %NULL 218 * for a center in (0, 0, 0) 219 * radius = the radius of the sphere 220 * 221 * Returns: the initialized #graphene_sphere_t 222 * 223 * Since: 1.2 224 */ 225 public Sphere init(Point3D center, float radius) 226 { 227 auto __p = graphene_sphere_init(graphene_sphere, (center is null) ? null : center.getPoint3DStruct(), radius); 228 229 if(__p is null) 230 { 231 return null; 232 } 233 234 return ObjectG.getDObject!(Sphere)(cast(graphene_sphere_t*) __p); 235 } 236 237 /** 238 * Initializes the given #graphene_sphere_t using the given array 239 * of 3D coordinates so that the sphere includes them. 240 * 241 * The center of the sphere can either be specified, or will be center 242 * of the 3D volume that encompasses all @points. 243 * 244 * Params: 245 * points = an array of #graphene_point3d_t 246 * center = the center of the sphere 247 * 248 * Returns: the initialized #graphene_sphere_t 249 * 250 * Since: 1.2 251 */ 252 public Sphere initFromPoints(Point3D[] points, Point3D center) 253 { 254 graphene_point3d_t[] pointsArray = new graphene_point3d_t[points.length]; 255 for ( int i = 0; i < points.length; i++ ) 256 { 257 pointsArray[i] = *(points[i].getPoint3DStruct()); 258 } 259 260 auto __p = graphene_sphere_init_from_points(graphene_sphere, cast(uint)points.length, pointsArray.ptr, (center is null) ? null : center.getPoint3DStruct()); 261 262 if(__p is null) 263 { 264 return null; 265 } 266 267 return ObjectG.getDObject!(Sphere)(cast(graphene_sphere_t*) __p); 268 } 269 270 /** 271 * Initializes the given #graphene_sphere_t using the given array 272 * of 3D coordinates so that the sphere includes them. 273 * 274 * The center of the sphere can either be specified, or will be center 275 * of the 3D volume that encompasses all @vectors. 276 * 277 * Params: 278 * vectors = an array of #graphene_vec3_t 279 * center = the center of the sphere 280 * 281 * Returns: the initialized #graphene_sphere_t 282 * 283 * Since: 1.2 284 */ 285 public Sphere initFromVectors(Vec3[] vectors, Point3D center) 286 { 287 graphene_vec3_t[] vectorsArray = new graphene_vec3_t[vectors.length]; 288 for ( int i = 0; i < vectors.length; i++ ) 289 { 290 vectorsArray[i] = *(vectors[i].getVec3Struct()); 291 } 292 293 auto __p = graphene_sphere_init_from_vectors(graphene_sphere, cast(uint)vectors.length, vectorsArray.ptr, (center is null) ? null : center.getPoint3DStruct()); 294 295 if(__p is null) 296 { 297 return null; 298 } 299 300 return ObjectG.getDObject!(Sphere)(cast(graphene_sphere_t*) __p); 301 } 302 303 /** 304 * Checks whether the sphere has a zero radius. 305 * 306 * Returns: `true` if the sphere is empty 307 * 308 * Since: 1.2 309 */ 310 public bool isEmpty() 311 { 312 return graphene_sphere_is_empty(graphene_sphere) != 0; 313 } 314 315 /** 316 * Translates the center of the given #graphene_sphere_t using the @point 317 * coordinates as the delta of the translation. 318 * 319 * Params: 320 * point = the coordinates of the translation 321 * res = return location for the translated sphere 322 * 323 * Since: 1.2 324 */ 325 public void translate(Point3D point, out Sphere res) 326 { 327 graphene_sphere_t* outres = sliceNew!graphene_sphere_t(); 328 329 graphene_sphere_translate(graphene_sphere, (point is null) ? null : point.getPoint3DStruct(), outres); 330 331 res = ObjectG.getDObject!(Sphere)(outres, true); 332 } 333 }