Skip to content
Snippets Groups Projects

Inside/Outside Subdeterminant Query

  • Clone with SSH
  • Clone with HTTPS
  • Embed
  • Share
    The snippet can be accessed without any authentication.
    Authored by Zain Selman
    query.cpp 1.41 KiB
    template <class geometry_t, class idx_t>
    tg::optional<idx_t> bsp<geometry_t, idx_t>::impl_subdeterminant_query_leaf_idx(idx_t idx, subdeterminants<geometry_t> const& sub) const
    {
        auto n_idx = idx;
        while (!nodes[n_idx].is_leaf())
        {
            auto& plane = planes[nodes[n_idx].plane_idx];
    
    
            const auto d = classify_vertex(sub, plane);
    
    
            if (is_zero(d))
            {
                TG_ASSERT(!nodes[n_idx].is_leaf());
                TG_ASSERT(nodes[n_idx].child_pos != n_idx);
                TG_ASSERT(nodes[n_idx].child_neg != n_idx);
    
                auto const q_neg = impl_subdeterminant_query_leaf_idx(nodes[n_idx].child_neg, sub);
                if (!q_neg.has_value())
                    return {}; /// means: point is on surface
    
                auto const q_pos = impl_subdeterminant_query_leaf_idx(nodes[n_idx].child_pos, sub);
                if (!q_pos.has_value())
                    return {}; /// means: point is on surface
    
                auto const& n_neg = nodes[q_neg.value()];
                auto const& n_pos = nodes[q_pos.value()];
                TG_ASSERT(n_neg.is_leaf() && n_pos.is_leaf());
                if (n_neg.plane_idx == n_pos.plane_idx)
                    return q_neg;
    
                return {}; /// means: point is on surface
            }
    
            if (less_than_zero(d))
                n_idx = nodes[n_idx].child_neg;
            else // d > 0
                n_idx = nodes[n_idx].child_pos;
        }
        return n_idx; /// bsp.nodes[n_idx].is_in() ?
    }
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Finish editing this message first!
    Please register or to comment