Visual Computing Library
All Classes Functions Variables Typedefs Enumerations Friends Modules Pages Concepts
min_max.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_MATH_MIN_MAX_H
24#define VCL_MATH_MIN_MAX_H
25
26#include <vclib/concepts/space/point.h>
27
28#include <algorithm>
29
30namespace vcl {
31
41template<typename T>
42constexpr auto min(const T& p1, const T& p2)
43{
44 return std::min(p1, p2);
45}
46
66template<typename Head, typename... Tail>
67constexpr auto min(const Head& head0, const Head& head1, const Tail&... tail)
68 requires (sizeof...(tail) > 0)
69{
70 return min(min(head0, head1), tail...);
71}
72
82template<typename T>
83constexpr auto max(const T& p1, const T& p2)
84{
85 return std::max(p1, p2);
86}
87
107template<typename Head, typename... Tail>
108constexpr auto max(const Head& head0, const Head& head1, const Tail&... tail)
109 requires (sizeof...(tail) > 0)
110{
111 return max(max(head0, head1), tail...);
112}
113
126template<PointConcept PointType>
127constexpr auto min(const PointType& p1, const PointType& p2)
128{
129 PointType p;
130 for (size_t i = 0; i < p.DIM; i++) {
131 p[i] = std::min(p1[i], p2[i]);
132 }
133 return p;
134}
135
148template<PointConcept PointType>
149constexpr auto max(const PointType& p1, const PointType& p2)
150{
151 PointType p;
152 for (size_t i = 0; i < p.DIM; i++) {
153 p[i] = std::max(p1[i], p2[i]);
154 }
155 return p;
156}
157
158} // namespace vcl
159
160#endif // VCL_MATH_MIN_MAX_H
A class representing a line segment in n-dimensional space. The class is parameterized by a PointConc...
Definition segment.h:43
static const uint DIM
The dimensionality of the segment.
Definition segment.h:62
constexpr auto max(const T &p1, const T &p2)
Returns the maximum between the two parameters.
Definition min_max.h:83
constexpr auto min(const T &p1, const T &p2)
Returns the minimum between the two parameters.
Definition min_max.h:42