diff --git a/tests/core/000-static-asserts/space.h b/tests/core/000-static-asserts/space.h index 5f48cd254..437437f98 100644 --- a/tests/core/000-static-asserts/space.h +++ b/tests/core/000-static-asserts/space.h @@ -37,6 +37,7 @@ #include "space/segment.h" #include "space/sphere.h" #include "space/tex_coord.h" +#include "space/tex_coord_indexed.h" #include "space/texture.h" void spaceStaticAsserts() @@ -55,6 +56,7 @@ void spaceStaticAsserts() segmentStaticAsserts(); sphereStaticAsserts(); texCoordStaticAsserts(); + texCoordIndexedStaticAsserts(); textureStaticAsserts(); using namespace vcl; diff --git a/tests/core/000-static-asserts/space/tex_coord.h b/tests/core/000-static-asserts/space/tex_coord.h index 6eb0e0b63..d36f5992e 100644 --- a/tests/core/000-static-asserts/space/tex_coord.h +++ b/tests/core/000-static-asserts/space/tex_coord.h @@ -45,6 +45,22 @@ void texCoordStaticAsserts() static_assert( TexCoordConcept, "TexCoordf&& does not satisfy the TexCoordConcept"); + + static_assert( + TexCoordConcept, + "TexCoordIndexedf does not satisfy the TexCoordConcept"); + static_assert( + TexCoordConcept, + "const TexCoordIndexedf does not satisfy the TexCoordConcept"); + static_assert( + TexCoordConcept, + "TexCoordIndexedf& does not satisfy the TexCoordConcept"); + static_assert( + TexCoordConcept, + "const TexCoordIndexedf& does not satisfy the TexCoordConcept"); + static_assert( + TexCoordConcept, + "TexCoordIndexedf&& does not satisfy the TexCoordConcept"); } #endif // TEX_COORD_H diff --git a/tests/core/000-static-asserts/space/tex_coord_indexed.h b/tests/core/000-static-asserts/space/tex_coord_indexed.h new file mode 100644 index 000000000..0837833ce --- /dev/null +++ b/tests/core/000-static-asserts/space/tex_coord_indexed.h @@ -0,0 +1,50 @@ +/***************************************************************************** + * VCLib * + * Visual Computing Library * + * * + * Copyright(C) 2021-2025 * + * Visual Computing Lab * + * ISTI - Italian National Research Council * + * * + * All rights reserved. * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the Mozilla Public License Version 2.0 as published * + * by the Mozilla Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * Mozilla Public License Version 2.0 * + * (https://www.mozilla.org/en-US/MPL/2.0/) for more details. * + ****************************************************************************/ + +#ifndef TEX_COORD_INDEXED_H +#define TEX_COORD_INDEXED_H + +#include + +void texCoordIndexedStaticAsserts() +{ + using namespace vcl; + + // TexCoord concept + static_assert( + TexCoordIndexedConcept, + "TexCoordIndexedf does not satisfy the TexCoordIndexedConcept"); + static_assert( + TexCoordIndexedConcept, + "const TexCoordIndexedf does not satisfy the TexCoordIndexedConcept"); + static_assert( + TexCoordIndexedConcept, + "TexCoordIndexedf& does not satisfy the TexCoordIndexedConcept"); + static_assert( + TexCoordIndexedConcept, + "const TexCoordIndexedf& does not satisfy the TexCoordIndexedConcept"); + static_assert( + TexCoordIndexedConcept, + "TexCoordIndexedf&& does not satisfy the TexCoordIndexedConcept"); +} + +#endif // TEX_COORD_INDEXED_H diff --git a/vclib/core/include/vclib/concepts/space.h b/vclib/core/include/vclib/concepts/space.h index 59f3c441b..50db9dc53 100644 --- a/vclib/core/include/vclib/concepts/space.h +++ b/vclib/core/include/vclib/concepts/space.h @@ -36,6 +36,7 @@ #include "space/segment.h" #include "space/sphere.h" #include "space/tex_coord.h" +#include "space/tex_coord_indexed.h" #include "space/texture.h" #include "space/triangle.h" diff --git a/vclib/core/include/vclib/concepts/space/tex_coord.h b/vclib/core/include/vclib/concepts/space/tex_coord.h index a3ad425ed..fed068c67 100644 --- a/vclib/core/include/vclib/concepts/space/tex_coord.h +++ b/vclib/core/include/vclib/concepts/space/tex_coord.h @@ -31,7 +31,7 @@ namespace vcl { /** * @brief A concept representing a Texture Coordinate. * - * @tparam T: The type to be tested for conformity to the BoxConcept. + * @tparam T: The type to be tested for conformity to the TexCoordConcept. */ template concept TexCoordConcept = requires ( diff --git a/vclib/core/include/vclib/concepts/space/tex_coord_indexed.h b/vclib/core/include/vclib/concepts/space/tex_coord_indexed.h new file mode 100644 index 000000000..2e0e279d3 --- /dev/null +++ b/vclib/core/include/vclib/concepts/space/tex_coord_indexed.h @@ -0,0 +1,60 @@ +/***************************************************************************** + * VCLib * + * Visual Computing Library * + * * + * Copyright(C) 2021-2025 * + * Visual Computing Lab * + * ISTI - Italian National Research Council * + * * + * All rights reserved. * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the Mozilla Public License Version 2.0 as published * + * by the Mozilla Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * Mozilla Public License Version 2.0 * + * (https://www.mozilla.org/en-US/MPL/2.0/) for more details. * + ****************************************************************************/ + +#ifndef VCL_CONCEPTS_SPACE_TEX_COORD_INDEXED_H +#define VCL_CONCEPTS_SPACE_TEX_COORD_INDEXED_H + +#include "tex_coord.h" + +namespace vcl { + +/** + * @brief A concept representing a Texture Coordinate with an index. + * + * @tparam T: The type to be tested for conformity to the TexCoordIndexedConcept. + */ +template +concept TexCoordIndexedConcept = + TexCoordConcept && requires ( + T&& obj, + ushort u, + ushort& uR, + typename RemoveRef::ScalarType s) { + typename RemoveRef::ScalarType; + + RemoveRef(); + RemoveRef(s, s, u); + + { obj.index() } -> std::convertible_to; + + { obj <=> obj } -> std::convertible_to; + + // non const requirements + requires IsConst || requires { + { obj.index() } -> std::same_as; + { obj.set(s, s, u) } -> std::same_as; + }; + }; + +} // namespace vcl + +#endif // VCL_CONCEPTS_SPACE_TEX_COORD_INDEXED_H diff --git a/vclib/core/include/vclib/space/core/tex_coord_indexed.h b/vclib/core/include/vclib/space/core/tex_coord_indexed.h index 193bc0377..70c29526a 100644 --- a/vclib/core/include/vclib/space/core/tex_coord_indexed.h +++ b/vclib/core/include/vclib/space/core/tex_coord_indexed.h @@ -49,6 +49,7 @@ class TexCoordIndexed : public TexCoord public: using Base::Base; + using Base::set; using Base::operator(); using Base::operator[]; @@ -86,6 +87,12 @@ class TexCoordIndexed : public TexCoord ushort& index() { return mIndex; } + void set(const Scalar& s1, const Scalar& s2, ushort index) + { + Base::set(s1, s2); + mIndex = index; + } + void serialize(std::ostream& os) const { Base::serialize(os); @@ -102,6 +109,12 @@ class TexCoordIndexed : public TexCoord auto operator<=>(const TexCoordIndexed& t1) const = default; }; +/* Specialization Aliases */ + +using TexCoordIndexedi = TexCoordIndexed; +using TexCoordIndexedf = TexCoordIndexed; +using TexCoordIndexedd = TexCoordIndexed; + } // namespace vcl #endif // VCL_SPACE_CORE_TEX_COORD_INDEXED_H