<commit_before>// This file is distributed under the MIT license.
// See the LICENSE file for details.

#pragma once

#ifndef VSNRAY_TEXTURE_DETAIL_FILTER_COMMON_H
#define VSNRAY_TEXTURE_DETAIL_FILTER_COMMON_H 1

#include <array>
#include <type_traits>

#include <visionaray/detail/macros.h>
#include <visionaray/math/detail/math.h>
#include <visionaray/math/simd/gather.h>
#include <visionaray/math/vector.h>

#include "../../forward.h"


namespace visionaray
{
namespace detail
{

//-------------------------------------------------------------------------------------------------
// Remap tex coord based on address mode
//

template <typename F, typename I>
inline F map_tex_coord(F const& coord, I const& texsize, tex_address_mode mode)
{
    F N = convert_to_float(texsize);

    switch (mode)
    {

    case Mirror:
        return select(
            (convert_to_int(floor(coord)) & I(1)) == 1, // if is odd
            F(texsize - 1) / F(texsize) - (coord - floor(coord)),
            coord - floor(coord)
            );

    case Wrap:
        return coord - floor(coord);

    case Clamp:
        // fall-through<commit_msg>Explicit conversion between simd vector types<commit_after>// This file is distributed under the MIT license.
// See the LICENSE file for details.

#pragma once

#ifndef VSNRAY_TEXTURE_DETAIL_FILTER_COMMON_H
#define VSNRAY_TEXTURE_DETAIL_FILTER_COMMON_H 1

#include <array>
#include <type_traits>

#include <visionaray/detail/macros.h>
#include <visionaray/math/detail/math.h>
#include <visionaray/math/simd/gather.h>
#include <visionaray/math/vector.h>

#include "../../forward.h"


namespace visionaray
{
namespace detail
{

//-------------------------------------------------------------------------------------------------
// Remap tex coord based on address mode
//

template <typename F, typename I>
inline F map_tex_coord(F const& coord, I const& texsize, tex_address_mode mode)
{
    F N = convert_to_float(texsize);

    switch (mode)
    {

    case Mirror:
        return select(
            (convert_to_int(floor(coord)) & I(1)) == 1, // if is odd
            convert_to_float(texsize - 1) / convert_to_float(texsize) - (coord - floor(coord)),
            coord - floor(coord)
            );

    case Wrap:
        return coord - floor(coord);

    case Clamp:
        // fall-through
{'fraction_non_alphanumeric': 0.18782161234991424, 'fraction_numerical': 0.003430531732418525, 'mean_word_length': 2.20467032967033, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3219636', 'n_tokens_mistral': 734, 'n_tokens_neox': 707, 'n_words': 188}