File: Vector.sip

package info (click to toggle)
tulip 4.8.0dfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 179,264 kB
  • ctags: 64,517
  • sloc: cpp: 600,444; ansic: 36,311; makefile: 22,136; python: 1,304; sh: 946; yacc: 522; xml: 337; pascal: 157; php: 66; lex: 55
file content (704 lines) | stat: -rw-r--r-- 15,886 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
/**
 *
 * This file is part of Tulip (www.tulip-software.org)
 *
 * Authors: David Auber and the Tulip development Team
 * from LaBRI, University of Bordeaux 1 and Inria Bordeaux - Sud Ouest
 *
 * Tulip is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License
 * as published by the Free Software Foundation, either version 3
 * of the License, or (at your option) any later version.
 *
 * Tulip is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details.
 *
 */

// +-------------------------------------------------------------------------+
// | Tulip Python Bindings                                                   |
// | inspired from bindings by the Booggie project development team          |
// | (http://booggie.org/)                                                   |
// +-------------------------------------------------------------------------+

%ModuleHeaderCode
#include <tulip/Vector.h>
#include <sstream>
%End

namespace tlp {
class Vec3f  {

%Docstring
This class represents a vector with 3 floating point components.
It can be instantiated as illustrated in the code below: ::

	# Initializes a Vec3f with all components set to 0.0
	v = tlp.Vec3f()
	
	# Initializes a Vec3f with all components set to 1.0
	v2 = tlp.Vec3f(1.0)
	
	# Initializes a Vec3f by specifying the value of each component
	v3 = tlp.Vec3f(1.0, 2.0, 3.0) 
	
	# Initializes a Vec3f by copy
	v4 = tlp.Vec3f(v3)

Numerous mathematical operations are available to work with vectors. The sample code below illustrates them: ::

	# Instantiate two vectors
	v = tlp.Vec3f(4.5, 1.0, 3.0)
	v2 = tlp.Vec3f(1.5, 2.0, 6.0)
	
	# Add two vectors, operator += is also available
	v3 = v + v2
	
	# Add a value to all components of a vector, operator += is also available
	v4 = v + 2.0
	
	# Subtract two vectors, operator -= is also available
	v5 = v - v2
	
	# Subtract a value to all components of a vector, operator -= is also available
	v6 = v - 3.0
	
	# Multiply two vectors (not vector product), operator *= is also available
	v7 = v * v2
	
	# Multiply each component of a vector by a value, operator *= is also available
	v8 = v * 2.0
	
	# Divide two vectors, operator /= is also available
	v9 = v / v2
	
	# Divide each component of a vector by a value, operator /= is also available
	v10 = v / 2.0
	
	# Perform a vector product, operator ^= is also available
	v11 = v ^ v2

Each component of the vector can be read / written through the [] operator: ::

	v = tlp.Vec3f(1.0, 2.0, 3.0)
	
	# read first component
	a = v[0]
	
	# write third component
	v[2] = 4.0
	
Operators for vectors equality (==), vectors difference (!=) and vectors comparison (<, >) are also available.
	
%End

public:

	Vec3f();
	
	Vec3f(const float a0);
	
  Vec3f(const float a0, const float a1, const float a2=0);
	
	Vec3f(const tlp::Vec3f &);
	
	float operator[](const unsigned int i) const;
%MethodCode
  if (a0 < 3) {
    sipRes = (*sipCpp)[a0];
  } else {
    sipIsErr = -1;
    PyErr_SetNone(PyExc_IndexError);
  }
%End

	void __setitem__(int i, const float &value);
%MethodCode
  if (a0 < 3) {
		(*sipCpp)[a0] = a1;
  } else {
    sipIsErr = -1;
    PyErr_SetNone(PyExc_IndexError);
  }
%End
	
	tlp::Vec3f & operator*=(const float &);
  tlp::Vec3f & operator*=(const tlp::Vec3f &);
  tlp::Vec3f & operator/=(const float &);
%MethodCode
  if (a0 != 0) {
            sipCpp->tlp::Vec3f::operator/=(a0);
} else {
    sipIsErr = -1;
    PyErr_SetString(PyExc_ZeroDivisionError, "division of a float vector[3] by zero");
  }
%End
  tlp::Vec3f & operator/=(const tlp::Vec3f &);
%MethodCode
  if ((*a0)[0] && (*a0)[1] && (*a0)[2]) {
            sipCpp->tlp::Vec3f::operator/=(*a0);
  } else {
    sipIsErr = -1;
    PyErr_SetString(PyExc_ZeroDivisionError, "division of a float vector[3] by a float vector[3] with a zero element");
  }
%End
  tlp::Vec3f & operator+=(const float &);
  tlp::Vec3f & operator+=(const tlp::Vec3f &);
  tlp::Vec3f & operator-=(const float &);
  tlp::Vec3f & operator-=(const tlp::Vec3f &);
  tlp::Vec3f & operator^=(const tlp::Vec3f &);

