mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-08-09 13:22:24 +03:00
0029825: Foundation Classes, NCollection_Vec4 - workaround gcc optimizer issues with xyz() method
Methods of NCollection_Vec3 and NCollection_Vec3 that returned reference to internal buffer as vector of lower dimension (non-const xy(), xyz() etc.) are eliminated. Use of these methods could led to generation of incorrect binary code by GCC. Instead added new method SetValues() accepting vector of lower dimension and additional value. DRAW test command QANColTestVec4 reproducing one situation where the bug occurs is added, along with a test case.
This commit is contained in:
@@ -65,12 +65,12 @@ public:
|
||||
v[2] = theZ;
|
||||
}
|
||||
|
||||
//! Constructor from 2-components vector.
|
||||
explicit NCollection_Vec3 (const NCollection_Vec2<Element_t>& theVec2)
|
||||
//! Constructor from 2-components vector + optional 3rd value.
|
||||
explicit NCollection_Vec3 (const NCollection_Vec2<Element_t>& theVec2, Element_t theZ = Element_t(0))
|
||||
{
|
||||
v[0] = theVec2[0];
|
||||
v[1] = theVec2[1];
|
||||
v[2] = Element_t(0);
|
||||
v[2] = theZ;
|
||||
}
|
||||
|
||||
//! Assign new values to the vector.
|
||||
@@ -83,6 +83,14 @@ public:
|
||||
v[2] = theZ;
|
||||
}
|
||||
|
||||
//! Assign new values to the vector.
|
||||
void SetValues (const NCollection_Vec2<Element_t>& theVec2, Element_t theZ)
|
||||
{
|
||||
v[0] = theVec2.x();
|
||||
v[1] = theVec2.y();
|
||||
v[2] = theZ;
|
||||
}
|
||||
|
||||
//! Alias to 1st component as X coordinate in XYZ.
|
||||
Element_t x() const { return v[0]; }
|
||||
|
||||
@@ -127,18 +135,6 @@ public:
|
||||
//! Alias to 3rd component as BLUE channel in RGB.
|
||||
Element_t& b() { return v[2]; }
|
||||
|
||||
//! @return XY-components modifiable vector
|
||||
NCollection_Vec2<Element_t>& xy()
|
||||
{
|
||||
return *((NCollection_Vec2<Element_t>* )&v[0]);
|
||||
}
|
||||
|
||||
//! @return YZ-components modifiable vector
|
||||
NCollection_Vec2<Element_t>& yz()
|
||||
{
|
||||
return *((NCollection_Vec2<Element_t>* )&v[1]);
|
||||
}
|
||||
|
||||
//! Check this vector with another vector for equality (without tolerance!).
|
||||
bool IsEqual (const NCollection_Vec3& theOther) const
|
||||
{
|
||||
@@ -295,7 +291,7 @@ public:
|
||||
}
|
||||
|
||||
//! Compute per-component division by scale factor.
|
||||
NCollection_Vec3 operator/ (const Element_t theInvFactor)
|
||||
NCollection_Vec3 operator/ (const Element_t theInvFactor) const
|
||||
{
|
||||
NCollection_Vec3 aResult (*this);
|
||||
return aResult /= theInvFactor;
|
||||
|
@@ -66,18 +66,11 @@ public:
|
||||
v[2] = v[3] = Element_t (0);
|
||||
}
|
||||
|
||||
//! Constructor from 3-components vector.
|
||||
explicit NCollection_Vec4(const NCollection_Vec3<Element_t>& theVec3)
|
||||
//! Constructor from 3-components vector + optional 4th value.
|
||||
explicit NCollection_Vec4(const NCollection_Vec3<Element_t>& theVec3, const Element_t theW = Element_t(0))
|
||||
{
|
||||
std::memcpy (this, &theVec3, sizeof(NCollection_Vec3<Element_t>));
|
||||
v[3] = Element_t (0);
|
||||
}
|
||||
|
||||
//! Constructor from 3-components vector + alpha value.
|
||||
explicit NCollection_Vec4(const NCollection_Vec3<Element_t>& theVec3,
|
||||
const Element_t theAlpha) {
|
||||
std::memcpy (this, &theVec3, sizeof(NCollection_Vec3<Element_t>));
|
||||
v[3] = theAlpha;
|
||||
v[3] = theW;
|
||||
}
|
||||
|
||||
//! Assign new values to the vector.
|
||||
@@ -92,6 +85,15 @@ public:
|
||||
v[3] = theW;
|
||||
}
|
||||
|
||||
//! Assign new values as 3-component vector and a 4-th value.
|
||||
void SetValues (const NCollection_Vec3<Element_t>& theVec3, const Element_t theW)
|
||||
{
|
||||
v[0] = theVec3.x();
|
||||
v[1] = theVec3.y();
|
||||
v[2] = theVec3.z();
|
||||
v[3] = theW;
|
||||
}
|
||||
|
||||
//! Alias to 1st component as X coordinate in XYZW.
|
||||
Element_t x() const { return v[0]; }
|
||||
|
||||
@@ -157,36 +159,6 @@ public:
|
||||
//! Alias to 4th component as ALPHA channel in RGBA.
|
||||
Element_t& a() { return v[3]; }
|
||||
|
||||
//! @return XY-components modifiable vector
|
||||
NCollection_Vec2<Element_t>& xy()
|
||||
{
|
||||
return *((NCollection_Vec2<Element_t>* )&v[0]);
|
||||
}
|
||||
|
||||
//! @return YZ-components modifiable vector
|
||||
NCollection_Vec2<Element_t>& yz()
|
||||
{
|
||||
return *((NCollection_Vec2<Element_t>* )&v[1]);
|
||||
}
|
||||
|
||||
//! @return YZ-components modifiable vector
|
||||
NCollection_Vec2<Element_t>& zw()
|
||||
{
|
||||
return *((NCollection_Vec2<Element_t>* )&v[2]);
|
||||
}
|
||||
|
||||
//! @return XYZ-components modifiable vector
|
||||
NCollection_Vec3<Element_t>& xyz()
|
||||
{
|
||||
return *((NCollection_Vec3<Element_t>* )&v[0]);
|
||||
}
|
||||
|
||||
//! @return YZW-components modifiable vector
|
||||
NCollection_Vec3<Element_t>& yzw()
|
||||
{
|
||||
return *((NCollection_Vec3<Element_t>* )&v[1]);
|
||||
}
|
||||
|
||||
//! Check this vector with another vector for equality (without tolerance!).
|
||||
bool IsEqual (const NCollection_Vec4& theOther) const
|
||||
{
|
||||
|
Reference in New Issue
Block a user