Skip to content

Commit

Permalink
[concepts] Add TexCoordIndexedConcept
Browse files Browse the repository at this point in the history
  • Loading branch information
alemuntoni committed Jan 26, 2025
1 parent a9ca363 commit 28549eb
Show file tree
Hide file tree
Showing 7 changed files with 143 additions and 1 deletion.
2 changes: 2 additions & 0 deletions tests/core/000-static-asserts/space.h
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -55,6 +56,7 @@ void spaceStaticAsserts()
segmentStaticAsserts();
sphereStaticAsserts();
texCoordStaticAsserts();
texCoordIndexedStaticAsserts();
textureStaticAsserts();

using namespace vcl;
Expand Down
16 changes: 16 additions & 0 deletions tests/core/000-static-asserts/space/tex_coord.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,22 @@ void texCoordStaticAsserts()
static_assert(
TexCoordConcept<TexCoordf&&>,
"TexCoordf&& does not satisfy the TexCoordConcept");

static_assert(
TexCoordConcept<TexCoordIndexedf>,
"TexCoordIndexedf does not satisfy the TexCoordConcept");
static_assert(
TexCoordConcept<const TexCoordIndexedf>,
"const TexCoordIndexedf does not satisfy the TexCoordConcept");
static_assert(
TexCoordConcept<TexCoordIndexedf&>,
"TexCoordIndexedf& does not satisfy the TexCoordConcept");
static_assert(
TexCoordConcept<const TexCoordIndexedf&>,
"const TexCoordIndexedf& does not satisfy the TexCoordConcept");
static_assert(
TexCoordConcept<TexCoordIndexedf&&>,
"TexCoordIndexedf&& does not satisfy the TexCoordConcept");
}

#endif // TEX_COORD_H
50 changes: 50 additions & 0 deletions tests/core/000-static-asserts/space/tex_coord_indexed.h
Original file line number Diff line number Diff line change
@@ -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 <vclib/space.h>

void texCoordIndexedStaticAsserts()
{
using namespace vcl;

// TexCoord concept
static_assert(
TexCoordIndexedConcept<TexCoordIndexedf>,
"TexCoordIndexedf does not satisfy the TexCoordIndexedConcept");
static_assert(
TexCoordIndexedConcept<const TexCoordIndexedf>,
"const TexCoordIndexedf does not satisfy the TexCoordIndexedConcept");
static_assert(
TexCoordIndexedConcept<TexCoordIndexedf&>,
"TexCoordIndexedf& does not satisfy the TexCoordIndexedConcept");
static_assert(
TexCoordIndexedConcept<const TexCoordIndexedf&>,
"const TexCoordIndexedf& does not satisfy the TexCoordIndexedConcept");
static_assert(
TexCoordIndexedConcept<TexCoordIndexedf&&>,
"TexCoordIndexedf&& does not satisfy the TexCoordIndexedConcept");
}

#endif // TEX_COORD_INDEXED_H
1 change: 1 addition & 0 deletions vclib/core/include/vclib/concepts/space.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
2 changes: 1 addition & 1 deletion vclib/core/include/vclib/concepts/space/tex_coord.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<typename T>
concept TexCoordConcept = requires (
Expand Down
60 changes: 60 additions & 0 deletions vclib/core/include/vclib/concepts/space/tex_coord_indexed.h
Original file line number Diff line number Diff line change
@@ -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<typename T>
concept TexCoordIndexedConcept =
TexCoordConcept<T> && requires (
T&& obj,
ushort u,
ushort& uR,
typename RemoveRef<T>::ScalarType s) {
typename RemoveRef<T>::ScalarType;

RemoveRef<T>();
RemoveRef<T>(s, s, u);

{ obj.index() } -> std::convertible_to<decltype(u)>;

{ obj <=> obj } -> std::convertible_to<std::partial_ordering>;

// non const requirements
requires IsConst<T> || requires {
{ obj.index() } -> std::same_as<decltype(uR)>;
{ obj.set(s, s, u) } -> std::same_as<void>;
};
};

} // namespace vcl

#endif // VCL_CONCEPTS_SPACE_TEX_COORD_INDEXED_H
13 changes: 13 additions & 0 deletions vclib/core/include/vclib/space/core/tex_coord_indexed.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class TexCoordIndexed : public TexCoord<Scalar>

public:
using Base::Base;
using Base::set;

using Base::operator();
using Base::operator[];
Expand Down Expand Up @@ -86,6 +87,12 @@ class TexCoordIndexed : public TexCoord<Scalar>

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);
Expand All @@ -102,6 +109,12 @@ class TexCoordIndexed : public TexCoord<Scalar>
auto operator<=>(const TexCoordIndexed& t1) const = default;
};

/* Specialization Aliases */

using TexCoordIndexedi = TexCoordIndexed<int>;
using TexCoordIndexedf = TexCoordIndexed<float>;
using TexCoordIndexedd = TexCoordIndexed<double>;

} // namespace vcl

#endif // VCL_SPACE_CORE_TEX_COORD_INDEXED_H

0 comments on commit 28549eb

Please sign in to comment.