	tlp::Vec3f operator*(const  tlp::Vec3f &) const;
	tlp::Vec3f operator*(const float &) const;
	tlp::Vec3f operator+(const  tlp::Vec3f &) const;
	tlp::Vec3f operator+(const float &) const;
	tlp::Vec3f operator-(const  tlp::Vec3f &) const;
	tlp::Vec3f operator-(const float &) const; 
	tlp::Vec3f operator/(const  tlp::Vec3f &) const;
%MethodCode
  if ((*a1)[0] && (*a1)[1] && (*a1)[2]) {
    sipRes = new tlp::Vec3f((*a0 / *a1));
  } else {
    sipIsErr = -1;
    PyErr_SetString(PyExc_ZeroDivisionError, "division of a float vector[3] by a float vector[3] with a zero element");
  }
%End
	tlp::Vec3f operator/(const float &) const;
%MethodCode
  if (a1 != 0) {
    sipRes = new tlp::Vec3f((*a0 / a1));
  } else {
    sipIsErr = -1;
    PyErr_SetString(PyExc_ZeroDivisionError, "division of a float vector[3] by zero");
  }
%End
	tlp::Vec3f operator^(const  tlp::Vec3f &) const;
    
  bool operator>(const tlp::Vec3f &) const;
  bool operator<(const tlp::Vec3f &) const;
  bool operator!=(const tlp::Vec3f &) const;
  bool operator==(const tlp::Vec3f &) const;
    
  void set(const float x=0,const float y=0, const float z=0);
%Docstring
tlp.Vec3f.set(x, y, z)

Sets each component of the vector.

:param x: the first component value
:type x: float
:param y: the second componant value
:type y: float
:param z: the third component value
:type z: float
%End

  void set(const tlp::Vec3f& v);
%Docstring
tlp.Vec3f.set(v)

Sets each component of the vector from another one.

:param v: a vector
:type c: :class:`tlp.Vec3f`
%End

  void setX(float x);
%Docstring
tlp.Vec3f.setX(x)

Convenient method. Sets the first component of the vector.

:param x: a value
:type x: float
%End

  void setY(float y);
%Docstring
tlp.Vec3f.setY(y)

Convenient method. Sets the second component of the vector.

:param y: a value
:type y: float
%End

  void setZ(float z);
%Docstring
tlp.Vec3f.setZ(z)

Convenient method. Sets the third component of the vector.

:param z: a value
:type z: float
%End

  float getX() const;
%Docstring
tlp.Vec3f.getX()

Convenient method. Returns the first component of the vector.

:rtype: float
%End

  float getY() const;
%Docstring
tlp.Vec3f.getY()

Convenient method. Returns the second component of the vector.

:rtype: float
%End

  float getZ() const;
%Docstring
tlp.Vec3f.getZ()

Convenient method. Returns the third component of the vector.

:rtype: float
%End

  float x() const;
%Docstring
tlp.Vec3f.x()

Convenient method. Returns the first component of the vector.

:rtype: float
%End

  float y() const;
%Docstring
tlp.Vec3f.y()

Convenient method. Returns the second component of the vector.

:rtype: float
%End

  float z() const;
%Docstring
tlp.Vec3f.z()

Convenient method. Returns the third component of the vector.

:rtype: float
%End

  void setW(const float width);
%Docstring
tlp.Vec3f.setW(width)

Convenient method. Sets the first component of the vector.

:param width: a value
:type width: float
%End

  void setH(const float height);
%Docstring
tlp.Vec3f.setH(height)

Convenient method. Sets the second component of the vector.

:param height: a value
:type height: float
%End

  void setD(const float depth);
%Docstring
tlp.Vec3f.setD(depth)

Convenient method. Sets the third component of the vector.

:param depth: a value
:type depth: float
%End

  float getW() const;
%Docstring
tlp.Vec3f.getW()

Convenient method. Returns the first component of the vector.

:rtype: float
%End

  float getH() const;
%Docstring
tlp.Vec3f.getH()

Convenient method. Returns the second component of the vector.

:rtype: float
%End

  float getD() const;
%Docstring
tlp.Vec3f.getD()

Convenient method. Returns the third component of the vector.

:rtype: float
%End

  float width() const;
%Docstring
tlp.Vec3f.width()

Convenient method. Returns the first component of the vector.

:rtype: float
%End

  float height() const;
%Docstring
tlp.Vec3f.height()

Convenient method. Returns the second component of the vector.

:rtype: float
%End

  float depth() const;
%Docstring
tlp.Vec3f.depth()

Convenient method. Returns the third component of the vector.

:rtype: float
%End

