1 /**
2 
3 
4 Copyright:
5 Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur.  
6 Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md)  
7 Copyright (c) 2017-2018 Godot-D contributors  
8 
9 License: $(LINK2 https://opensource.org/licenses/MIT, MIT License)
10 
11 
12 */
13 module godot.geometry;
14 import std.meta : AliasSeq, staticIndexOf;
15 import std.traits : Unqual;
16 import godot.d.meta;
17 import godot.core;
18 import godot.c;
19 import godot.d.bind;
20 import godot.d.reference;
21 import godot.object;
22 /**
23 
24 */
25 @GodotBaseClass struct GeometrySingleton
26 {
27 	enum string _GODOT_internal_name = "_Geometry";
28 public:
29 @nogc nothrow:
30 	union { godot_object _godot_object; GodotObject _GODOT_base; }
31 	alias _GODOT_base this;
32 	alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses);
33 	package(godot) __gshared bool _classBindingInitialized = false;
34 	package(godot) static struct _classBinding
35 	{
36 		__gshared:
37 		godot_object _singleton;
38 		immutable char* _singletonName = "Geometry";
39 		@GodotName("build_box_planes") GodotMethod!(Array, Vector3) buildBoxPlanes;
40 		@GodotName("build_cylinder_planes") GodotMethod!(Array, double, double, long, long) buildCylinderPlanes;
41 		@GodotName("build_capsule_planes") GodotMethod!(Array, double, double, long, long, long) buildCapsulePlanes;
42 		@GodotName("segment_intersects_circle") GodotMethod!(double, Vector2, Vector2, Vector2, double) segmentIntersectsCircle;
43 		@GodotName("segment_intersects_segment_2d") GodotMethod!(Variant, Vector2, Vector2, Vector2, Vector2) segmentIntersectsSegment2d;
44 		@GodotName("line_intersects_line_2d") GodotMethod!(Variant, Vector2, Vector2, Vector2, Vector2) lineIntersectsLine2d;
45 		@GodotName("get_closest_points_between_segments_2d") GodotMethod!(PoolVector2Array, Vector2, Vector2, Vector2, Vector2) getClosestPointsBetweenSegments2d;
46 		@GodotName("get_closest_points_between_segments") GodotMethod!(PoolVector3Array, Vector3, Vector3, Vector3, Vector3) getClosestPointsBetweenSegments;
47 		@GodotName("get_closest_point_to_segment_2d") GodotMethod!(Vector2, Vector2, Vector2, Vector2) getClosestPointToSegment2d;
48 		@GodotName("get_closest_point_to_segment") GodotMethod!(Vector3, Vector3, Vector3, Vector3) getClosestPointToSegment;
49 		@GodotName("get_closest_point_to_segment_uncapped_2d") GodotMethod!(Vector2, Vector2, Vector2, Vector2) getClosestPointToSegmentUncapped2d;
50 		@GodotName("get_closest_point_to_segment_uncapped") GodotMethod!(Vector3, Vector3, Vector3, Vector3) getClosestPointToSegmentUncapped;
51 		@GodotName("get_uv84_normal_bit") GodotMethod!(long, Vector3) getUv84NormalBit;
52 		@GodotName("ray_intersects_triangle") GodotMethod!(Variant, Vector3, Vector3, Vector3, Vector3, Vector3) rayIntersectsTriangle;
53 		@GodotName("segment_intersects_triangle") GodotMethod!(Variant, Vector3, Vector3, Vector3, Vector3, Vector3) segmentIntersectsTriangle;
54 		@GodotName("segment_intersects_sphere") GodotMethod!(PoolVector3Array, Vector3, Vector3, Vector3, double) segmentIntersectsSphere;
55 		@GodotName("segment_intersects_cylinder") GodotMethod!(PoolVector3Array, Vector3, Vector3, double, double) segmentIntersectsCylinder;
56 		@GodotName("segment_intersects_convex") GodotMethod!(PoolVector3Array, Vector3, Vector3, Array) segmentIntersectsConvex;
57 		@GodotName("point_is_inside_triangle") GodotMethod!(bool, Vector2, Vector2, Vector2, Vector2) pointIsInsideTriangle;
58 		@GodotName("triangulate_polygon") GodotMethod!(PoolIntArray, PoolVector2Array) triangulatePolygon;
59 		@GodotName("convex_hull_2d") GodotMethod!(PoolVector2Array, PoolVector2Array) convexHull2d;
60 		@GodotName("clip_polygon") GodotMethod!(PoolVector3Array, PoolVector3Array, Plane) clipPolygon;
61 		@GodotName("make_atlas") GodotMethod!(Dictionary, PoolVector2Array) makeAtlas;
62 	}
63 	bool opEquals(in GeometrySingleton other) const { return _godot_object.ptr is other._godot_object.ptr; }
64 	GeometrySingleton opAssign(T : typeof(null))(T n) { _godot_object.ptr = null; }
65 	bool opEquals(typeof(null) n) const { return _godot_object.ptr is null; }
66 	mixin baseCasts;
67 	static GeometrySingleton _new()
68 	{
69 		static godot_class_constructor constructor;
70 		if(constructor is null) constructor = _godot_api.godot_get_class_constructor("_Geometry");
71 		if(constructor is null) return typeof(this).init;
72 		return cast(GeometrySingleton)(constructor());
73 	}
74 	@disable new(size_t s);
75 	/**
76 	Returns an array with 6 $(D Plane)s that describe the sides of a box centered at the origin. The box size is defined by `extents`, which represents one (positive) corner of the box (i.e. half its actual size).
77 	*/
78 	Array buildBoxPlanes(in Vector3 extents)
79 	{
80 		checkClassBinding!(typeof(this))();
81 		return ptrcall!(Array)(_classBinding.buildBoxPlanes, _godot_object, extents);
82 	}
83 	/**
84 	Returns an array of $(D Plane)s closely bounding a faceted cylinder centered at the origin with radius `radius` and height `height`. The parameter `sides` defines how many planes will be generated for the round part of the cylinder. The parameter `axis` describes the axis along which the cylinder is oriented (0 for X, 1 for Y, 2 for Z).
85 	*/
86 	Array buildCylinderPlanes(in double radius, in double height, in long sides, in long axis = 2)
87 	{
88 		checkClassBinding!(typeof(this))();
89 		return ptrcall!(Array)(_classBinding.buildCylinderPlanes, _godot_object, radius, height, sides, axis);
90 	}
91 	/**
92 	Returns an array of $(D Plane)s closely bounding a faceted capsule centered at the origin with radius `radius` and height `height`. The parameter `sides` defines how many planes will be generated for the side part of the capsule, whereas `lats` gives the number of latitudinal steps at the bottom and top of the capsule. The parameter `axis` describes the axis along which the capsule is oriented (0 for X, 1 for Y, 2 for Z).
93 	*/
94 	Array buildCapsulePlanes(in double radius, in double height, in long sides, in long lats, in long axis = 2)
95 	{
96 		checkClassBinding!(typeof(this))();
97 		return ptrcall!(Array)(_classBinding.buildCapsulePlanes, _godot_object, radius, height, sides, lats, axis);
98 	}
99 	/**
100 	Given the 2d segment (`segment_from`, `segment_to`), returns the position on the segment (as a number between 0 and 1) at which the segment hits the circle that is located at position `circle_position` and has radius `circle_radius`. If the segment does not intersect the circle, -1 is returned (this is also the case if the line extending the segment would intersect the circle, but the segment does not).
101 	*/
102 	double segmentIntersectsCircle(in Vector2 segment_from, in Vector2 segment_to, in Vector2 circle_position, in double circle_radius)
103 	{
104 		checkClassBinding!(typeof(this))();
105 		return ptrcall!(double)(_classBinding.segmentIntersectsCircle, _godot_object, segment_from, segment_to, circle_position, circle_radius);
106 	}
107 	/**
108 	Checks if the two segments (`from_a`, `to_a`) and (`from_b`, `to_b`) intersect. If yes, return the point of intersection as $(D Vector2). If no intersection takes place, returns an empty $(D Variant).
109 	*/
110 	Variant segmentIntersectsSegment2d(in Vector2 from_a, in Vector2 to_a, in Vector2 from_b, in Vector2 to_b)
111 	{
112 		checkClassBinding!(typeof(this))();
113 		return ptrcall!(Variant)(_classBinding.segmentIntersectsSegment2d, _godot_object, from_a, to_a, from_b, to_b);
114 	}
115 	/**
116 	Checks if the two lines (`from_a`, `dir_a`) and (`from_b`, `dir_b`) intersect. If yes, return the point of intersection as $(D Vector2). If no intersection takes place, returns an empty $(D Variant). Note that the lines are specified using direction vectors, not end points.
117 	*/
118 	Variant lineIntersectsLine2d(in Vector2 from_a, in Vector2 dir_a, in Vector2 from_b, in Vector2 dir_b)
119 	{
120 		checkClassBinding!(typeof(this))();
121 		return ptrcall!(Variant)(_classBinding.lineIntersectsLine2d, _godot_object, from_a, dir_a, from_b, dir_b);
122 	}
123 	/**
124 	Given the two 2d segments (`p1`, `p2`) and (`q1`, `q2`), finds those two points on the two segments that are closest to each other. Returns a $(D PoolVector2Array) that contains this point on (`p1`, `p2`) as well the accompanying point on (`q1`, `q2`).
125 	*/
126 	PoolVector2Array getClosestPointsBetweenSegments2d(in Vector2 p1, in Vector2 q1, in Vector2 p2, in Vector2 q2)
127 	{
128 		checkClassBinding!(typeof(this))();
129 		return ptrcall!(PoolVector2Array)(_classBinding.getClosestPointsBetweenSegments2d, _godot_object, p1, q1, p2, q2);
130 	}
131 	/**
132 	Given the two 3d segments (`p1`, `p2`) and (`q1`, `q2`), finds those two points on the two segments that are closest to each other. Returns a $(D PoolVector3Array) that contains this point on (`p1`, `p2`) as well the accompanying point on (`q1`, `q2`).
133 	*/
134 	PoolVector3Array getClosestPointsBetweenSegments(in Vector3 p1, in Vector3 p2, in Vector3 q1, in Vector3 q2)
135 	{
136 		checkClassBinding!(typeof(this))();
137 		return ptrcall!(PoolVector3Array)(_classBinding.getClosestPointsBetweenSegments, _godot_object, p1, p2, q1, q2);
138 	}
139 	/**
140 	Returns the 2d point on the 2d segment (`s1`, `s2`) that is closest to `point`. The returned point will always be inside the specified segment.
141 	*/
142 	Vector2 getClosestPointToSegment2d(in Vector2 point, in Vector2 s1, in Vector2 s2)
143 	{
144 		checkClassBinding!(typeof(this))();
145 		return ptrcall!(Vector2)(_classBinding.getClosestPointToSegment2d, _godot_object, point, s1, s2);
146 	}
147 	/**
148 	Returns the 3d point on the 3d segment (`s1`, `s2`) that is closest to `point`. The returned point will always be inside the specified segment.
149 	*/
150 	Vector3 getClosestPointToSegment(in Vector3 point, in Vector3 s1, in Vector3 s2)
151 	{
152 		checkClassBinding!(typeof(this))();
153 		return ptrcall!(Vector3)(_classBinding.getClosestPointToSegment, _godot_object, point, s1, s2);
154 	}
155 	/**
156 	Returns the 2d point on the 2d line defined by (`s1`, `s2`) that is closest to `point`. The returned point can be inside the segment (`s1`, `s2`) or outside of it, i.e. somewhere on the line extending from the segment.
157 	*/
158 	Vector2 getClosestPointToSegmentUncapped2d(in Vector2 point, in Vector2 s1, in Vector2 s2)
159 	{
160 		checkClassBinding!(typeof(this))();
161 		return ptrcall!(Vector2)(_classBinding.getClosestPointToSegmentUncapped2d, _godot_object, point, s1, s2);
162 	}
163 	/**
164 	Returns the 3d point on the 3d line defined by (`s1`, `s2`) that is closest to `point`. The returned point can be inside the segment (`s1`, `s2`) or outside of it, i.e. somewhere on the line extending from the segment.
165 	*/
166 	Vector3 getClosestPointToSegmentUncapped(in Vector3 point, in Vector3 s1, in Vector3 s2)
167 	{
168 		checkClassBinding!(typeof(this))();
169 		return ptrcall!(Vector3)(_classBinding.getClosestPointToSegmentUncapped, _godot_object, point, s1, s2);
170 	}
171 	/**
172 	
173 	*/
174 	long getUv84NormalBit(in Vector3 normal)
175 	{
176 		checkClassBinding!(typeof(this))();
177 		return ptrcall!(long)(_classBinding.getUv84NormalBit, _godot_object, normal);
178 	}
179 	/**
180 	Tests if the 3d ray starting at `from` with the direction of `dir` intersects the triangle specified by `a`, `b` and `c`. If yes, returns the point of intersection as $(D Vector3). If no intersection takes place, an empty $(D Variant) is returned.
181 	*/
182 	Variant rayIntersectsTriangle(in Vector3 from, in Vector3 dir, in Vector3 a, in Vector3 b, in Vector3 c)
183 	{
184 		checkClassBinding!(typeof(this))();
185 		return ptrcall!(Variant)(_classBinding.rayIntersectsTriangle, _godot_object, from, dir, a, b, c);
186 	}
187 	/**
188 	Tests if the segment (`from`, `to`) intersects the triangle `a`, `b`, `c`. If yes, returns the point of intersection as $(D Vector3). If no intersection takes place, an empty $(D Variant) is returned.
189 	*/
190 	Variant segmentIntersectsTriangle(in Vector3 from, in Vector3 to, in Vector3 a, in Vector3 b, in Vector3 c)
191 	{
192 		checkClassBinding!(typeof(this))();
193 		return ptrcall!(Variant)(_classBinding.segmentIntersectsTriangle, _godot_object, from, to, a, b, c);
194 	}
195 	/**
196 	Checks if the segment (`from`, `to`) intersects the sphere that is located at `sphere_position` and has radius `sphere_radius`. If no, returns an empty $(D PoolVector3Array). If yes, returns a $(D PoolVector3Array) containing the point of intersection and the sphere's normal at the point of intersection.
197 	*/
198 	PoolVector3Array segmentIntersectsSphere(in Vector3 from, in Vector3 to, in Vector3 sphere_position, in double sphere_radius)
199 	{
200 		checkClassBinding!(typeof(this))();
201 		return ptrcall!(PoolVector3Array)(_classBinding.segmentIntersectsSphere, _godot_object, from, to, sphere_position, sphere_radius);
202 	}
203 	/**
204 	Checks if the segment (`from`, `to`) intersects the cylinder with height `height` that is centered at the origin and has radius `radius`. If no, returns an empty $(D PoolVector3Array). If an intersection takes place, the returned array contains the point of intersection and the cylinder's normal at the point of intersection.
205 	*/
206 	PoolVector3Array segmentIntersectsCylinder(in Vector3 from, in Vector3 to, in double height, in double radius)
207 	{
208 		checkClassBinding!(typeof(this))();
209 		return ptrcall!(PoolVector3Array)(_classBinding.segmentIntersectsCylinder, _godot_object, from, to, height, radius);
210 	}
211 	/**
212 	Given a convex hull defined though the $(D Plane)s in the array `planes`, tests if the segment (`from`, `to`) intersects with that hull. If an intersection is found, returns a $(D PoolVector3Array) containing the point the intersection and the hull's normal. If no intersecion is found, an the returned array is empty.
213 	*/
214 	PoolVector3Array segmentIntersectsConvex(in Vector3 from, in Vector3 to, in Array planes)
215 	{
216 		checkClassBinding!(typeof(this))();
217 		return ptrcall!(PoolVector3Array)(_classBinding.segmentIntersectsConvex, _godot_object, from, to, planes);
218 	}
219 	/**
220 	Returns if `point` is inside the triangle specified by `a`, `b` and `c`.
221 	*/
222 	bool pointIsInsideTriangle(in Vector2 point, in Vector2 a, in Vector2 b, in Vector2 c) const
223 	{
224 		checkClassBinding!(typeof(this))();
225 		return ptrcall!(bool)(_classBinding.pointIsInsideTriangle, _godot_object, point, a, b, c);
226 	}
227 	/**
228 	Triangulates the polygon specified by the points in `polygon`. Returns a $(D PoolIntArray) where each triangle consists of three consecutive point indices into `polygon` (i.e. the returned array will have `n * 3` elements, with `n` being the number of found triangles). If the triangulation did not succeed, an empty $(D PoolIntArray) is returned.
229 	*/
230 	PoolIntArray triangulatePolygon(in PoolVector2Array polygon)
231 	{
232 		checkClassBinding!(typeof(this))();
233 		return ptrcall!(PoolIntArray)(_classBinding.triangulatePolygon, _godot_object, polygon);
234 	}
235 	/**
236 	Given an array of $(D Vector2)s, returns the convex hull as a list of points in counter-clockwise order. The last point is the same as the first one.
237 	*/
238 	PoolVector2Array convexHull2d(in PoolVector2Array points)
239 	{
240 		checkClassBinding!(typeof(this))();
241 		return ptrcall!(PoolVector2Array)(_classBinding.convexHull2d, _godot_object, points);
242 	}
243 	/**
244 	Clips the polygon defined by the points in `points` against the `plane` and returns the points of the clipped polygon.
245 	*/
246 	PoolVector3Array clipPolygon(in PoolVector3Array points, in Plane plane)
247 	{
248 		checkClassBinding!(typeof(this))();
249 		return ptrcall!(PoolVector3Array)(_classBinding.clipPolygon, _godot_object, points, plane);
250 	}
251 	/**
252 	Given an array of $(D Vector2)s representing tiles, builds an atlas. The returned dictionary has two keys: `points` is a vector of $(D Vector2) that specifies the positions of each tile, `size` contains the overall size of the whole atlas as $(D Vector2).
253 	*/
254 	Dictionary makeAtlas(in PoolVector2Array sizes)
255 	{
256 		checkClassBinding!(typeof(this))();
257 		return ptrcall!(Dictionary)(_classBinding.makeAtlas, _godot_object, sizes);
258 	}
259 }
260 /// Returns: the GeometrySingleton
261 @property @nogc nothrow pragma(inline, true)
262 GeometrySingleton Geometry()
263 {
264 	checkClassBinding!GeometrySingleton();
265 	return GeometrySingleton(GeometrySingleton._classBinding._singleton);
266 }