Visual Computing Library
Loading...
Searching...
No Matches
box.h
1/*****************************************************************************
2 * VCLib *
3 * Visual Computing Library *
4 * *
5 * Copyright(C) 2021-2025 *
6 * Visual Computing Lab *
7 * ISTI - Italian National Research Council *
8 * *
9 * All rights reserved. *
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the Mozilla Public License Version 2.0 as published *
13 * by the Mozilla Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 * This program is distributed in the hope that it will be useful, *
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
19 * Mozilla Public License Version 2.0 *
20 * (https://www.mozilla.org/en-US/MPL/2.0/) for more details. *
21 ****************************************************************************/
22
23#ifndef VCL_CONCEPTS_SPACE_BOX_H
24#define VCL_CONCEPTS_SPACE_BOX_H
25
26#include "point.h"
27
28#include <vclib/types.h>
29
30namespace vcl {
31
42template<typename T>
43concept BoxConcept = requires (
44 T&& obj,
45 typename RemoveRef<T>::PointType p,
46 typename RemoveRef<T>::PointType& pR,
47 typename RemoveRef<T>::PointType::ScalarType s) {
48 typename RemoveRef<T>::PointType;
49 obj.DIM;
50
51 // Constructors
52 RemoveRef<T>();
53 RemoveRef<T>(p);
54 RemoveRef<T>(p, p);
55
56 // Accessors for the minimum and maximum corners of the box.
57 { obj.min() } -> PointConcept;
58 { obj.max() } -> PointConcept;
59
60 // Boolean tests for the nullity and emptiness of the box.
61 { obj.isNull() } -> std::same_as<bool>;
62 { obj.isEmpty() } -> std::same_as<bool>;
63
64 // Boolean tests for whether a point lies inside or outside the box.
65 { obj.isInside(p) } -> std::same_as<bool>;
66 { obj.isInsideOpenBox(p) } -> std::same_as<bool>;
67
68 // Boolean tests for whether two boxes overlap with each other.
69 { obj.overlap(obj) } -> std::same_as<bool>;
70 { obj.collide(obj) } -> std::same_as<bool>;
71 { obj.intersects(obj) } -> std::same_as<bool>;
72
73 // Accessors for various properties of the box.
74 { obj.diagonal() } -> std::same_as<decltype(s)>;
75 { obj.squaredDiagonal() } -> std::same_as<decltype(s)>;
76 { obj.center() } -> PointConcept;
77 { obj.size() } -> PointConcept;
78 { obj.volume() } -> std::convertible_to<decltype(s)>;
79 { obj.dim(uint()) } -> std::convertible_to<decltype(s)>;
80 { obj.minDim() } -> std::convertible_to<decltype(s)>;
81 { obj.maxDim() } -> std::convertible_to<decltype(s)>;
82 { obj.intersection(obj) } -> std::convertible_to<RemoveRef<T>>;
83
84 // Comparison operators.
85 { obj == obj } -> std::same_as<bool>;
86 { obj != obj } -> std::same_as<bool>;
87
88 // non const requirements
89 requires IsConst<T> || requires {
90 { obj.min() } -> std::same_as<decltype(pR)>;
91 { obj.max() } -> std::same_as<decltype(pR)>;
92
93 // Mutators for modifying the state of the box.
94 { obj.setNull() } -> std::same_as<void>;
95 { obj.add(p) } -> std::same_as<void>;
96 { obj.add(p, s) } -> std::same_as<void>;
97 { obj.add(obj) } -> std::same_as<void>;
98 { obj.translate(p) } -> std::same_as<void>;
99 };
100};
101
112template<typename T>
113concept Box2Concept = BoxConcept<T> && RemoveRef<T>::DIM == 2;
114
125template<typename T>
126concept Box3Concept = BoxConcept<T> && RemoveRef<T>::DIM == 3;
127
128} // namespace vcl
129
130#endif // VCL_CONCEPTS_SPACE_BOX_H
A concept that requires a type to satisfy the BoxConcept and have a dimension of 2.
Definition box.h:113
A concept that requires a type to satisfy the BoxConcept and have a dimension of 3.
Definition box.h:126
A concept representing a N-Dimensional Box.
Definition box.h:43
The IsConst concept is satisfied if T satisfies one of the following conditions:
Definition const_correctness.h:43
Concept for types representing points in Euclidean space.
Definition point.h:40