  void get(float & /Out/, float & /Out/, float & /Out/) const;
%Docstring
tlp.Vec3f.get()

Returns the vector as a tuple.

:rtype: (float, float, float)
%End

  tlp::Vec3f & fill(const float &obj);
%Docstring
tlp.Vec3f.fill(val)

Set the same value to each component of the vector.

:param val: a value
:type val: float
%End
    
  float norm () const;
%Docstring
tlp.Vec3f.norm()

Computes and returns the euclidean norm of the vector.

:rtype: float
%End    
    
  float dist (const tlp::Vec3f &) const;
%Docstring
tlp.Vec3f.dist(v)

Computes and returns the distance between the vector (3d point) and another one.

:param v: a vector
:type v: :class:`tlp.Vec3f`
:rtype: float
%End    
    
  float dotProduct(const tlp::Vec3f &) const;
%Docstring
tlp.Vec3f.dotProduct(v)

Computes and returns the dot product (scalar product) of the vector with another one

:param v: a vector
:type v: :class:`tlp.Vec3f`
:rtype: float
%End
   
  SIP_PYOBJECT __repr__() const;
%MethodCode
  std::ostringstream oss;
  oss << *sipCpp;
  std::string s = oss.str();
  s[0] = '[';
  s[s.size() - 1] = ']';
#if PY_MAJOR_VERSION >= 3
  sipRes = PyUnicode_FromString(s.c_str());
#else
  sipRes = PyString_FromString(s.c_str());
#endif
%End

};

tlp::Vec3f operator*(const float &, const tlp::Vec3f &) const;

class Vec4f  {

%Docstring
This class represents a vector with 4 floating point components.
Constructors, operators and methods are similar to those from the :class:`tlp.Vec3f` class. 
%End

public:

	Vec4f();
	
	Vec4f(const float a0);

  Vec4f(const float a0, const float a1);

  Vec4f(const float a0, const float a1, const float a2);

	Vec4f(const float a0, const float a1, const float a2, const float a3);
	
	Vec4f(const tlp::Vec4f &);
	
	float operator[](const unsigned int i) const;
%MethodCode
  if (a0 < 4) {
    sipRes = (*sipCpp)[a0];
  } else {
    sipIsErr = -1;
    PyErr_SetNone(PyExc_IndexError);
  }
%End

	void __setitem__(int i, const float &value);
%MethodCode
  if (a0 < 4) {
		(*sipCpp)[a0] = a1;
  } else {
    sipIsErr = -1;
    PyErr_SetNone(PyExc_IndexError);
  }
%End
	
	tlp::Vec4f & operator*=(const float &);
  tlp::Vec4f & operator*=(const tlp::Vec4f &);
  tlp::Vec4f & operator/=(const float &);
%MethodCode
  if (a0 != 0) {
            sipCpp->tlp::Vec4f::operator/=(a0);
} else {
    sipIsErr = -1;
    PyErr_SetString(PyExc_ZeroDivisionError, "division of a float vector[4] by zero");
  }
%End
  tlp::Vec4f & operator/=(const tlp::Vec4f &);
%MethodCode
  if ((*a0)[0] && (*a0)[1] && (*a0)[2] && (*a0)[3]) {
            sipCpp->tlp::Vec4f::operator/=(*a0);
  } else {
    sipIsErr = -1;
    PyErr_SetString(PyExc_ZeroDivisionError, "division of a float vector[4] by a float vector[4] with a zero element");
  }
%End
  tlp::Vec4f & operator+=(const float &);
  tlp::Vec4f & operator+=(const tlp::Vec4f &);
  tlp::Vec4f & operator-=(const float &);
  tlp::Vec4f & operator-=(const tlp::Vec4f &);
  tlp::Vec4f & operator^=(const tlp::Vec4f &);

	tlp::Vec4f operator*(const  tlp::Vec4f &) const;
	tlp::Vec4f operator*(const tlp::Mat4f &mat) const;
	tlp::Vec4f operator*(const float &) const;
	tlp::Vec4f operator+(const  tlp::Vec4f &) const;
	tlp::Vec4f operator+(const float &) const;
	tlp::Vec4f operator-(const  tlp::Vec4f &) const;
	tlp::Vec4f operator-(const float &) const; 
	tlp::Vec4f operator/(const  tlp::Vec4f &) const;
%MethodCode
  if ((*a1)[0] && (*a1)[1] && (*a1)[2] && (*a1)[3]) {
    sipRes = new tlp::Vec4f((*a0 / *a1));
  } else {
    sipIsErr = -1;
    PyErr_SetString(PyExc_ZeroDivisionError, "division of a float vector[4] by a float vector[4] with a zero element");
  }
%End
	tlp::Vec4f operator/(const float &) const;
%MethodCode
  if (a1 != 0) {
    sipRes = new tlp::Vec4f((*a0 / a1));
  } else {
    sipIsErr = -1;
    PyErr_SetString(PyExc_ZeroDivisionError, "division of a float vector[4] by zero");
  }
%End
	tlp::Vec4f operator^(const  tlp::Vec4f &) const;
    
