Warning, file /include/opencascade/NCollection_Vec3.hxx was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #ifndef NCollection_Vec3_HeaderFile
0016 #define NCollection_Vec3_HeaderFile
0017
0018 #include <cstring>
0019 #include <cmath>
0020 #include <NCollection_Vec2.hxx>
0021
0022
0023 #define NCOLLECTION_VEC_COMPONENTS_3D(theX, theY, theZ) \
0024 const NCollection_Vec3<Element_t> theX##theY##theZ() const { return NCollection_Vec3<Element_t>(theX(), theY(), theZ()); } \
0025 const NCollection_Vec3<Element_t> theX##theZ##theY() const { return NCollection_Vec3<Element_t>(theX(), theZ(), theY()); } \
0026 const NCollection_Vec3<Element_t> theY##theX##theZ() const { return NCollection_Vec3<Element_t>(theY(), theX(), theZ()); } \
0027 const NCollection_Vec3<Element_t> theY##theZ##theX() const { return NCollection_Vec3<Element_t>(theY(), theZ(), theX()); } \
0028 const NCollection_Vec3<Element_t> theZ##theY##theX() const { return NCollection_Vec3<Element_t>(theZ(), theY(), theX()); } \
0029 const NCollection_Vec3<Element_t> theZ##theX##theY() const { return NCollection_Vec3<Element_t>(theZ(), theX(), theY()); }
0030
0031
0032
0033
0034 template<typename Element_t>
0035 class NCollection_Vec3
0036 {
0037
0038 public:
0039
0040
0041 static int Length()
0042 {
0043 return 3;
0044 }
0045
0046
0047 NCollection_Vec3()
0048 {
0049 std::memset (this, 0, sizeof(NCollection_Vec3));
0050 }
0051
0052
0053 explicit NCollection_Vec3 (Element_t theValue)
0054 {
0055 v[0] = v[1] = v[2] = theValue;
0056 }
0057
0058
0059 explicit NCollection_Vec3 (const Element_t theX,
0060 const Element_t theY,
0061 const Element_t theZ)
0062 {
0063 v[0] = theX;
0064 v[1] = theY;
0065 v[2] = theZ;
0066 }
0067
0068
0069 explicit NCollection_Vec3 (const NCollection_Vec2<Element_t>& theVec2, Element_t theZ = Element_t(0))
0070 {
0071 v[0] = theVec2[0];
0072 v[1] = theVec2[1];
0073 v[2] = theZ;
0074 }
0075
0076
0077
0078
0079
0080
0081 template <typename OtherElement_t>
0082 explicit NCollection_Vec3 (const NCollection_Vec3<OtherElement_t>& theOtherVec3)
0083 {
0084 v[0] = static_cast<Element_t> (theOtherVec3[0]);
0085 v[1] = static_cast<Element_t> (theOtherVec3[1]);
0086 v[2] = static_cast<Element_t> (theOtherVec3[2]);
0087 }
0088
0089
0090 void SetValues (const Element_t theX,
0091 const Element_t theY,
0092 const Element_t theZ)
0093 {
0094 v[0] = theX;
0095 v[1] = theY;
0096 v[2] = theZ;
0097 }
0098
0099
0100 void SetValues (const NCollection_Vec2<Element_t>& theVec2, Element_t theZ)
0101 {
0102 v[0] = theVec2.x();
0103 v[1] = theVec2.y();
0104 v[2] = theZ;
0105 }
0106
0107
0108 Element_t x() const { return v[0]; }
0109
0110
0111 Element_t r() const { return v[0]; }
0112
0113
0114 Element_t y() const { return v[1]; }
0115
0116
0117 Element_t g() const { return v[1]; }
0118
0119
0120 Element_t z() const { return v[2]; }
0121
0122
0123 Element_t b() const { return v[2]; }
0124
0125
0126 NCOLLECTION_VEC_COMPONENTS_2D(x, y)
0127 NCOLLECTION_VEC_COMPONENTS_2D(x, z)
0128 NCOLLECTION_VEC_COMPONENTS_2D(y, z)
0129
0130
0131 NCOLLECTION_VEC_COMPONENTS_3D(x, y, z)
0132
0133
0134 Element_t& x() { return v[0]; }
0135
0136
0137 Element_t& r() { return v[0]; }
0138
0139
0140 Element_t& y() { return v[1]; }
0141
0142
0143 Element_t& g() { return v[1]; }
0144
0145
0146 Element_t& z() { return v[2]; }
0147
0148
0149 Element_t& b() { return v[2]; }
0150
0151
0152 bool IsEqual (const NCollection_Vec3& theOther) const
0153 {
0154 return v[0] == theOther.v[0]
0155 && v[1] == theOther.v[1]
0156 && v[2] == theOther.v[2];
0157 }
0158
0159
0160 bool operator== (const NCollection_Vec3& theOther) const { return IsEqual (theOther); }
0161
0162
0163 bool operator!= (const NCollection_Vec3& theOther) const { return !IsEqual (theOther); }
0164
0165
0166 const Element_t* GetData() const { return v; }
0167 Element_t* ChangeData() { return v; }
0168 operator const Element_t*() const { return v; }
0169 operator Element_t*() { return v; }
0170
0171
0172 NCollection_Vec3& operator+= (const NCollection_Vec3& theAdd)
0173 {
0174 v[0] += theAdd.v[0];
0175 v[1] += theAdd.v[1];
0176 v[2] += theAdd.v[2];
0177 return *this;
0178 }
0179
0180
0181 friend NCollection_Vec3 operator+ (const NCollection_Vec3& theLeft,
0182 const NCollection_Vec3& theRight)
0183 {
0184 NCollection_Vec3 aSumm = NCollection_Vec3 (theLeft);
0185 return aSumm += theRight;
0186 }
0187
0188
0189 NCollection_Vec3 operator-() const
0190 {
0191 return NCollection_Vec3 (-x(), -y(), -z());
0192 }
0193
0194
0195 NCollection_Vec3& operator-= (const NCollection_Vec3& theDec)
0196 {
0197 v[0] -= theDec.v[0];
0198 v[1] -= theDec.v[1];
0199 v[2] -= theDec.v[2];
0200 return *this;
0201 }
0202
0203
0204 friend NCollection_Vec3 operator- (const NCollection_Vec3& theLeft,
0205 const NCollection_Vec3& theRight)
0206 {
0207 NCollection_Vec3 aSumm = NCollection_Vec3 (theLeft);
0208 return aSumm -= theRight;
0209 }
0210
0211
0212 void Multiply (const Element_t theFactor)
0213 {
0214 v[0] *= theFactor;
0215 v[1] *= theFactor;
0216 v[2] *= theFactor;
0217 }
0218
0219
0220 NCollection_Vec3& operator*= (const NCollection_Vec3& theRight)
0221 {
0222 v[0] *= theRight.v[0];
0223 v[1] *= theRight.v[1];
0224 v[2] *= theRight.v[2];
0225 return *this;
0226 }
0227
0228
0229 friend NCollection_Vec3 operator* (const NCollection_Vec3& theLeft,
0230 const NCollection_Vec3& theRight)
0231 {
0232 NCollection_Vec3 aResult = NCollection_Vec3 (theLeft);
0233 return aResult *= theRight;
0234 }
0235
0236
0237 NCollection_Vec3& operator*= (const Element_t theFactor)
0238 {
0239 Multiply (theFactor);
0240 return *this;
0241 }
0242
0243
0244 NCollection_Vec3 operator* (const Element_t theFactor) const
0245 {
0246 return Multiplied (theFactor);
0247 }
0248
0249
0250 NCollection_Vec3 Multiplied (const Element_t theFactor) const
0251 {
0252 NCollection_Vec3 aCopyVec3 (*this);
0253 aCopyVec3 *= theFactor;
0254 return aCopyVec3;
0255 }
0256
0257
0258 NCollection_Vec3 cwiseMin (const NCollection_Vec3& theVec) const
0259 {
0260 return NCollection_Vec3 (v[0] < theVec.v[0] ? v[0] : theVec.v[0],
0261 v[1] < theVec.v[1] ? v[1] : theVec.v[1],
0262 v[2] < theVec.v[2] ? v[2] : theVec.v[2]);
0263 }
0264
0265
0266 NCollection_Vec3 cwiseMax (const NCollection_Vec3& theVec) const
0267 {
0268 return NCollection_Vec3 (v[0] > theVec.v[0] ? v[0] : theVec.v[0],
0269 v[1] > theVec.v[1] ? v[1] : theVec.v[1],
0270 v[2] > theVec.v[2] ? v[2] : theVec.v[2]);
0271 }
0272
0273
0274 NCollection_Vec3 cwiseAbs() const
0275 {
0276 return NCollection_Vec3 (std::abs (v[0]),
0277 std::abs (v[1]),
0278 std::abs (v[2]));
0279 }
0280
0281
0282 Element_t maxComp() const
0283 {
0284 return v[0] > v[1] ? (v[0] > v[2] ? v[0] : v[2])
0285 : (v[1] > v[2] ? v[1] : v[2]);
0286 }
0287
0288
0289 Element_t minComp() const
0290 {
0291 return v[0] < v[1] ? (v[0] < v[2] ? v[0] : v[2])
0292 : (v[1] < v[2] ? v[1] : v[2]);
0293 }
0294
0295
0296 NCollection_Vec3& operator/= (const Element_t theInvFactor)
0297 {
0298 v[0] /= theInvFactor;
0299 v[1] /= theInvFactor;
0300 v[2] /= theInvFactor;
0301 return *this;
0302 }
0303
0304
0305 NCollection_Vec3& operator/= (const NCollection_Vec3& theRight)
0306 {
0307 v[0] /= theRight.v[0];
0308 v[1] /= theRight.v[1];
0309 v[2] /= theRight.v[2];
0310 return *this;
0311 }
0312
0313
0314 NCollection_Vec3 operator/ (const Element_t theInvFactor) const
0315 {
0316 NCollection_Vec3 aResult (*this);
0317 return aResult /= theInvFactor;
0318 }
0319
0320
0321 friend NCollection_Vec3 operator/ (const NCollection_Vec3& theLeft,
0322 const NCollection_Vec3& theRight)
0323 {
0324 NCollection_Vec3 aResult = NCollection_Vec3 (theLeft);
0325 return aResult /= theRight;
0326 }
0327
0328
0329 Element_t Dot (const NCollection_Vec3& theOther) const
0330 {
0331 return x() * theOther.x() + y() * theOther.y() + z() * theOther.z();
0332 }
0333
0334
0335 Element_t Modulus() const
0336 {
0337 return std::sqrt (x() * x() + y() * y() + z() * z());
0338 }
0339
0340
0341
0342 Element_t SquareModulus() const
0343 {
0344 return x() * x() + y() * y() + z() * z();
0345 }
0346
0347
0348 void Normalize()
0349 {
0350 Element_t aModulus = Modulus();
0351 if (aModulus != Element_t(0))
0352 {
0353 x() = x() / aModulus;
0354 y() = y() / aModulus;
0355 z() = z() / aModulus;
0356 }
0357 }
0358
0359
0360 NCollection_Vec3 Normalized() const
0361 {
0362 NCollection_Vec3 aCopy (*this);
0363 aCopy.Normalize();
0364 return aCopy;
0365 }
0366
0367
0368 static NCollection_Vec3 Cross (const NCollection_Vec3& theVec1,
0369 const NCollection_Vec3& theVec2)
0370 {
0371 return NCollection_Vec3(theVec1.y() * theVec2.z() - theVec1.z() * theVec2.y(),
0372 theVec1.z() * theVec2.x() - theVec1.x() * theVec2.z(),
0373 theVec1.x() * theVec2.y() - theVec1.y() * theVec2.x());
0374 }
0375
0376
0377
0378
0379 static NCollection_Vec3 GetLERP (const NCollection_Vec3& theFrom,
0380 const NCollection_Vec3& theTo,
0381 const Element_t theT)
0382 {
0383 return theFrom * (Element_t(1) - theT) + theTo * theT;
0384 }
0385
0386
0387 static NCollection_Vec3 DX()
0388 {
0389 return NCollection_Vec3 (Element_t(1), Element_t(0), Element_t(0));
0390 }
0391
0392
0393 static NCollection_Vec3 DY()
0394 {
0395 return NCollection_Vec3 (Element_t(0), Element_t(1), Element_t(0));
0396 }
0397
0398
0399 static NCollection_Vec3 DZ()
0400 {
0401 return NCollection_Vec3 (Element_t(0), Element_t(0), Element_t(1));
0402 }
0403
0404
0405 void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const
0406 {
0407 (void)theDepth;
0408 OCCT_DUMP_FIELD_VALUES_NUMERICAL (theOStream, "Vec3", 3, v[0], v[1], v[2])
0409 }
0410
0411 private:
0412
0413 Element_t v[3];
0414
0415 };
0416
0417
0418 template<> inline NCollection_Vec3<float>& NCollection_Vec3<float>::operator/= (const float theInvFactor)
0419 {
0420 Multiply (1.0f / theInvFactor);
0421 return *this;
0422 }
0423
0424
0425 template<> inline NCollection_Vec3<double>& NCollection_Vec3<double>::operator/= (const double theInvFactor)
0426 {
0427 Multiply (1.0 / theInvFactor);
0428 return *this;
0429 }
0430
0431 #endif