Skip to content

Commit 1843440

Browse files
authored
Add files via upload
1 parent c3105f8 commit 1843440

File tree

1 file changed

+99
-0
lines changed

1 file changed

+99
-0
lines changed

RadeonRays/include/math/int3.h

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/**********************************************************************
2+
Copyright (c) 2016 Advanced Micro Devices, Inc. All rights reserved.
3+
4+
Permission is hereby granted, free of charge, to any person obtaining a copy
5+
of this software and associated documentation files (the "Software"), to deal
6+
in the Software without restriction, including without limitation the rights
7+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
copies of the Software, and to permit persons to whom the Software is
9+
furnished to do so, subject to the following conditions:
10+
11+
The above copyright notice and this permission notice shall be included in
12+
all copies or substantial portions of the Software.
13+
14+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20+
THE SOFTWARE.
21+
********************************************************************/
22+
#pragma once
23+
24+
#include <cmath>
25+
#include <algorithm>
26+
27+
#include "float3.h"
28+
#include "int2.h"
29+
30+
namespace RadeonRays
31+
{
32+
class int3
33+
{
34+
public:
35+
int3(int xx = 0, int yy = 0, int zz = 0) : x(xx), y(yy), z(zz) {}
36+
int3(int2 v) : x(v.x), y(v.y), z(0) {}
37+
38+
int& operator [](int i) { return *(&x + i); }
39+
int operator [](int i) const { return *(&x + i); }
40+
int3 operator-() const { return int3(-x, -y, -z); }
41+
42+
int sqnorm() const { return x*x + y*y; }
43+
44+
operator float3() { return float3((float)x, (float)y, (float)z); }
45+
46+
int3& operator += (int3 const& o) { x += o.x; y += o.y; z += o.z; return *this; }
47+
int3& operator -= (int3 const& o) { x -= o.x; y -= o.y; z -= o.z; return *this; }
48+
int3& operator *= (int3 const& o) { x *= o.x; y *= o.y; z *= o.z; return *this; }
49+
int3& operator *= (int c) { x *= c; y *= c; z *= c; return *this; }
50+
51+
int x, y, z;
52+
};
53+
54+
55+
inline int3 operator+(int3 const& v1, int3 const& v2)
56+
{
57+
int3 res = v1;
58+
return res+=v2;
59+
}
60+
61+
inline int3 operator-(int3 const& v1, int3 const& v2)
62+
{
63+
int3 res = v1;
64+
return res-=v2;
65+
}
66+
67+
inline int3 operator*(int3 const& v1, int3 const& v2)
68+
{
69+
int3 res = v1;
70+
return res*=v2;
71+
}
72+
73+
inline int3 operator*(int3 const& v1, int c)
74+
{
75+
int3 res = v1;
76+
return res*=c;
77+
}
78+
79+
inline int3 operator*(int c, int3 const& v1)
80+
{
81+
return operator*(v1, c);
82+
}
83+
84+
inline int dot(int3 const& v1, int3 const& v2)
85+
{
86+
return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z;
87+
}
88+
89+
90+
inline int3 vmin(int3 const& v1, int3 const& v2)
91+
{
92+
return int3(std::min(v1.x, v2.x), std::min(v1.y, v2.y), std::min(v1.z, v2.z));
93+
}
94+
95+
inline int3 vmax(int3 const& v1, int3 const& v2)
96+
{
97+
return int3(std::max(v1.x, v2.x), std::max(v1.y, v2.y), std::max(v1.z, v2.z));
98+
}
99+
}

0 commit comments

Comments
 (0)