Visual Computing Library
Loading...
Searching...
No Matches
point.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_POINT_H
24#define VCL_CONCEPTS_SPACE_POINT_H
25
26#include <vclib/concepts/const_correctness.h>
27#include <vclib/concepts/iterators.h>
28#include <vclib/types.h>
29
30namespace vcl {
31
39template<typename T>
40concept PointConcept = requires (
41 T&& obj,
42 typename RemoveRef<T>::ScalarType s,
43 typename RemoveRef<T>::ScalarType& sR,
44 typename RemoveRef<T>::BaseMatrixType& baseObjR) {
45 // inner types
46 typename RemoveRef<T>::ScalarType;
47 typename RemoveRef<T>::BaseMatrixType;
48
49 obj.DIM;
50
51 RemoveRef<T>();
52 RemoveRef<T>(obj);
53
54 { obj.isDegenerate() } -> std::same_as<bool>;
55 { obj.dot(obj) } -> std::same_as<decltype(s)>;
56 { obj.angle(obj) } -> std::same_as<decltype(s)>;
57 { obj.dist(obj) } -> std::same_as<decltype(s)>;
58 { obj.squaredDist(obj) } -> std::same_as<decltype(s)>;
59 { obj.norm() } -> std::same_as<decltype(s)>;
60 { obj.squaredNorm() } -> std::same_as<decltype(s)>;
61 { obj.size() } -> std::same_as<uint>;
62
63 { obj.hash() } -> std::same_as<std::size_t>;
64
65 { obj(uint()) } -> std::convertible_to<decltype(s)>;
66 { obj[uint()] } -> std::convertible_to<decltype(s)>;
67
68 { obj == obj } -> std::same_as<bool>;
69 { obj <=> obj } -> std::convertible_to<std::partial_ordering>;
70
71 { obj.normalized() } -> std::convertible_to<RemoveRef<T>>;
72 { obj + s } -> std::convertible_to<RemoveRef<T>>;
73 { obj + obj } -> std::convertible_to<RemoveRef<T>>;
74
75 { -obj } -> std::convertible_to<RemoveRef<T>>;
76 { obj - s } -> std::convertible_to<RemoveRef<T>>;
77 { obj - obj } -> std::convertible_to<RemoveRef<T>>;
78
79 { obj* s } -> std::convertible_to<RemoveRef<T>>;
80
81 { obj / s } -> std::convertible_to<RemoveRef<T>>;
82
83 // non const requirements
84 requires IsConst<T> || requires {
85 { obj.setConstant(s) } -> std::same_as<decltype(baseObjR)>;
86 { obj.setZero() } -> std::same_as<decltype(baseObjR)>;
87 { obj.setOnes() } -> std::same_as<decltype(baseObjR)>;
88 { obj.normalize() } -> std::same_as<void>;
89
90 { obj(uint()) } -> std::same_as<decltype(sR)>;
91 { obj[uint()] } -> std::same_as<decltype(sR)>;
92
93 { obj = obj } -> std::same_as<T&>;
94
95 { obj += s } -> std::same_as<T&>;
96 { obj += obj } -> std::same_as<decltype(baseObjR)>;
97
98 { obj -= s } -> std::same_as<T&>;
99 { obj -= obj } -> std::same_as<decltype(baseObjR)>;
100
101 { obj *= s } -> std::same_as<decltype(baseObjR)>;
102 { obj /= s } -> std::same_as<decltype(baseObjR)>;
103 };
104};
105
116template<typename T>
117concept Point2Concept = PointConcept<T> && RemoveRef<T>::DIM == 2;
118
129template<typename T>
131 PointConcept<T> && RemoveRef<T>::DIM == 3 && requires (T&& obj) {
132 { obj.cross(obj) } -> std::convertible_to<RemoveRef<T>>;
133 };
134
145template<typename T>
146concept Point4Concept = PointConcept<T> && RemoveRef<T>::DIM == 4;
147
159template<typename It>
162
175template<typename It>
178
191template<typename It>
194
207template<typename It>
210
211} // namespace vcl
212
213#endif // VCL_CONCEPTS_SPACE_POINT_H
The IsConst concept is satisfied if T satisfies one of the following conditions:
Definition const_correctness.h:43
The IteratorConcept is satisfied if T is an input or output iterator.
Definition iterators.h:37
Concept for points in two-dimensional space.
Definition point.h:117
Concept for iterators that iterate over 2D Points (class that satisfies the vcl::Point2Concept).
Definition point.h:176
Concept for points in three-dimensional space.
Definition point.h:130
Concept for iterators that iterate over 3D Points (class that satisfies the vcl::Point3Concept).
Definition point.h:192
Concept for points in four-dimensional space.
Definition point.h:146
Concept for iterators that iterate over 4D Points (class that satisfies the vcl::Point4Concept).
Definition point.h:208
Concept for types representing points in Euclidean space.
Definition point.h:40
Concept for iterators that iterate over Points (class that satisfies the vcl::PointConcept).
Definition point.h:160