00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef HxVec2Double_h
00012 #define HxVec2Double_h
00013
00014
00015
00016 #include "HxIoFwd.h"
00017 #include "HxMath.h"
00018 #include "HxString.h"
00019
00020 #undef min
00021 #undef max
00022
00023 class HxScalarInt;
00024 #include "HxScalarDouble.h"
00025 class HxVec2Int;
00026 class HxVec3Int;
00027 class HxVec3Double;
00028 class HxComplex;
00029
00030
00034 class L_HXBASIS HxVec2Double
00035 {
00036 public:
00037
00039
00041 HxVec2Double();
00042
00044 HxVec2Double(double x, double y);
00045
00047 HxVec2Double(const HxVec2Double& rhs);
00049
00050 void* operator new(size_t, void * = 0);
00051
00052 HxVec2Double& operator=(const HxVec2Double& rhs);
00053
00055
00058 int dim() const;
00059
00061 double x() const;
00062
00064 double y() const;
00065
00067 double getValue(int dimension) const;
00068 void setValue(int dimension, double value);
00070
00072
00074 operator HxScalarInt() const;
00075
00077 operator HxScalarDouble() const;
00078
00080 operator HxVec2Int() const;
00081
00083 operator HxVec3Int() const;
00084
00086 operator HxVec3Double() const;
00087
00089 operator HxComplex() const;
00091
00093
00097 int operator==(const HxVec2Double& v) const;
00098
00100 int operator!=(const HxVec2Double& v) const;
00101
00103 int operator< (const HxVec2Double& v) const;
00104
00106 int operator<=(const HxVec2Double& v) const;
00107
00109 int operator> (const HxVec2Double& v) const;
00110
00112 int operator>=(const HxVec2Double& v) const;
00113
00118 static const HxVec2Double SMALL_VAL;
00119
00124 static const HxVec2Double LARGE_VAL;
00126
00128
00132 HxVec2Double operator-() const;
00133
00135 HxVec2Double complement() const;
00136
00138 HxVec2Double abs() const;
00139
00141 HxVec2Double ceil() const;
00142
00144 HxVec2Double floor() const;
00145
00147 HxVec2Double round() const;
00148
00150 HxScalarDouble sum() const;
00151
00153 HxScalarDouble product() const;
00154
00156 HxScalarDouble min() const;
00157
00159 HxScalarDouble max() const;
00160
00162 HxScalarDouble norm1() const;
00163
00165 HxScalarDouble norm2() const;
00166
00168 HxScalarDouble normInf() const;
00169
00171 HxVec2Double sqrt() const;
00172
00174 HxVec2Double sin() const;
00175
00177 HxVec2Double cos() const;
00178
00180 HxVec2Double tan() const;
00181
00183 HxVec2Double asin() const;
00184
00186 HxVec2Double acos() const;
00187
00189 HxVec2Double atan() const;
00190
00192 HxScalarDouble atan2() const;
00193
00195 HxVec2Double sinh() const;
00196
00198 HxVec2Double cosh() const;
00199
00201 HxVec2Double tanh() const;
00202
00204 HxVec2Double exp() const;
00205
00207 HxVec2Double log() const;
00208
00210 HxVec2Double log10() const;
00212
00214
00218 HxVec2Double& operator+=(const HxVec2Double& v);
00219
00221 HxVec2Double& operator-=(const HxVec2Double& v);
00222
00224 HxVec2Double& operator*=(const HxVec2Double& v);
00225
00227 HxVec2Double& operator/=(const HxVec2Double& v);
00228
00229
00231 friend HxVec2Double operator+(const HxVec2Double& v1,
00232 const HxVec2Double& v2);
00233
00235 friend HxVec2Double operator-(const HxVec2Double& v1,
00236 const HxVec2Double& v2);
00237
00239 friend HxVec2Double operator*(const HxVec2Double& v1,
00240 const HxVec2Double& v2);
00241
00243 friend HxVec2Double operator/(const HxVec2Double& v1,
00244 const HxVec2Double& v2);
00245
00246
00248 HxVec2Double min(const HxVec2Double& v) const;
00249
00251 HxVec2Double& minAssign(const HxVec2Double& v);
00252
00254 HxVec2Double max(const HxVec2Double& v) const;
00255
00257 HxVec2Double& maxAssign(const HxVec2Double& v);
00258
00260 HxVec2Double inf(const HxVec2Double& v) const;
00261
00263 HxVec2Double& infAssign(const HxVec2Double& v);
00264
00266 HxVec2Double sup(const HxVec2Double& v) const;
00267
00269 HxVec2Double& supAssign(const HxVec2Double& v);
00270
00272 HxVec2Double pow(const HxVec2Double& v) const;
00273
00275 HxVec2Double mod(const HxVec2Double& v) const;
00276
00278 HxVec2Double and(const HxVec2Double& v) const;
00279
00281 HxVec2Double or(const HxVec2Double& v) const;
00282
00284 HxVec2Double xor(const HxVec2Double& v) const;
00285
00287 HxVec2Double leftShift(const HxVec2Double& v) const;
00288
00290 HxVec2Double rightShift(const HxVec2Double& v) const;
00291
00293 HxScalarDouble dot(const HxVec2Double& v) const;
00294
00296 HxVec2Double cross(const HxVec2Double& v) const;
00298
00300
00302 STD_OSTREAM& put(STD_OSTREAM& os) const;
00303
00305 HxString toString() const;
00307
00308 private:
00309 double _values[2];
00310 };
00311
00312 typedef HxVec2Double (*HxUpoVec2Double)(const HxVec2Double& a);
00313 typedef HxVec2Double (*HxBpoVec2Double)(const HxVec2Double& a1, const HxVec2Double& a2);
00314
00315 inline STD_OSTREAM&
00316 operator<<(STD_OSTREAM& os, const HxVec2Double v)
00317 {
00318 return v.put(os);
00319 }
00320
00321 inline
00322 HxVec2Double::HxVec2Double()
00323 {
00324 }
00325
00326 inline
00327 HxVec2Double::HxVec2Double(double x, double y)
00328 {
00329 _values[0] = x;
00330 _values[1] = y;
00331 }
00332
00333 inline
00334 HxVec2Double::HxVec2Double(const HxVec2Double& v)
00335 {
00336 _values[0] = v._values[0];
00337 _values[1] = v._values[1];
00338 }
00339
00340 inline HxVec2Double&
00341 HxVec2Double::operator=(const HxVec2Double& rhs)
00342 {
00343 _values[0] = rhs._values[0];
00344 _values[1] = rhs._values[1];
00345 return *this;
00346 }
00347
00348 inline void*
00349 HxVec2Double::operator new(size_t size, void *m)
00350 {
00351 return m ? m : new char[size];
00352 }
00353
00354 inline int
00355 HxVec2Double::dim() const
00356 {
00357 return 2;
00358 }
00359
00360 inline double
00361 HxVec2Double::x() const
00362 {
00363 return _values[0];
00364 }
00365
00366 inline double
00367 HxVec2Double::y() const
00368 {
00369 return _values[1];
00370 }
00371
00372 inline double
00373 HxVec2Double::getValue(int dim) const
00374 {
00375 return _values[dim - 1];
00376 }
00377
00378 inline void
00379 HxVec2Double::setValue(int dim, double val)
00380 {
00381 _values[dim - 1] = val;
00382 }
00383
00384 inline int
00385 HxVec2Double::operator==(const HxVec2Double& v) const
00386 {
00387 return (_values[0] == v._values[0]) && (_values[1] == v._values[1]);
00388 }
00389
00390 inline int
00391 HxVec2Double::operator!=(const HxVec2Double& v) const
00392 {
00393 return (_values[0] != v._values[0]) || (_values[1] != v._values[1]);
00394 }
00395
00396 inline int
00397 HxVec2Double::operator<(const HxVec2Double& v) const
00398 {
00399 return (fabs(_values[0]) + fabs(_values[1])) <
00400 (fabs(v._values[0]) + fabs(v._values[1]));
00401 }
00402
00403 inline int
00404 HxVec2Double::operator<=(const HxVec2Double& v) const
00405 {
00406 return (fabs(_values[0]) + fabs(_values[1])) <=
00407 (fabs(v._values[0]) + fabs(v._values[1]));
00408 }
00409
00410 inline int
00411 HxVec2Double::operator>(const HxVec2Double& v) const
00412 {
00413 return (fabs(_values[0]) + fabs(_values[1])) >
00414 (fabs(v._values[0]) + fabs(v._values[1]));
00415 }
00416
00417 inline int
00418 HxVec2Double::operator>=(const HxVec2Double& v) const
00419 {
00420 return (fabs(_values[0]) + fabs(_values[1])) >=
00421 (fabs(v._values[0]) + fabs(v._values[1]));
00422 }
00423
00424 inline HxVec2Double
00425 HxVec2Double::operator-() const
00426 {
00427 return HxVec2Double(-_values[0], -_values[1]);
00428 }
00429
00430 inline HxVec2Double
00431 HxVec2Double::complement() const
00432 {
00433 return HxVec2Double(-_values[0], -_values[1]);
00434 }
00435
00436 inline HxVec2Double
00437 HxVec2Double::abs() const
00438 {
00439 return HxVec2Double(fabs(_values[0]), fabs(_values[1]));
00440 }
00441
00442 inline HxVec2Double
00443 HxVec2Double::ceil() const
00444 {
00445 return HxVec2Double(::ceil(_values[0]), ::ceil(_values[1]));
00446 }
00447
00448 inline HxVec2Double
00449 HxVec2Double::floor() const
00450 {
00451 return HxVec2Double(::floor(_values[0]), ::floor(_values[1]));
00452 }
00453
00454 inline HxVec2Double
00455 HxVec2Double::round() const
00456 {
00457 return HxVec2Double((int) (_values[0] + ((_values[0] >= 0) ? 0.5 : -0.5)),
00458 (int) (_values[1] + ((_values[1] >= 0) ? 0.5 : -0.5)));
00459 }
00460
00461 inline HxVec2Double
00462 HxVec2Double::sqrt() const
00463 {
00464 return HxVec2Double(::sqrt(_values[0]), ::sqrt(_values[1]));
00465 }
00466
00467 inline HxVec2Double
00468 HxVec2Double::sin() const
00469 {
00470 return HxVec2Double(::sin(_values[0]), ::sin(_values[1]));
00471 }
00472
00473 inline HxVec2Double
00474 HxVec2Double::cos() const
00475 {
00476 return HxVec2Double(::cos(_values[0]), ::cos(_values[1]));
00477 }
00478
00479 inline HxVec2Double
00480 HxVec2Double::tan() const
00481 {
00482 return HxVec2Double(::tan(_values[0]), ::tan(_values[1]));
00483 }
00484
00485 inline HxVec2Double
00486 HxVec2Double::asin() const
00487 {
00488 return HxVec2Double(::asin(_values[0]), ::asin(_values[1]));
00489 }
00490
00491 inline HxVec2Double
00492 HxVec2Double::acos() const
00493 {
00494 return HxVec2Double(::acos(_values[0]), ::acos(_values[1]));
00495 }
00496
00497 inline HxVec2Double
00498 HxVec2Double::atan() const
00499 {
00500 return HxVec2Double(::atan(_values[0]), ::atan(_values[1]));
00501 }
00502
00503 inline HxVec2Double
00504 HxVec2Double::sinh() const
00505 {
00506 return HxVec2Double(::sinh(_values[0]), ::sinh(_values[1]));
00507 }
00508
00509 inline HxVec2Double
00510 HxVec2Double::cosh() const
00511 {
00512 return HxVec2Double(::cosh(_values[0]), ::cosh(_values[1]));
00513 }
00514
00515 inline HxVec2Double
00516 HxVec2Double::tanh() const
00517 {
00518 return HxVec2Double(::tanh(_values[0]), ::tanh(_values[1]));
00519 }
00520
00521 inline HxVec2Double
00522 HxVec2Double::exp() const
00523 {
00524 return HxVec2Double(::exp(_values[0]), ::exp(_values[1]));
00525 }
00526
00527 inline HxVec2Double
00528 HxVec2Double::log() const
00529 {
00530 return HxVec2Double(::log(_values[0]), ::log(_values[1]));
00531 }
00532
00533 inline HxVec2Double
00534 HxVec2Double::log10() const
00535 {
00536 return HxVec2Double(::log10(_values[0]), ::log10(_values[1]));
00537 }
00538
00539 inline HxVec2Double&
00540 HxVec2Double::operator+=(const HxVec2Double& v)
00541 {
00542 _values[0] += v._values[0];
00543 _values[1] += v._values[1];
00544 return *this;
00545 }
00546
00547 inline HxVec2Double&
00548 HxVec2Double::operator-=(const HxVec2Double& v)
00549 {
00550 _values[0] -= v._values[0];
00551 _values[1] -= v._values[1];
00552 return *this;
00553 }
00554
00555 inline HxVec2Double&
00556 HxVec2Double::operator*=(const HxVec2Double& v)
00557 {
00558 _values[0] *= v._values[0];
00559 _values[1] *= v._values[1];
00560 return *this;
00561 }
00562
00563 inline HxVec2Double&
00564 HxVec2Double::operator/=(const HxVec2Double& v)
00565 {
00566 _values[0] /= v._values[0];
00567 _values[1] /= v._values[1];
00568 return *this;
00569 }
00570
00571 inline HxVec2Double
00572 operator+(const HxVec2Double& v1, const HxVec2Double& v2)
00573 {
00574 return HxVec2Double(v1._values[0] + v2._values[0],
00575 v1._values[1] + v2._values[1]);
00576 }
00577
00578 inline HxVec2Double
00579 operator-(const HxVec2Double& v1, const HxVec2Double& v2)
00580 {
00581 return HxVec2Double(v1._values[0] - v2._values[0],
00582 v1._values[1] - v2._values[1]);
00583 }
00584
00585 inline HxVec2Double
00586 operator*(const HxVec2Double& v1, const HxVec2Double& v2)
00587 {
00588 return HxVec2Double(v1._values[0] * v2._values[0],
00589 v1._values[1] * v2._values[1]);
00590 }
00591
00592 inline HxVec2Double
00593 operator/(const HxVec2Double& v1, const HxVec2Double& v2)
00594 {
00595 return HxVec2Double(v1._values[0] / v2._values[0],
00596 v1._values[1] / v2._values[1]);
00597 }
00598
00599 inline HxVec2Double
00600 HxVec2Double::min(const HxVec2Double& v) const
00601 {
00602 return (operator<(v)) ? (*this) : v;
00603 }
00604
00605 inline HxVec2Double&
00606 HxVec2Double::minAssign(const HxVec2Double& v)
00607 {
00608 if (operator<(v))
00609 return *this;
00610 operator=(v);
00611 return *this;
00612 }
00613
00614 inline HxVec2Double
00615 HxVec2Double::max(const HxVec2Double& v) const
00616 {
00617 return (operator>(v)) ? (*this) : v;
00618 }
00619
00620 inline HxVec2Double&
00621 HxVec2Double::maxAssign(const HxVec2Double& v)
00622 {
00623 if (operator>(v))
00624 return *this;
00625 operator=(v);
00626 return *this;
00627 }
00628
00629 inline HxVec2Double
00630 HxVec2Double::inf(const HxVec2Double& v) const
00631 {
00632 return HxVec2Double((_values[0] < v._values[0]) ? _values[0] : v._values[0],
00633 (_values[1] < v._values[1]) ? _values[1] : v._values[1]);
00634 }
00635
00636 inline HxVec2Double&
00637 HxVec2Double::infAssign(const HxVec2Double& v)
00638 {
00639 _values[0] = (_values[0] < v._values[0]) ? _values[0] : v._values[0];
00640 _values[1] = (_values[1] < v._values[1]) ? _values[1] : v._values[1];
00641 return *this;
00642 }
00643
00644 inline HxVec2Double
00645 HxVec2Double::sup(const HxVec2Double& v) const
00646 {
00647 return HxVec2Double((_values[0] > v._values[0]) ? _values[0] : v._values[0],
00648 (_values[1] > v._values[1]) ? _values[1] : v._values[1]);
00649 }
00650
00651 inline HxVec2Double&
00652 HxVec2Double::supAssign(const HxVec2Double& v)
00653 {
00654 _values[0] = (_values[0] > v._values[0]) ? _values[0] : v._values[0];
00655 _values[1] = (_values[1] > v._values[1]) ? _values[1] : v._values[1];
00656 return *this;
00657 }
00658
00659 inline HxVec2Double
00660 HxVec2Double::pow(const HxVec2Double& v) const
00661 {
00662 return HxVec2Double(::pow(_values[0], v._values[0]),
00663 ::pow(_values[1], v._values[1]));
00664 }
00665
00666 inline HxVec2Double
00667 HxVec2Double::mod(const HxVec2Double&) const
00668 {
00669 return (*this);
00670 }
00671
00672 inline HxVec2Double
00673 HxVec2Double::and(const HxVec2Double&) const
00674 {
00675 return (*this);
00676 }
00677
00678 inline HxVec2Double
00679 HxVec2Double::or(const HxVec2Double&) const
00680 {
00681 return (*this);
00682 }
00683
00684 inline HxVec2Double
00685 HxVec2Double::xor(const HxVec2Double&) const
00686 {
00687 return (*this);
00688 }
00689
00690 inline HxVec2Double
00691 HxVec2Double::leftShift(const HxVec2Double&) const
00692 {
00693 return (*this);
00694 }
00695
00696 inline HxVec2Double
00697 HxVec2Double::rightShift(const HxVec2Double&) const
00698 {
00699 return (*this);
00700 }
00701
00702 inline HxVec2Double
00703 HxVec2Double::cross(const HxVec2Double&) const
00704 {
00705 return HxVec2Double(0, 0);
00706 }
00707
00708 inline HxScalarDouble
00709 HxVec2Double::sum() const
00710 {
00711 return _values[0] + _values[1];
00712 }
00713
00714 inline HxScalarDouble
00715 HxVec2Double::product() const
00716 {
00717 return _values[0] * _values[1];
00718 }
00719
00720 inline HxScalarDouble
00721 HxVec2Double::min() const
00722 {
00723 return (_values[0] < _values[1]) ? _values[0] : _values[1];
00724 }
00725
00726 inline HxScalarDouble
00727 HxVec2Double::max() const
00728 {
00729 return (_values[0] > _values[1]) ? _values[0] : _values[1];
00730 }
00731
00732 #endif