Visual Computing Library
Loading...
Searching...
No Matches
tex_coord.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_SPACE_CORE_TEX_COORD_H
24#define VCL_SPACE_CORE_TEX_COORD_H
25
26#include "point.h"
27
28namespace vcl {
29
48// TODO: TexCoord should inherit from Point2
49template<typename Scalar>
51{
52 template<typename S>
53 friend class TexCoord;
54
55 Point2<Scalar> mCoord;
56
57public:
58 using ScalarType = Scalar;
59
60 TexCoord() = default;
61
62 TexCoord(const Scalar& s1, const Scalar& s2) : mCoord(s1, s2) {}
63
64 TexCoord(const Point2<Scalar>& p) : mCoord(p) {}
65
66 template<typename S>
67 auto cast() const
68 {
69 if constexpr (std::is_same<Scalar, S>::value) {
70 return *this;
71 }
72 else {
74 tmp.mCoord = mCoord.template cast<S>();
75 return tmp;
76 }
77 }
78
79 Scalar u() const { return mCoord.x(); }
80
81 Scalar v() const { return mCoord.y(); }
82
83 Scalar& u() { return mCoord.x(); }
84
85 Scalar& v() { return mCoord.y(); }
86
87 void setU(Scalar s)
88 {
89 assert(s >= 0 && s <= 1);
90 mCoord.x() = s;
91 }
92
93 void setV(Scalar s)
94 {
95 assert(s >= 0 && s <= 1);
96 mCoord.y() = s;
97 }
98
99 void set(Scalar u, Scalar v)
100 {
101 setU(u);
102 setV(v);
103 }
104
105 void serialize(std::ostream& os) const { mCoord.serialize(os); }
106
107 void deserialize(std::istream& is) { mCoord.deserialize(is); }
108
109 // operators
110 Scalar& operator()(uint i) { return mCoord[i]; }
111
112 const Scalar& operator()(uint i) const { return mCoord[i]; }
113
114 Scalar& operator[](uint i) { return mCoord[i]; }
115
116 const Scalar& operator[](uint i) const { return mCoord[i]; }
117
118 auto operator<=>(const TexCoord& t1) const = default;
119};
120
121/* Specialization Aliases */
122
126
127} // namespace vcl
128
129#endif // VCL_SPACE_CORE_TEX_COORD_H
A class representing a line segment in n-dimensional space. The class is parameterized by a PointConc...
Definition segment.h:43
The TexCoord class represents a 2-dimensional texture coordinate containing two scalar values.
Definition tex_coord.h:51