-
Notifications
You must be signed in to change notification settings - Fork 0
/
interval.h
32 lines (24 loc) · 789 Bytes
/
interval.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
//
// Created by leo on 3/3/24.
//
#ifndef RAY_TRACING_IN_ONE_WEEKEND_CUDA_INTERVAL_H
#define RAY_TRACING_IN_ONE_WEEKEND_CUDA_INTERVAL_H
#include "rtweekend.h"
class interval {
public:
float min, max;
__host__ __device__ interval() : min(+infinity), max(-infinity) {} // Default interval is empty
__host__ __device__ interval(float _min, float _max) : min(_min), max(_max) {}
__host__ __device__ bool contains(float x) const {
return min <= x && x <= max;
}
__host__ __device__ bool surrounds(float x) const {
return min < x && x < max;
}
__host__ __device__ float clamp(float x) const {
if (x < min) return min;
if (x > max) return max;
return x;
}
};
#endif //RAY_TRACING_IN_ONE_WEEKEND_CUDA_INTERVAL_H