  bool operator>(const tlp::Vec4f &) const;
  bool operator<(const tlp::Vec4f &) const;
  bool operator!=(const tlp::Vec4f &) const;
  bool operator==(const tlp::Vec4f &) const;
    
  void set(const float x=0,const float y=0, const float z=0, const float w=0);

  void set(const tlp::Vec4f& v);

  void setX(float x);

  void setY(float y);

  void setZ(float z);

  float getX() const;

  float getY() const;

  float getZ() const;

  float x() const;

  float y() const;

  float z() const;

  float w() const;
%Docstring
tlp.Vec4f.w()

Convenient method. Returns the fourth component of the vector.

:rtype: float
%End

  void setW(const float width);

  void setH(const float height);

  void setD(const float depth);

  float getW() const;

  float getH() const;

  float getD() const;

  float width() const;

  float height() const;

  float depth() const;

  void get(float & /Out/, float & /Out/, float & /Out/, float & /Out/) const;

  tlp::Vec4f & fill(const float &obj);
  float norm () const;
  float dist (const tlp::Vec4f &) const;
  float dotProduct(const tlp::Vec4f &) const;
   
  SIP_PYOBJECT __repr__() const;
%MethodCode
  std::ostringstream oss;
  oss << *sipCpp;
  std::string s = oss.str();
  s[0] = '[';
  s[s.size() - 1] = ']';
#if PY_MAJOR_VERSION >= 3
  sipRes = PyUnicode_FromString(s.c_str());
#else
  sipRes = PyString_FromString(s.c_str());
#endif
%End

};

tlp::Vec4f operator*(const float &, const tlp::Vec4f &) const;

class Vec4i  {

%Docstring
This class represents a vector with 4 integer components.
Constructors, operators and methods are similar to those from the :class:`tlp.Vec3f` class. 
%End

public:

	Vec4i();
	
	Vec4i(const int a0);
	
  Vec4i(const int a0, const int a1);

  Vec4i(const int a0, const int a1, const int a2);

	Vec4i(const int a0, const int a1, const int a2, const int a3);
	
	Vec4i(const tlp::Vec4i &);
	
	int operator[](const unsigned int i) const;
%MethodCode
  if (a0 < 4) {
    sipRes = (*sipCpp)[a0];
  } else {
    sipIsErr = -1;
    PyErr_SetNone(PyExc_IndexError);
  }
%End

	void __setitem__(int i, const int &value);
%MethodCode
  if (a0 < 4) {
		(*sipCpp)[a0] = a1;
  } else {
    sipIsErr = -1;
    PyErr_SetNone(PyExc_IndexError);
  }
%End
	
	tlp::Vec4i & operator*=(const int &);
  tlp::Vec4i & operator*=(const tlp::Vec4i &);
  tlp::Vec4i & operator/=(const int &);
  tlp::Vec4i & operator/=(const tlp::Vec4i &);
  tlp::Vec4i & operator+=(const int &);
  tlp::Vec4i & operator+=(const tlp::Vec4i &);
  tlp::Vec4i & operator-=(const int &);
  tlp::Vec4i & operator-=(const tlp::Vec4i &);
  tlp::Vec4i & operator^=(const tlp::Vec4i &);

	tlp::Vec4i operator*(const  tlp::Vec4i &) const;
	tlp::Vec4i operator*(const int &) const;
	tlp::Vec4i operator+(const  tlp::Vec4i &) const;
	tlp::Vec4i operator+(const int &) const;
	tlp::Vec4i operator-(const  tlp::Vec4i &) const;
	tlp::Vec4i operator-(const int &) const; 
	tlp::Vec4i operator/(const  tlp::Vec4i &) const;
	tlp::Vec4i operator/(const int &) const;
	tlp::Vec4i operator^(const  tlp::Vec4i &) const;
    
  bool operator>(const tlp::Vec4i &) const;
  bool operator<(const tlp::Vec4i &) const;
  bool operator!=(const tlp::Vec4i &) const;
  bool operator==(const tlp::Vec4i &) const;
    
  tlp::Vec4i & fill(const int &obj);
    
  SIP_PYOBJECT __repr__() const;
%MethodCode
  std::ostringstream oss;
  oss << *sipCpp;
  std::string s = oss.str();
  s[0] = '[';
  s[s.size() - 1] = ']';
#if PY_MAJOR_VERSION >= 3
  sipRes = PyUnicode_FromString(s.c_str());
#else
  sipRes = PyString_FromString(s.c_str());
#endif
%End

};

tlp::Vec4i operator*(const int &, const tlp::Vec4i &) const;

};