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

#pragma once

#ifndef VSNRAY_UPDATE_IF_H
#define VSNRAY_UPDATE_IF_H 1

#include "detail/macros.h"
#include "math/aabb.h"
#include "math/intersect.h"
#include "math/ray.h"

namespace visionaray
{

//-------------------------------------------------------------------------------------------------
// Utility functions that can be reimplemented for user-supplied hit records
// Used by the traversal functions (linear traversal, BVH traversal, etc.)
//-------------------------------------------------------------------------------------------------


//-------------------------------------------------------------------------------------------------
// update_if()
//
// Update hit record <dst> with params from hit record <src> if <cond> is met
//

// default implementation for hit_record<ray, primitive<unsigned>>
template <typename HR, typename Cond>
VSNRAY_FUNC
void update_if(HR& dst, HR const& src, Cond const& cond)
{
    dst.hit        |= cond;
    dst.t           = select( cond, src.t, dst.t );
    dst.prim_id     = select( cond, src.prim_id, dst.prim_id );
    dst.geom_id     = select( cond, src.geom_id, dst.geom_id );
    dst.u           = select( cond, src.u, dst.u );
    dst.v           = select( cond, src.v, dst.v );
}


//-------------------------------------------------------------------------------------------------
// is_closer()
//
// Check if hit record <query> is valid and closer than hit record <reference> in ray's
// parameter space
//

// default implementation for hit_record<ray, primitive<unsigned>>
template <typename HR>
VSNRAY_FUNC
auto is_closer(HR const& query, HR const& reference)
    -> decltype(query.t < reference.t)
{
    using T = decltype(query.t);

    return query.hit && ( query.t >= T(0.0) && query.t < reference.t );
}

// query is box, reference is general primitive

template <typename T, typename U, typename HR>
VSNRAY_FUNC
auto is_closer(hit_record<basic_ray<T>, basic_aabb<U>> const& query, HR const& reference)
    -> decltype(query.tnear < reference.t)<commit_msg>Also update isect_pos in update_if(hit_record)<commit_after>// This file is distributed under the MIT license.
// See the LICENSE file for details.

#pragma once

#ifndef VSNRAY_UPDATE_IF_H
#define VSNRAY_UPDATE_IF_H 1

#include "detail/macros.h"
#include "math/aabb.h"
#include "math/intersect.h"
#include "math/ray.h"

namespace visionaray
{

//-------------------------------------------------------------------------------------------------
// Utility functions that can be reimplemented for user-supplied hit records
// Used by the traversal functions (linear traversal, BVH traversal, etc.)
//-------------------------------------------------------------------------------------------------


//-------------------------------------------------------------------------------------------------
// update_if()
//
// Update hit record <dst> with params from hit record <src> if <cond> is met
//

// default implementation for hit_record<ray, primitive<unsigned>>
template <typename HR, typename Cond>
VSNRAY_FUNC
void update_if(HR& dst, HR const& src, Cond const& cond)
{
    dst.hit        |= cond;
    dst.prim_id     = select( cond, src.prim_id, dst.prim_id );
    dst.geom_id     = select( cond, src.geom_id, dst.geom_id );
    dst.t           = select( cond, src.t, dst.t );
    dst.isect_pos   = select( cond, src.isect_pos, dst.isect_pos );
    dst.u           = select( cond, src.u, dst.u );
    dst.v           = select( cond, src.v, dst.v );
}


//-------------------------------------------------------------------------------------------------
// is_closer()
//
// Check if hit record <query> is valid and closer than hit record <reference> in ray's
// parameter space
//

// default implementation for hit_record<ray, primitive<unsigned>>
template <typename HR>
VSNRAY_FUNC
auto is_closer(HR const& query, HR const& reference)
    -> decltype(query.t < reference.t)
{
    using T = decltype(query.t);

    return query.hit && ( query.t >= T(0.0) && query.t < reference.t );
}

// query is box, reference is general primitive

template <typename T, typename U, typename HR>
VSNRAY_FUNC
auto is_closer(hit_record<basic_ray<T>, basic_aabb<U>> const& query, HR const& reference)
    -> decltype(query.tnear < reference.t)
{'fraction_non_alphanumeric': 0.2824742268041237, 'fraction_numerical': 0.0013745704467353953, 'mean_word_length': 1.7067575945443274, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 39, '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': '752398', 'n_tokens_mistral': 1236, 'n_tokens_neox': 1210, 'n_words': 376}