Visual Computing Library
Loading...
Searching...
No Matches
segment.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_SEGMENT_H
24#define VCL_CONCEPTS_SPACE_SEGMENT_H
25
26#include "point.h"
27
28namespace vcl {
29
35template<typename T>
36concept SegmentConcept = requires (
37 T&& obj,
38 typename RemoveRef<T>::PointType p,
39 typename RemoveRef<T>::ScalarType s) {
40 typename RemoveRef<T>::PointType;
41 typename RemoveRef<T>::ScalarType;
42
43 obj.DIM;
44
45 RemoveRef<T>();
46 RemoveRef<T>(p, p);
47
48 { obj.p0() } -> PointConcept;
49 { obj.p1() } -> PointConcept;
50
51 { obj.midPoint() } -> PointConcept;
52 { obj.direction() } -> PointConcept;
53 { obj.normalizedDirection() } -> PointConcept;
54 { obj.length() } -> std::same_as<decltype(s)>;
55 { obj.squaredLength() } -> std::same_as<decltype(s)>;
56
57 { obj == obj } -> std::same_as<bool>;
58 { obj != obj } -> std::same_as<bool>;
59
60 { obj + obj } -> std::convertible_to<RemoveRef<T>>;
61 { obj - obj } -> std::convertible_to<RemoveRef<T>>;
62 { obj* s } -> std::convertible_to<RemoveRef<T>>;
63 { obj / s } -> std::convertible_to<RemoveRef<T>>;
64
65 // non const requirements
66 requires IsConst<T> || requires {
67 { obj.flip() } -> std::same_as<void>;
68
69 { obj = obj } -> std::same_as<T&>;
70
71 { obj += obj } -> std::same_as<T&>;
72 { obj -= obj } -> std::same_as<T&>;
73 { obj *= s } -> std::same_as<T&>;
74 { obj /= s } -> std::same_as<T&>;
75 };
76};
77
90template<typename T>
91concept Segment2Concept = SegmentConcept<T> && RemoveRef<T>::DIM == 2;
92
105template<typename T>
106concept Segment3Concept = SegmentConcept<T> && RemoveRef<T>::DIM == 3;
107
108} // namespace vcl
109
110#endif // VCL_CONCEPTS_SPACE_SEGMENT_H
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
A concept to check whether a type meets the requirements of a 2D segment.
Definition segment.h:91
A concept to check whether a type meets the requirements of a 3D segment.
Definition segment.h:106
Concept for types representing line segments in Euclidean space.
Definition segment.h:36