|
1
|
|
|
<?php |
|
2
|
|
|
/** @formatter:off |
|
3
|
|
|
* ****************************************************************** |
|
4
|
|
|
* Created by Marko Kungla on Jun 21, 2016 - 12:20:44 AM |
|
5
|
|
|
* Contact [email protected] |
|
6
|
|
|
* @copyright 2016 Marko Kungla - https://github.com/mkungla |
|
7
|
|
|
* @license The MIT License (MIT) |
|
8
|
|
|
* |
|
9
|
|
|
* @category AframeVR |
|
10
|
|
|
* @package aframe-php |
|
11
|
|
|
* |
|
12
|
|
|
* Lang PHP (php version >= 7) |
|
13
|
|
|
* Encoding UTF-8 |
|
14
|
|
|
* File Geometry.php |
|
15
|
|
|
* Code format PSR-2 and 12 |
|
16
|
|
|
* @link https://github.com/mkungla/aframe-php |
|
17
|
|
|
^ @issues https://github.com/mkungla/aframe-php/issues |
|
18
|
|
|
* ******************************************************************** |
|
19
|
|
|
* Contributors: |
|
20
|
|
|
* @author Marko Kungla <[email protected]> |
|
21
|
|
|
* ******************************************************************** |
|
22
|
|
|
* Comments: |
|
23
|
|
|
* @formatter:on */ |
|
24
|
|
|
namespace AframeVR\Components; |
|
25
|
|
|
|
|
26
|
|
|
use \AframeVR\Interfaces\ComponentInterface; |
|
27
|
|
|
use \AframeVR\Core\Exceptions\{ |
|
28
|
|
|
InvalidComponentArgumentException, |
|
29
|
|
|
InvalidComponentMethodException |
|
30
|
|
|
}; |
|
31
|
|
|
use \DOMAttr; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* The geometry component provides a basic shape for an entity. |
|
35
|
|
|
* The general geometry is defined by the primitive property. |
|
36
|
|
|
* Geometric primitives, in computer graphics, means an extremely basic shape. With the primitive defined, |
|
37
|
|
|
* additional properties are used to further define the geometry. A material component is usually defined alongside |
|
38
|
|
|
* to provide a appearance alongside the shape to create a complete mesh. |
|
39
|
|
|
*/ |
|
40
|
|
|
class Geometry implements ComponentInterface |
|
41
|
|
|
{ |
|
42
|
|
|
|
|
43
|
|
|
const ALLOWED_PRIMITIVES = array( |
|
44
|
|
|
'box', |
|
45
|
|
|
'circle', |
|
46
|
|
|
'cone', |
|
47
|
|
|
'cylinder', |
|
48
|
|
|
'plane', |
|
49
|
|
|
'ring', |
|
50
|
|
|
'sphere', |
|
51
|
|
|
'torus', |
|
52
|
|
|
'torusKnot' |
|
53
|
|
|
); |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Properties based on primitive |
|
57
|
|
|
*/ |
|
58
|
|
|
const P_COMMON_PROPS = array( |
|
59
|
|
|
|
|
60
|
|
|
/* One of box, circle, cone, cylinder, plane, ring, sphere, torus, torusKnot. */ |
|
61
|
|
|
'primitive' => null, |
|
62
|
|
|
|
|
63
|
|
|
/* The translate property translates the geometry. It is provided as a vec3. This is a useful short-hand for |
|
64
|
|
|
* translating the geometry to effectively move its pivot point when running animations. */ |
|
65
|
|
|
'translate' => '0 1 0' |
|
66
|
|
|
); |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* The box primitive defines boxes (i.e., any quadilateral, not just cubes). |
|
70
|
|
|
*/ |
|
71
|
|
|
const P_BOX = array( |
|
72
|
|
|
/* Width (in meters) of the sides on the X axis. */ |
|
73
|
|
|
'width' => 1, |
|
74
|
|
|
/* Height (in meters) of the sides on the Y axis. */ |
|
75
|
|
|
'height' => 1, |
|
76
|
|
|
/* Depth (in meters) of the sides on the Z axis. */ |
|
77
|
|
|
'depth' => 1 |
|
78
|
|
|
); |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* The circle primitive defines two-dimensional circles, which can be complete circles or partial circles (like Pac-Man). |
|
82
|
|
|
* Note that because it is flat, only a single side of the circle will be rendered if “side: double” is not specified on the material component. |
|
83
|
|
|
*/ |
|
84
|
|
|
const P_CIRCLE = array( |
|
85
|
|
|
/* Radius (in meters) of the circle. */ |
|
86
|
|
|
'radius' => 1, |
|
87
|
|
|
/* Number of triangles to construct the circle, like pizza slices. A higher number of segments means the circle will be more round. */ |
|
88
|
|
|
'segments' => 32, |
|
89
|
|
|
/* Start angle for first segment. Can be used to define a partial circle. */ |
|
90
|
|
|
'thetaStart' => 0, |
|
91
|
|
|
/* The central angle (in degrees). Defaults to 360, which makes for a complete circle. */ |
|
92
|
|
|
'thetaLength' => 360 |
|
93
|
|
|
); |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* The cone primitive under the hood is a cylinder primitive with varying top and bottom radiuses. |
|
97
|
|
|
*/ |
|
98
|
|
|
const P_CONE = array( |
|
99
|
|
|
/* Height of the cone. */ |
|
100
|
|
|
'height' => 2, |
|
101
|
|
|
/* Whether the ends of the cone are open (true) or capped ('false'). */ |
|
102
|
|
|
'openEnded' => 'false', |
|
103
|
|
|
/* Radius of the bottom end of the cone. */ |
|
104
|
|
|
'radiusBottom' => 1, |
|
105
|
|
|
/* Radius of the top end of the cone. */ |
|
106
|
|
|
'radiusTop' => 1, |
|
107
|
|
|
/* Number of segmented faces around the circumference of the cone. */ |
|
108
|
|
|
'segmentsRadial' => 36, |
|
109
|
|
|
/* Number of rows of faces along the height of the cone. */ |
|
110
|
|
|
'segmentsHeight' => 18, |
|
111
|
|
|
/* Starting angle in degrees. */ |
|
112
|
|
|
'thetaStart' => 0, |
|
113
|
|
|
/* Central angle in degrees. */ |
|
114
|
|
|
'thetaLength' => 360 |
|
115
|
|
|
); |
|
116
|
|
|
|
|
117
|
|
|
/** |
|
118
|
|
|
* The cylinder primitive can define cylinders in the traditional sense like a Coca-Cola™ can, |
|
119
|
|
|
* but it can also define shapes such as tubes and curved surfaces. |
|
120
|
|
|
* We’ll go over some of these cylinder recipes below. |
|
121
|
|
|
* 1. Traditional cylinders can be defined by using only a height and a radius: |
|
122
|
|
|
* 2. Tubes can be defined by making the cylinder open-ended, which removes the top and bottom surfaces of the cylinder such that the inside is visible. |
|
123
|
|
|
* A double-sided material will be needed to render properly: |
|
124
|
|
|
* 3. Curved surfaces can be defined by specifying the angle via thetaLength such that the cylinder doesn’t curve all the way around, |
|
125
|
|
|
* making the cylinder open-ended, and then making the material double-sided. |
|
126
|
|
|
* 4. Other types of prisms can be defined by varying the number of radial segments (i.e., sides). For example, to make a hexagonal prism: |
|
127
|
|
|
*/ |
|
128
|
|
|
const P_CYLINDER = array( |
|
129
|
|
|
/* Radius of the cylinder. */ |
|
130
|
|
|
'height' => 3, |
|
131
|
|
|
/* Height of the cylinder. */ |
|
132
|
|
|
'radius' => 2, |
|
133
|
|
|
/* Number of segmented faces around the circumference of the cylinder. */ |
|
134
|
|
|
'segmentsRadial' => 36, |
|
135
|
|
|
/* Number of rows of faces along the height of the cylinder. */ |
|
136
|
|
|
'segmentsHeight' => 18, |
|
137
|
|
|
/* Whether the ends of the cylinder are open (true) or capped ('false'). */ |
|
138
|
|
|
'openEnded' => 'false', |
|
139
|
|
|
/* Starting angle in degrees. */ |
|
140
|
|
|
'thetaStart' => 0, |
|
141
|
|
|
/* Central angle in degrees. */ |
|
142
|
|
|
'thetaLength' => 360 |
|
143
|
|
|
); |
|
144
|
|
|
|
|
145
|
|
|
/** |
|
146
|
|
|
* The plane primitive defines a flat surface. |
|
147
|
|
|
* Note that because it is flat, |
|
148
|
|
|
* only a single side of the plane will be rendered if side: double is not specified on the material component. |
|
149
|
|
|
*/ |
|
150
|
|
|
const P_PLANE = array( |
|
151
|
|
|
/* Width along the X axis. */ |
|
152
|
|
|
'width' => 1, |
|
153
|
|
|
/* Height along the Y axis. */ |
|
154
|
|
|
'height' => 1 |
|
155
|
|
|
); |
|
156
|
|
|
|
|
157
|
|
|
/** |
|
158
|
|
|
* The ring geometry defines a flat ring, like a CD. |
|
159
|
|
|
* Note that because it is flat, |
|
160
|
|
|
* only a single side of the ring will be rendered if side: double is not specified on the material component. |
|
161
|
|
|
*/ |
|
162
|
|
|
const P_RING = array( |
|
163
|
|
|
/* Radius of the inner hole of the ring. */ |
|
164
|
|
|
'radiusInner' => 1, |
|
165
|
|
|
/* Radius of the outer edge of the ring. */ |
|
166
|
|
|
'radiusOuter' => 1, |
|
167
|
|
|
/* Number of segments. A higher number means the ring will be more round */ |
|
168
|
|
|
'segmentsTheta' => 32, |
|
169
|
|
|
/* Number of triangles within each face defined by segmentsTheta. */ |
|
170
|
|
|
'segmentsPhi' => 8, |
|
171
|
|
|
/* Starting angle in degrees. */ |
|
172
|
|
|
'thetaStart' => 0, |
|
173
|
|
|
/* Central angle in degrees. */ |
|
174
|
|
|
'thetaLength' => 360 |
|
175
|
|
|
); |
|
176
|
|
|
|
|
177
|
|
|
/** |
|
178
|
|
|
* The sphere primitive can define spheres in the traditional sense like a basketball. |
|
179
|
|
|
* |
|
180
|
|
|
* But it can also define various polyhedrons and abstract shapes given that it can specify |
|
181
|
|
|
* the number of horizontal and vertical angles and faces. |
|
182
|
|
|
* |
|
183
|
|
|
* Sticking with a basic sphere, the default number of segments is high enough to make the sphere appear round. |
|
184
|
|
|
*/ |
|
185
|
|
|
const P_SPHERE = array( |
|
186
|
|
|
/* Radius of the sphere. */ |
|
187
|
|
|
'radius' => 1, |
|
188
|
|
|
/* Number of horizontal segments. */ |
|
189
|
|
|
'segmentsWidth' => 18, |
|
190
|
|
|
/* Number of vertical segments. */ |
|
191
|
|
|
'segmentsHeight' => 36, |
|
192
|
|
|
/* Horizontal starting angle. */ |
|
193
|
|
|
'phiStart' => 0, |
|
194
|
|
|
/* Horizontal sweep angle size. */ |
|
195
|
|
|
'phiLength' => 360, |
|
196
|
|
|
/* Vertical starting angle. */ |
|
197
|
|
|
'thetaStart' => 0, |
|
198
|
|
|
/* Vertical sweep angle size. */ |
|
199
|
|
|
'thetaLength' => 360 |
|
200
|
|
|
); |
|
201
|
|
|
|
|
202
|
|
|
/** |
|
203
|
|
|
* The torus primitive defines a donut shape. |
|
204
|
|
|
*/ |
|
205
|
|
|
const P_TORUS = array( |
|
206
|
|
|
/* Radius of the outer edge of the torus. */ |
|
207
|
|
|
'radius' => 1, |
|
208
|
|
|
/* Radius of the tube. */ |
|
209
|
|
|
'radiusTubular' => 0.2, |
|
210
|
|
|
/* Number of segments along the circumference of the tube ends. A higher number means the tube will be more round. */ |
|
211
|
|
|
'segmentsRadial' => 36, |
|
212
|
|
|
/* Number of segments along the circumference of the tube face. A higher number means the tube will be more round. */ |
|
213
|
|
|
'segmentsTubular' => 32, |
|
214
|
|
|
/* Central angle. */ |
|
215
|
|
|
'arc' => 360 |
|
216
|
|
|
); |
|
217
|
|
|
|
|
218
|
|
|
/** |
|
219
|
|
|
* The torus knot primitive defines a pretzel shape, the particular shape of which is defined by a pair of coprime integers, |
|
220
|
|
|
* p and q. |
|
221
|
|
|
* If p and q are not coprime the result will be a torus link. |
|
222
|
|
|
*/ |
|
223
|
|
|
const P_TORUS_KNOT = array( |
|
224
|
|
|
/* Radius that contains the torus knot. */ |
|
225
|
|
|
'radius' => 1, |
|
226
|
|
|
/* Radius of the tubes of the torus knot. */ |
|
227
|
|
|
'radiusTubular' => 0.2, |
|
228
|
|
|
/* Number of segments along the circumference of the tube ends. A higher number means the tube will be more round. */ |
|
229
|
|
|
'segmentsRadial' => 36, |
|
230
|
|
|
/* Number of segments along the circumference of the tube face. A higher number means the tube will be more round. */ |
|
231
|
|
|
'segmentsTubular' => 32, |
|
232
|
|
|
/* Number that helps define the pretzel shape. */ |
|
233
|
|
|
'p' => 2, |
|
234
|
|
|
/* Number that helps define the pretzel shape. */ |
|
235
|
|
|
'q' => 3 |
|
236
|
|
|
); |
|
237
|
|
|
|
|
238
|
|
|
/* DOM atrributes */ |
|
239
|
|
|
protected $primitive; |
|
240
|
|
|
|
|
241
|
|
|
protected $width; |
|
242
|
|
|
|
|
243
|
|
|
protected $height; |
|
244
|
|
|
|
|
245
|
|
|
protected $depth; |
|
246
|
|
|
|
|
247
|
|
|
protected $radius; |
|
248
|
|
|
|
|
249
|
|
|
protected $radiusTubular; |
|
250
|
|
|
|
|
251
|
|
|
protected $radiusBottom; |
|
252
|
|
|
|
|
253
|
|
|
protected $radiusTop; |
|
254
|
|
|
|
|
255
|
|
|
protected $segments; |
|
256
|
|
|
|
|
257
|
|
|
protected $thetaStart; |
|
258
|
|
|
|
|
259
|
|
|
protected $thetaLength; |
|
260
|
|
|
|
|
261
|
|
|
protected $openEnded; |
|
262
|
|
|
|
|
263
|
|
|
protected $segmentsRadial; |
|
264
|
|
|
|
|
265
|
|
|
protected $segmentsHeight; |
|
266
|
|
|
|
|
267
|
|
|
protected $segmentsWidth; |
|
268
|
|
|
|
|
269
|
|
|
protected $segmentsTheta; |
|
270
|
|
|
|
|
271
|
|
|
protected $segmentsPhi; |
|
272
|
|
|
|
|
273
|
|
|
protected $segmentsTubular; |
|
274
|
|
|
|
|
275
|
|
|
protected $phiStart; |
|
276
|
|
|
|
|
277
|
|
|
protected $phiLength; |
|
278
|
|
|
|
|
279
|
|
|
protected $radiusInner; |
|
280
|
|
|
|
|
281
|
|
|
protected $radiusOuter; |
|
282
|
|
|
|
|
283
|
|
|
protected $arc; |
|
284
|
|
|
|
|
285
|
|
|
protected $p; |
|
286
|
|
|
|
|
287
|
|
|
protected $q; |
|
288
|
|
|
|
|
289
|
|
|
protected $translate; |
|
290
|
|
|
|
|
291
|
|
|
/** |
|
292
|
|
|
* Get Component scripts |
|
293
|
|
|
* |
|
294
|
|
|
* {@inheritdoc} |
|
295
|
|
|
* |
|
296
|
|
|
* @return array |
|
297
|
|
|
*/ |
|
298
|
|
|
public function getScripts(): array |
|
299
|
|
|
{ |
|
300
|
|
|
return array(); |
|
301
|
|
|
} |
|
302
|
|
|
|
|
303
|
|
|
/** |
|
304
|
|
|
* Does component have DOM Atributes |
|
305
|
|
|
* |
|
306
|
|
|
* {@inheritdoc} |
|
307
|
|
|
* |
|
308
|
|
|
* @return bool |
|
309
|
|
|
*/ |
|
310
|
|
|
public function hasDOMAttributes(): bool |
|
311
|
|
|
{ |
|
312
|
|
|
return ! empty(get_object_vars($this)); |
|
313
|
|
|
} |
|
314
|
|
|
|
|
315
|
|
|
/** |
|
316
|
|
|
* Remove default DOMElement Attributes which are not required |
|
317
|
|
|
* |
|
318
|
|
|
* @return void |
|
319
|
|
|
*/ |
|
320
|
|
|
public function removeDefaultDOMAttributes() |
|
321
|
|
|
{ |
|
322
|
|
|
$defaults = $this->primitiveDefaults(); |
|
323
|
|
|
foreach (get_object_vars($this) as $name => $value) { |
|
324
|
|
|
if (empty($value) || (array_key_exists($name, self::P_COMMON_PROPS) && $value === self::P_COMMON_PROPS[$name]) || (array_key_exists($name, $defaults) && $value === $defaults[$name])) |
|
325
|
|
|
unset($this->$name); |
|
326
|
|
|
} |
|
327
|
|
|
} |
|
328
|
|
|
|
|
329
|
|
|
/** |
|
330
|
|
|
* Get DOMAttr for the entity |
|
331
|
|
|
* |
|
332
|
|
|
* @return DOMAttr |
|
333
|
|
|
*/ |
|
334
|
|
|
public function getDOMAttributes(): DOMAttr |
|
335
|
|
|
{ |
|
336
|
|
|
$format = implode(': %s; ', array_keys(get_object_vars($this))) . ': %s;'; |
|
337
|
|
|
return new DOMAttr('geometry', vsprintf($format, array_values(get_object_vars($this)))); |
|
338
|
|
|
} |
|
339
|
|
|
|
|
340
|
|
|
/** |
|
341
|
|
|
* Set primitive |
|
342
|
|
|
* |
|
343
|
|
|
* One of box, circle, cone, cylinder, plane, ring, sphere, torus, torusKnot. |
|
344
|
|
|
* |
|
345
|
|
|
* @param unknown $primitive |
|
|
|
|
|
|
346
|
|
|
* @throws InvalidComponentArgumentException |
|
347
|
|
|
*/ |
|
348
|
8 |
|
public function primitive($primitive = null) |
|
349
|
|
|
{ |
|
350
|
|
|
try { |
|
351
|
8 |
|
if (in_array($primitive, self::ALLOWED_PRIMITIVES)) { |
|
352
|
|
|
/* If primitive is changed we reset the object and releoad allowed attributes */ |
|
353
|
8 |
|
$this->primitive = $primitive; |
|
354
|
8 |
|
$defaults = $this->primitiveDefaults(); |
|
355
|
8 |
|
foreach (get_class_vars(get_class($this)) as $name => $default) { |
|
356
|
8 |
|
if ($name === 'primitive') |
|
357
|
8 |
|
continue; |
|
358
|
|
|
|
|
359
|
8 |
|
if (array_key_exists($name, $defaults)) |
|
360
|
8 |
|
$this->$name = $defaults[$name]; |
|
361
|
8 |
|
elseif (array_key_exists($name, self::P_COMMON_PROPS)) |
|
362
|
8 |
|
$this->$name = self::P_COMMON_PROPS[$name]; |
|
363
|
|
|
else |
|
364
|
8 |
|
unset($this->$name); |
|
365
|
|
|
} |
|
366
|
|
|
} else { |
|
367
|
8 |
|
throw new InvalidComponentArgumentException($primitive, 'Geometry::primitive'); |
|
|
|
|
|
|
368
|
|
|
} |
|
369
|
|
|
} catch (InvalidComponentArgumentException $e) { |
|
370
|
|
|
die($e->getMessage()); |
|
371
|
|
|
} |
|
372
|
8 |
|
} |
|
373
|
|
|
|
|
374
|
|
|
/** |
|
375
|
|
|
* Set Buffer |
|
376
|
|
|
* |
|
377
|
|
|
* Transform geometry into a BufferGeometry to reduce memory usage at the cost of being harder to manipulate. |
|
378
|
|
|
* |
|
379
|
|
|
* @param string $buffer |
|
380
|
|
|
*/ |
|
381
|
|
|
public function buffer($buffer = 'true') |
|
382
|
|
|
{ |
|
383
|
|
|
$this->buffer = $buffer; |
|
|
|
|
|
|
384
|
|
|
} |
|
385
|
|
|
|
|
386
|
|
|
/** |
|
387
|
|
|
* skipCache |
|
388
|
|
|
* |
|
389
|
|
|
* Disable retrieving the shared geometry object from the cache. |
|
390
|
|
|
* |
|
391
|
|
|
* @param string $skipCache |
|
392
|
|
|
*/ |
|
393
|
|
|
public function skipCache($skipCache = 'false') |
|
394
|
|
|
{ |
|
395
|
|
|
$this->skipCache = $skipCache; |
|
|
|
|
|
|
396
|
|
|
} |
|
397
|
|
|
|
|
398
|
4 |
|
public function width($width) |
|
399
|
|
|
{ |
|
400
|
4 |
|
$this->width = $width; |
|
401
|
4 |
|
} |
|
402
|
|
|
|
|
403
|
8 |
|
public function height($height) |
|
404
|
|
|
{ |
|
405
|
8 |
|
$this->height = $height; |
|
406
|
8 |
|
} |
|
407
|
|
|
|
|
408
|
4 |
|
public function depth($depth) |
|
409
|
|
|
{ |
|
410
|
4 |
|
$this->depth = $depth; |
|
411
|
4 |
|
} |
|
412
|
|
|
|
|
413
|
4 |
|
public function radius($radius) |
|
414
|
|
|
{ |
|
415
|
4 |
|
$this->radius = $radius; |
|
416
|
4 |
|
} |
|
417
|
|
|
|
|
418
|
|
|
public function radiusTubular($radiusTubular) |
|
419
|
|
|
{ |
|
420
|
|
|
$this->radiusTubular = $radiusTubular; |
|
421
|
|
|
} |
|
422
|
|
|
|
|
423
|
|
|
public function radiusBottom($radiusBottom) |
|
424
|
|
|
{ |
|
425
|
|
|
$this->radiusBottom = $radiusBottom; |
|
426
|
|
|
} |
|
427
|
|
|
|
|
428
|
|
|
public function radiusTop($radiusTop) |
|
429
|
|
|
{ |
|
430
|
|
|
$this->radiusTop = $radiusTop; |
|
431
|
|
|
} |
|
432
|
|
|
|
|
433
|
|
|
public function segments($segments) |
|
434
|
|
|
{ |
|
435
|
|
|
$this->segments = $segments; |
|
436
|
|
|
} |
|
437
|
|
|
|
|
438
|
4 |
|
public function thetaStart($thetaStart) |
|
439
|
|
|
{ |
|
440
|
4 |
|
$this->thetaStart = $thetaStart; |
|
441
|
4 |
|
} |
|
442
|
|
|
|
|
443
|
4 |
|
public function thetaLength($thetaLength) |
|
444
|
|
|
{ |
|
445
|
4 |
|
$this->thetaLength = $thetaLength; |
|
446
|
4 |
|
} |
|
447
|
|
|
|
|
448
|
4 |
|
public function openEnded($openEnded) |
|
449
|
|
|
{ |
|
450
|
4 |
|
$this->openEnded = $openEnded; |
|
451
|
4 |
|
} |
|
452
|
|
|
|
|
453
|
|
|
public function segmentsRadial($segmentsRadial) |
|
454
|
|
|
{ |
|
455
|
|
|
$this->segmentsRadial = $segmentsRadial; |
|
456
|
|
|
} |
|
457
|
|
|
|
|
458
|
4 |
|
public function segmentsHeight($segmentsHeight) |
|
459
|
|
|
{ |
|
460
|
4 |
|
$this->segmentsHeight = $segmentsHeight; |
|
461
|
4 |
|
} |
|
462
|
|
|
|
|
463
|
|
|
public function segmentsWidth($segmentsWidth) |
|
464
|
|
|
{ |
|
465
|
|
|
$this->segmentsWidth = $segmentsWidth; |
|
466
|
|
|
} |
|
467
|
|
|
|
|
468
|
|
|
public function segmentsTheta($segmentsTheta) |
|
469
|
|
|
{ |
|
470
|
|
|
$this->segmentsTheta = $segmentsTheta; |
|
471
|
|
|
} |
|
472
|
|
|
|
|
473
|
|
|
public function segmentsPhi($segmentsPhi) |
|
474
|
|
|
{ |
|
475
|
|
|
$this->segmentsPhi = $segmentsPhi; |
|
476
|
|
|
} |
|
477
|
|
|
|
|
478
|
|
|
public function segmentsTubular($segmentsTubular) |
|
479
|
|
|
{ |
|
480
|
|
|
$this->segmentsTubular = $segmentsTubular; |
|
481
|
|
|
} |
|
482
|
|
|
|
|
483
|
|
|
public function phiStart($phiStart) |
|
484
|
|
|
{ |
|
485
|
|
|
$this->phiStart = $phiStart; |
|
486
|
|
|
} |
|
487
|
|
|
|
|
488
|
|
|
public function phiLength($phiLength) |
|
489
|
|
|
{ |
|
490
|
|
|
$this->phiLength = $phiLength; |
|
491
|
|
|
} |
|
492
|
|
|
|
|
493
|
|
|
public function radiusInner($radiusInner) |
|
494
|
|
|
{ |
|
495
|
|
|
$this->radiusInner = $radiusInner; |
|
496
|
|
|
} |
|
497
|
|
|
|
|
498
|
|
|
public function radiusOuter($radiusOuter) |
|
499
|
|
|
{ |
|
500
|
|
|
$this->radiusOuter = $radiusOuter; |
|
501
|
|
|
} |
|
502
|
|
|
|
|
503
|
|
|
public function arc($arc) |
|
504
|
|
|
{ |
|
505
|
|
|
$this->arc = $arc; |
|
506
|
|
|
} |
|
507
|
|
|
|
|
508
|
|
|
public function p($p) |
|
509
|
|
|
{ |
|
510
|
|
|
$this->p = $p; |
|
511
|
|
|
} |
|
512
|
|
|
|
|
513
|
|
|
public function q($q) |
|
514
|
|
|
{ |
|
515
|
|
|
$this->q = $q; |
|
516
|
|
|
} |
|
517
|
|
|
|
|
518
|
3 |
|
public function translate($translate) |
|
519
|
|
|
{ |
|
520
|
3 |
|
$this->translate = $translate; |
|
521
|
3 |
|
} |
|
522
|
|
|
|
|
523
|
|
|
/** |
|
524
|
|
|
* Magic Call |
|
525
|
|
|
* |
|
526
|
|
|
* @param string $method |
|
527
|
|
|
* @param array $args |
|
528
|
|
|
* @throws InvalidComponentMethodException |
|
529
|
|
|
*/ |
|
530
|
|
|
public function __call($method, $args) |
|
531
|
|
|
{ |
|
532
|
|
|
if ($method === 'primitive') { |
|
533
|
|
|
return call_user_func_array(array( |
|
534
|
|
|
$this, |
|
535
|
|
|
$method |
|
536
|
|
|
), $args); |
|
537
|
|
|
} |
|
538
|
|
|
try { |
|
539
|
|
|
if (method_exists($this, $method) && $this->isPrimitiveMethod($method)) { |
|
|
|
|
|
|
540
|
|
|
return call_user_func_array(array( |
|
541
|
|
|
$this, |
|
542
|
|
|
$method |
|
543
|
|
|
), $args); |
|
544
|
|
|
} else { |
|
545
|
|
|
throw new InvalidComponentMethodException($method, 'Geometry::primitive ' . $this->primitive); |
|
546
|
|
|
} |
|
547
|
|
|
} catch (InvalidComponentMethodException $e) { |
|
548
|
|
|
die($e->getMessage()); |
|
549
|
|
|
} |
|
550
|
|
|
} |
|
551
|
|
|
|
|
552
|
|
|
/** |
|
553
|
|
|
* Is called method allowed for current primitive |
|
554
|
|
|
* |
|
555
|
|
|
* @param unknown $method |
|
556
|
|
|
*/ |
|
557
|
|
|
protected function isPrimitiveMethod($method) |
|
558
|
|
|
{ |
|
559
|
|
|
switch ($this->primitive) { |
|
560
|
|
|
case 'box': |
|
561
|
|
|
return in_array($method, self::P_BOX) ? self::P_BOX : false; |
|
562
|
|
|
break; |
|
|
|
|
|
|
563
|
|
|
case 'circle': |
|
564
|
|
|
return in_array($method, self::P_CIRCLE) ? self::P_CIRCLE : false; |
|
565
|
|
|
break; |
|
|
|
|
|
|
566
|
|
|
case 'cone': |
|
567
|
|
|
return in_array($method, self::P_CONE) ? self::P_CONE : false; |
|
568
|
|
|
break; |
|
|
|
|
|
|
569
|
|
|
case 'cylinder': |
|
570
|
|
|
return in_array($method, self::P_CYLINDER) ? self::P_CYLINDER : false; |
|
571
|
|
|
break; |
|
|
|
|
|
|
572
|
|
|
case 'plane': |
|
573
|
|
|
return in_array($method, self::P_PLANE) ? self::P_PLANE : false; |
|
574
|
|
|
break; |
|
|
|
|
|
|
575
|
|
|
case 'ring': |
|
576
|
|
|
return in_array($method, self::P_RING) ? self::P_RING : false; |
|
577
|
|
|
break; |
|
|
|
|
|
|
578
|
|
|
case 'sphere': |
|
579
|
|
|
return in_array($method, self::P_SPHERE) ? self::P_SPHERE : false; |
|
580
|
|
|
break; |
|
|
|
|
|
|
581
|
|
|
case 'torus': |
|
582
|
|
|
return in_array($method, self::P_TORUS) ? self::P_TORUS : false; |
|
583
|
|
|
break; |
|
|
|
|
|
|
584
|
|
|
case 'torusKnot': |
|
585
|
|
|
return in_array($method, self::P_TORUS_KNOT) ? self::P_TORUS_KNOT : false; |
|
586
|
|
|
break; |
|
|
|
|
|
|
587
|
|
|
default: |
|
588
|
|
|
return false; |
|
589
|
|
|
break; |
|
|
|
|
|
|
590
|
|
|
} |
|
591
|
|
|
} |
|
592
|
|
|
|
|
593
|
|
|
/** |
|
594
|
|
|
* Get defaults for current primitve type |
|
595
|
|
|
* |
|
596
|
|
|
* @return array; |
|
|
|
|
|
|
597
|
|
|
*/ |
|
598
|
8 |
|
protected function primitiveDefaults(): array |
|
599
|
|
|
{ |
|
600
|
8 |
|
switch ($this->primitive) { |
|
601
|
8 |
|
case 'box': |
|
602
|
4 |
|
return self::P_BOX; |
|
603
|
|
|
break; |
|
|
|
|
|
|
604
|
4 |
|
case 'circle': |
|
605
|
|
|
return self::P_CIRCLE; |
|
606
|
|
|
break; |
|
|
|
|
|
|
607
|
4 |
|
case 'cone': |
|
608
|
|
|
return self::P_CONE; |
|
609
|
|
|
break; |
|
|
|
|
|
|
610
|
4 |
|
case 'cylinder': |
|
611
|
4 |
|
return self::P_CYLINDER; |
|
612
|
|
|
break; |
|
|
|
|
|
|
613
|
|
|
case 'plane': |
|
614
|
|
|
return self::P_PLANE; |
|
615
|
|
|
break; |
|
|
|
|
|
|
616
|
|
|
case 'ring': |
|
617
|
|
|
return self::P_RING; |
|
618
|
|
|
break; |
|
|
|
|
|
|
619
|
|
|
case 'sphere': |
|
620
|
|
|
return self::P_SPHERE; |
|
621
|
|
|
break; |
|
|
|
|
|
|
622
|
|
|
case 'torus': |
|
623
|
|
|
return self::P_TORUS; |
|
624
|
|
|
break; |
|
|
|
|
|
|
625
|
|
|
case 'torusKnot': |
|
626
|
|
|
return self::P_TORUS_KNOT; |
|
627
|
|
|
break; |
|
|
|
|
|
|
628
|
|
|
default: |
|
629
|
|
|
return array(); |
|
630
|
|
|
break; |
|
|
|
|
|
|
631
|
|
|
} |
|
632
|
|
|
} |
|
633
|
|
|
} |
|
634
|
|
|
|
This check looks for
@paramannotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.