13#include <vector_types.h>
19__host__ __device__ __forceinline__ float3 operator+(
const float3 &a,
const float3 &b) {
20 return make_float3(a.x + b.x, a.y + b.y, a.z + b.z);
22__host__ __device__ __forceinline__ float3
operator-(
const float3 &a,
const float3 &b) {
23 return make_float3(a.x - b.x, a.y - b.y, a.z - b.z);
25__host__ __device__ __forceinline__ float3
operator*(
const float3 &a,
float s) {
26 return make_float3(a.x * s, a.y * s, a.z * s);
28__host__ __device__ __forceinline__ float3
operator*(
float s,
const float3 &a) {
29 return make_float3(a.x * s, a.y * s, a.z * s);
31__host__ __device__ __forceinline__ float3
operator*(
const float3 &a,
const float3 &b) {
32 return make_float3(a.x * b.x, a.y * b.y, a.z * b.z);
34__host__ __device__ __forceinline__ float3
operator/(
const float3 &a,
float s) {
35 return make_float3(a.x / s, a.y / s, a.z / s);
37__host__ __device__ __forceinline__ float3
operator-(
const float3 &a) {
38 return make_float3(-a.x, -a.y, -a.z);
40__host__ __device__ __forceinline__ float3 &operator+=(float3 &a,
const float3 &b) {
41 a.x += b.x; a.y += b.y; a.z += b.z;
return a;
43__host__ __device__ __forceinline__ float3 &operator-=(float3 &a,
const float3 &b) {
44 a.x -= b.x; a.y -= b.y; a.z -= b.z;
return a;
46__host__ __device__ __forceinline__ float3 &operator*=(float3 &a,
float s) {
47 a.x *= s; a.y *= s; a.z *= s;
return a;
54__host__ __device__ __forceinline__ float2 operator+(
const float2 &a,
const float2 &b) {
55 return make_float2(a.x + b.x, a.y + b.y);
57__host__ __device__ __forceinline__ float2
operator-(
const float2 &a,
const float2 &b) {
58 return make_float2(a.x - b.x, a.y - b.y);
60__host__ __device__ __forceinline__ float2
operator*(
const float2 &a,
float s) {
61 return make_float2(a.x * s, a.y * s);
63__host__ __device__ __forceinline__ float2
operator*(
float s,
const float2 &a) {
64 return make_float2(a.x * s, a.y * s);
71__host__ __device__ __forceinline__
float dot(
const float3 &a,
const float3 &b) {
72 return a.x * b.x + a.y * b.y + a.z * b.z;
75__host__ __device__ __forceinline__ float3
cross(
const float3 &a,
const float3 &b) {
77 a.y * b.z - a.z * b.y,
78 a.z * b.x - a.x * b.z,
79 a.x * b.y - a.y * b.x);
82__host__ __device__ __forceinline__
float length(
const float3 &v) {
83 return sqrtf(v.x * v.x + v.y * v.y + v.z * v.z);
86__host__ __device__ __forceinline__ float3 normalize(
const float3 &v) {
87 float inv_len = 1.0f / length(v);
91__host__ __device__ __forceinline__
float dot(
const float2 &a,
const float2 &b) {
92 return a.x * b.x + a.y * b.y;