Skip to content

Commit

Permalink
Added comparison opertors and single value constructors to vec2, vec3…
Browse files Browse the repository at this point in the history
… and vec4.
  • Loading branch information
AndrewRichards-Code committed Nov 27, 2024
1 parent 4652ccd commit e8570d3
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 0 deletions.
23 changes: 23 additions & 0 deletions CrossPlatform/Shaders/vec2.sl
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ struct tvector2
this->x = x;
this->y = y;
}
tvector2(T v)
{
x = v;
y = v;
}
tvector2(const T *v)
{
x = v[0];
Expand Down Expand Up @@ -51,6 +56,24 @@ struct tvector2
return (x != v.x || y != v.y);
}

// Comparison operators
bool operator<(const tvector2 &v) const
{
return (x < v.x && y < v.y);
}
bool operator>(const tvector2 &v) const
{
return (x > v.x && y > v.y);
}
bool operator<=(const tvector2 &v) const
{
return (x <= v.x && y <= v.y);
}
bool operator>=(const tvector2 &v) const
{
return (x >= v.x && y >= v.y);
}

// Implicit conversions
operator T *()
{
Expand Down
24 changes: 24 additions & 0 deletions CrossPlatform/Shaders/vec3.sl
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ struct tvector3
this->y = y;
this->z = z;
}
tvector3(T v)
{
x = v;
y = v;
z = v;
}
tvector3(const T *v)
{
x = v[0];
Expand Down Expand Up @@ -57,6 +63,24 @@ struct tvector3
return (x != v.x || y != v.y || z != v.z);
}

// Comparison operators
bool operator<(const tvector3 &v) const
{
return (x < v.x && y < v.y && z < v.z);
}
bool operator>(const tvector3 &v) const
{
return (x > v.x && y > v.y && z > v.z);
}
bool operator<=(const tvector3 &v) const
{
return (x <= v.x && y <= v.y && z <= v.z);
}
bool operator>=(const tvector3 &v) const
{
return (x >= v.x && y >= v.y && z >= v.z);
}

// Implicit conversions
operator T *()
{
Expand Down
25 changes: 25 additions & 0 deletions CrossPlatform/Shaders/vec4.sl
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ struct tvector4
this->z = v.z;
this->w = w;
}
tvector4(T v)
{
x = v;
y = v;
z = v;
w = v;
}
tvector4(const T *v)
{
x = v[0];
Expand Down Expand Up @@ -81,6 +88,24 @@ struct tvector4
return (x != v.x || y != v.y || z != v.z || w != v.w);
}

// Comparison operators
bool operator<(const tvector4 &v) const
{
return (x < v.x && y < v.y && z < v.z && z < v.w);
}
bool operator>(const tvector4 &v) const
{
return (x > v.x && y > v.y && z > v.z && z > v.w);
}
bool operator<=(const tvector4 &v) const
{
return (x <= v.x && y <= v.y && z <= v.z && z <= v.w);
}
bool operator>=(const tvector4 &v) const
{
return (x >= v.x && y >= v.y && z >= v.z && z >= v.w);
}

// Implicit conversions
operator T *()
{
Expand Down

0 comments on commit e8570d3

Please sign in to comment.