Cumulia Illustrator Rendering Engine v1.0.0
A Rendering engine for industrial CAD/CAE model and optimized for greatest performance
 
Loading...
Searching...
No Matches
box.h
1//##################################################################################################
2//
3// Copyright (c) 2024 Beijing Qiongqi Tech Co.,Ltd. All rights reserved.
4
5// This source code is confidential and proprietary to Beijing Qiongqi Tech Co.,Ltd(The Holder).
6// Any unauthorized use, copying, modification, or distribution of the code is strictly prohibited.
7// Any user shall obtain authorizaition from the Holder before modifying the source code. And the user shall not
8// sublicense, sell, distribute, or transfer the source code, whether in original or modified form, to any third party
9// without the prior written consent of the Holder.
10
11// This copyright notice and permission grant shall be included in all copies or substantial portions of the source code.
12
13// Author Cumulia Illustrator
14// Date 2024-05-01
15// Version V1.0.0
16//##################################################################################################
17
18#pragma once
19
20// bitten by these ancient macros. They can't remove them, that would break old code.
21// https://stackoverflow.com/questions/6884093/warning-c4003-not-enough-actual-parameters-for-macro-max-visual-studio-2010
22#undef min
23#undef max
24
25#include "tuple.h"
26
27namespace cil
28{
29 class Vector2i;
30 class Vector2f;
31 class Vector3i;
32 class Vector3f;
33 class Float32Array;
34
36 template<typename T>
37 class Box : public Tuple<T>
38 {
39 public:
41 Box(int size)
42 : Tuple<T>(size)
43 {
44 }
46 const T& operator[](int index) const
47 {
48 return this->m_data[index];
49 }
51 T& operator[](int index)
52 {
53 return this->m_data[index];
54 }
55 };
56
58 template<typename T, typename S>
59 class Box2 : public Box<T>
60 {
61 public:
64 : Box<T>(4)
65 {
66 }
68 void set(T xmin, T xmax, T ymin, T ymax)
69 {
70 this->m_data[0] = xmin;
71 this->m_data[1] = xmax;
72 this->m_data[2] = ymin;
73 this->m_data[3] = ymax;
74 }
78 void set(const S& min, const S& max)
79 {
80 this->setMin(min);
81 this->setMax(max);
82 }
84 S min() const
85 {
86 return S(this->m_data[0], this->m_data[2]);
87 }
89 void setMin(const S& min)
90 {
91 this->m_data[0] = min.data()[0];
92 this->m_data[2] = min.data()[1];
93 }
95 S max() const
96 {
97 return S(this->m_data[1], this->m_data[3]);
98 }
100 void setMax(const S& max)
101 {
102 this->m_data[1] = max.data()[0];
103 this->m_data[3] = max.data()[1];
104 }
106 S center() const
107 {
108 return (this->min() + this->max()) / 2.0f;
109 }
111 S extent() const
112 {
113 return this->max() - this->min();
114 }
115 };
116
118 class Box2i final : public Box2<int, Vector2i>
119 {
120 public:
122 Box2i(int xmin, int xmax, int ymin, int ymax);
123 Box2i(const Vector2i& min, const Vector2i& max);
124 Box2i(const Box2i& other);
125 };
127 class Box2f final : public Box2<float, Vector2f>
128 {
129 public:
131 Box2f(float xmin, float xmax, float ymin, float ymax);
132 Box2f(const Vector2f& min, const Vector2f& max);
133 Box2f(const Box2f& other);
134 };
135
137 template<typename T, typename S>
138 class Box3 : public Box<T>
139 {
140 public:
143 : Box<T>(6)
144 {
145 }
147 void set(T xmin, T xmax, T ymin, T ymax, T zmin, T zmax)
148 {
149 this->m_data[0] = xmin;
150 this->m_data[1] = xmax;
151 this->m_data[2] = ymin;
152 this->m_data[3] = ymax;
153 this->m_data[4] = zmin;
154 this->m_data[5] = zmax;
155 }
159
160 void set(const S& min, const S& max)
161 {
162 this->setMin(min);
163 this->setMax(max);
164 }
166 S min() const
167 {
168 return S(this->m_data[0], this->m_data[2], this->m_data[4]);
169 }
170
172 void setMin(const S& min)
173 {
174 this->m_data[0] = min.data()[0];
175 this->m_data[2] = min.data()[1];
176 this->m_data[4] = min.data()[2];
177 }
179 S max() const
180 {
181 return S(this->m_data[1], this->m_data[3], this->m_data[5]);
182 }
184 void setMax(const S& max)
185 {
186 this->m_data[1] = max.data()[0];
187 this->m_data[3] = max.data()[1];
188 this->m_data[5] = max.data()[2];
189 }
191 S center() const
192 {
193 return (this->min() + this->max()) / 2.0f;
194 }
196 S extent() const
197 {
198 return this->max() - this->min();
199 }
200 };
201
203 class Box3i final : public Box3<int, Vector3i>
204 {
205 public:
207 Box3i(int xmin, int xmax, int ymin, int ymax, int zmin, int zmax);
208 Box3i(const Vector3i& min, const Vector3i& max);
209 Box3i(const Box3i& other);
210 };
211
213 class Box3f final : public Box3<float, Vector3f>
214 {
215 public:
217 Box3f(float xmin, float xmax, float ymin, float ymax, float zmin, float zmax);
218 Box3f(const Vector3f& min, const Vector3f& max);
219 Box3f(const Box3f& other);
220 };
221
223 class BoundingBox final : public Box3<float, Vector3f>
224 {
225 public:
228 BoundingBox(float xmin, float xmax, float ymin, float ymax, float zmin, float zmax);
230
233
234 bool isValid() const;
235 bool inRange(Vector3f value) const;
236 void addPoint(float x, float y, float z);
237 void addPoint(const Vector3f& point);
238 void addPoints(const Float32Array& points);
239 };
240
241 using box2 = Box2f;
242 using ibox2 = Box2i;
243 using box3 = Box3f;
244 using ibox3 = Box3i;
246}
The BoundingBox class inherits from Box3, specilizing the template parameters to float for element ty...
Definition box.h:224
void addPoints(const Float32Array &points)
bool isValid() const
Check if the bounding box is valid, which means that the minimum extents should be less than or equal...
BoundingBox & operator+=(Vector3f value)
Expands the current bounding box to encompass the minimum and maximum points of the other bounding bo...
bool inRange(Vector3f value) const
Check if a vector3f (a 3D point) is within this boundingbox.
BoundingBox(const Vector3f &min, const Vector3f &max)
void addPoint(const Vector3f &point)
BoundingBox()
Constructs a bounding box object, and initializes it.
BoundingBox(const BoundingBox &other)
BoundingBox(float xmin, float xmax, float ymin, float ymax, float zmin, float zmax)
Constructs a bounding box object with the specified minimum and maximum extents.
BoundingBox & operator+=(const BoundingBox &other)
void addPoint(float x, float y, float z)
The Box2 is a templated class inheriting from the Box class, which represents a rectangular zone.
Definition box.h:60
void set(T xmin, T xmax, T ymin, T ymax)
Sets the four elements of the Box2 object with the four input arguments.
Definition box.h:68
S extent() const
Gets the extent of the Box2 object, which means the length and width of the rectangular zone.
Definition box.h:111
S max() const
Gets the maximum values, namely xmax and ymax, of the Box2 object.
Definition box.h:95
void set(const S &min, const S &max)
Sets the minimum and maximum values of the box.
Definition box.h:78
void setMin(const S &min)
Sets the minimum values, namely xmin and ymin, for the Box2 object.
Definition box.h:89
void setMax(const S &max)
Sets the maximum values, namely xmax and ymax, for the Box2 object.
Definition box.h:100
S center() const
Gets the center of the Box2 object, which means the center of the rectangular zone.
Definition box.h:106
S min() const
Gets the minimum values, namely xmin and ymin, of the Box2 object.
Definition box.h:84
Box2()
Contructs a Box2 object, a specialization of Box for storing 4 elements.
Definition box.h:63
The Box2f class inherits from Box2, specilizing the template parameters to float for element type and...
Definition box.h:128
Box2f()
Constructs a Box2f object, and sets its minimum and maximum extent to(0.0f, 0.0f) and(1....
Box2f(const Vector2f &min, const Vector2f &max)
Box2f(const Box2f &other)
Box2f(float xmin, float xmax, float ymin, float ymax)
The Box2i class inherits from Box2, specilizing the template parameters to int for element type and V...
Definition box.h:119
Box2i(const Box2i &other)
Box2i(const Vector2i &min, const Vector2i &max)
Box2i()
Constructs a Box2i object, and sets its minimum and maximum extent to(0, 0) and(1,...
Box2i(int xmin, int xmax, int ymin, int ymax)
The Box3 is a templated class inheriting from the Box class, which represents a cubic zone.
Definition box.h:139
void setMax(const S &max)
Sets the maximum values, namely xmax, ymax and zmax, for the Box3 object.
Definition box.h:184
void set(const S &min, const S &max)
Sets the minimum and maximum values of the box.
Definition box.h:160
void set(T xmin, T xmax, T ymin, T ymax, T zmin, T zmax)
Sets the six elements of the Box3 object with the six input arguments.
Definition box.h:147
S center() const
Gets the center of the Box3 object, which means the center of the cubic zone.
Definition box.h:191
S max() const
Gets the maximum values, namely xmax, ymax and zmax, of the Box3 object.
Definition box.h:179
S min() const
Gets the minimum values, namely xmin, ymin and zmin, for the Box3 object.
Definition box.h:166
Box3()
Contructs a Box3 object, a specialization of Box for storing 6 elements.
Definition box.h:142
S extent() const
Gets the extent of the Box3 object, which means the length, width and height of the cubic zone.
Definition box.h:196
void setMin(const S &min)
Sets the minimum values, namely xmin, ymin and zmin, for the Box3 object.
Definition box.h:172
The Box3f class inherits from Box3, specilizing the template parameters to float for element type and...
Definition box.h:214
Box3f(float xmin, float xmax, float ymin, float ymax, float zmin, float zmax)
Box3f(const Vector3f &min, const Vector3f &max)
Box3f()
Constructs a Box3f object, and sets its minimum and maximum extent to(0.0f, 0.0f, 0....
Box3f(const Box3f &other)
The Box3i class inherits from Box3, specilizing the template parameters to int for element type and V...
Definition box.h:204
Box3i()
Constructs a Box3i object, and sets its minimum and maximum extent to(0, 0, 0) and(1,...
Box3i(const Box3i &other)
Box3i(int xmin, int xmax, int ymin, int ymax, int zmin, int zmax)
Box3i(const Vector3i &min, const Vector3i &max)
The Box is a templated class inheriting from the Tuple class,from which we can derive box2 and box3 c...
Definition box.h:38
T & operator[](int index)
Provides a read-write access to the element at a specific index(position) within the Box object.
Definition box.h:51
const T & operator[](int index) const
Provides a read-only access to the element at a specific index(position) within the Box object.
Definition box.h:46
Box(int size)
Constructs a box object.
Definition box.h:41
Definition typedarray.h:157
The Tuple is a templated class inheriting from the most basic class Variant.
Definition tuple.h:27
T * m_data
The data array of the Tuple.
Definition tuple.h:35
int size() const
Gets the number of elements of the Tuple.
Definition tuple.h:54
The class Vector2f inherits from the templated class of Vector2, and the template parameters are spec...
Definition vector.h:268
The class Vector2i inherits from the templated class of Vector2, and the template parameters are spec...
Definition vector.h:255
The class Vector3f inherits from the templated class of Vector3, and the template parameters are spec...
Definition vector.h:322
The class Vector3i inherits from the templated class of Vector3, and the template parameters are spec...
Definition vector.h:312
Definition decal.h:23