QUGaR 0.1.3
Loading...
Searching...
No Matches
bbox.hpp
Go to the documentation of this file.
1// --------------------------------------------------------------------------
2//
3// Copyright (C) 2025-present by Pablo Antolin
4//
5// This file is part of the QUGaR library.
6//
7// SPDX-License-Identifier: MIT
8//
9// --------------------------------------------------------------------------
10
11#ifndef QUGAR_LIBRARY_BBOX_HPP
12
13#define QUGAR_LIBRARY_BBOX_HPP
14
21
22
23#include <qugar/concepts.hpp>
24#include <qugar/point.hpp>
25#include <qugar/types.hpp>
26
27#include <algoim/hyperrectangle.hpp>
28
29#include <array>
30#include <cstddef>
31
32namespace qugar {
33
37template<int dim> class BoundBox
38{
39
40public:
42
43
46
50 BoundBox(const std::array<real, static_cast<std::size_t>(dim)> &min,
51 const std::array<real, static_cast<std::size_t>(dim)> &max);
52
56 BoundBox(const real min, const real max);
57
62
71 explicit BoundBox(const ::algoim::HyperRectangle<real, dim> &rectangle);
72
74
75private:
78
81
82public:
86 void set(const Point<dim> &min, const Point<dim> &max);
87
91 void extend(const Point<dim> &point);
92
94
95
98 [[nodiscard]] real min(int dir) const;
99
103 [[nodiscard]] real max(int dir) const;
104
107 template<int dim_aux = dim>
108 requires Is1D<dim_aux, dim>
109 [[nodiscard]] real min() const;
110
113 template<int dim_aux = dim>
114 requires Is1D<dim_aux, dim>
115 [[nodiscard]] real max() const;
116
119 [[nodiscard]] const Point<dim> &min_corner() const;
120
123 [[nodiscard]] const Point<dim> &max_corner() const;
124
128 [[nodiscard]] BoundBox<dim> extend(real delta) const;
129
137 ::algoim::HyperRectangle<real, dim> to_hyperrectangle() const;
138
145 [[nodiscard]] Point<dim> get_lengths() const;
146
150 [[nodiscard]] real length(int dir) const;
151
154 template<int dim_aux = dim>
155 requires Is1D<dim_aux, dim>
156 [[nodiscard]] real length() const;
157
160 [[nodiscard]] real volume() const;
161
164 [[nodiscard]] Point<dim> mid_point() const;
165
170 [[nodiscard]] Point<dim> scale_to_new_domain(const BoundBox<dim> &new_domain, const Point<dim> &point) const;
171
175 [[nodiscard]] Point<dim> scale_to_0_1(const Point<dim> &point) const;
176
180 [[nodiscard]] Point<dim> scale_from_0_1(const Point<dim> &point_01) const;
181
184 template<int dim_aux = dim>
185 requires(dim_aux == dim && dim > 1)
186 [[nodiscard]] BoundBox<dim - 1> slice(const int const_dir) const
187 {
188 Point<dim - 1> _min_corner;
189 Point<dim - 1> _max_corner;
190 for (int dir = 0, dir2 = 0; dir < dim; ++dir) {
191 if (dir != const_dir) {
192 _min_corner(dir2) = this->min(dir);
193 _max_corner(dir2) = this->max(dir);
194 ++dir2;
195 }
196 }
197 return BoundBox<dim - 1>(_min_corner, _max_corner);
198 }
199
200
202};
203
206
207}// namespace qugar
208
209#endif// QUGAR_LIBRARY_BBOX_HPP
Class representing a dim-dimensional Cartesian product bounding box.
Definition bbox.hpp:38
Point< dim > scale_to_new_domain(const BoundBox< dim > &new_domain, const Point< dim > &point) const
Scales the given point from the current domain to the new_domain.
real max() const
Gets the maxnimum value of the box for 1D boxes.
real length(int dir) const
Gets the box length along the given direction.
real max(int dir) const
Point< dim > get_lengths() const
Retrieves the lengths of the bounding box along each dimension.
BoundBox()
Construct a new default BoundBox. Initializes the box to the unit_ domain [0, 1].
Point< dim > mid_point() const
Gets the mid point of the box.
BoundBox(const ::algoim::HyperRectangle< real, dim > &rectangle)
Constructs a BoundBox from a given Algoim's hyperrectangle.
Point< dim > max_
Definition bbox.hpp:80
Point< dim > scale_to_0_1(const Point< dim > &point) const
Scales the given point from the current domain to the [0,1]^dim domain.
BoundBox(const Point< dim > &min, const Point< dim > &max)
Construct a new BoundBox object from the max and min coordinates.
BoundBox< dim > extend(real delta) const
Extends the current bounding box by a given +/- delta on each side.
::algoim::HyperRectangle< real, dim > to_hyperrectangle() const
Converts the current object to an Algoim's hyperrectangle.
BoundBox< dim - 1 > slice(const int const_dir) const
Performs a slice of the domain reduding it by one dimension.
Definition bbox.hpp:186
BoundBox(const std::array< real, static_cast< std::size_t >(dim)> &min, const std::array< real, static_cast< std::size_t >(dim)> &max)
Construct a new BoundBox object from the max and min coordinates.
Point< dim > min_
Definition bbox.hpp:77
Point< dim > scale_from_0_1(const Point< dim > &point_01) const
Scales the given point from the [0,1]^dim domain to the current domain.
real volume() const
Computes the box volume.
real length() const
Gets the box length for 1D boxes.
void extend(const Point< dim > &point)
Expands the current bounding box such that it contains the given point.
real min() const
Gets the minimum value of the box for 1D boxes.
const Point< dim > & max_corner() const
Gets the maximum bounds along all the directions.
const Point< dim > & min_corner() const
Gets the minimum bounds along all the directions.
BoundBox(const real min, const real max)
Construct a new BoundBox object from the max and min coordinates.
real min(int dir) const
void set(const Point< dim > &min, const Point< dim > &max)
Sets the bounds of the domain.
Checks if the given dimension is 1.
Definition concepts.hpp:19
Declaration of concepts.
QUGaR's main namespace.
Definition affine_transf.hpp:28
double real
Definition types.hpp:18
BoundBox< 1 > Interval
Alias representing an interval as a 1-dimensional bounding box.
Definition bbox.hpp:205
Vector< T, dim > Point
Class representing a dim-dimensional Point.
Definition point.hpp:34
Definition and implementation of Point class.
Declaration of types.