
// StrokeTessellator.cpp - common CPU and GPU stroke tessellator infrastructure

#include <assert.h>

#include "StrokeTessellator.hpp"

int StrokeTessellator::JoinEnumToMaxJoinSteps(JoinEnum join_style)
{
    static const int JoinEnum_to_max_join_steps[] = {
        max_steps, // ROUND_JOIN (or any larger value)
        1,     // BEVEL
        2,     // TRIANGULAR_JOIN
        -1,    // MITER_REVERT
        -2,    // MITER_TRUNCATE
        0,     // NO_JOIN
    };
    assert(join_style < JOIN_ENUM_COUNT);
    return JoinEnum_to_max_join_steps[join_style];
}

unsigned int StrokeTessellator::CapStateToCapMask(CapEnum initial_cap,
                                                  CapEnum terminal_cap, 
                                                  CapEnum initial_dash_cap,
                                                  CapEnum terminal_dash_cap)
{
    unsigned int cap_placement_to_type = initial_cap << 0
                                       | terminal_cap << 8
                                       | initial_dash_cap << 16
                                       | terminal_dash_cap << 24;
    return cap_placement_to_type;
}

unsigned int StrokeTessellator::CapStateToCapMask(CapEnum identical_cap)
{
    return CapStateToCapMask(identical_cap, identical_cap, identical_cap, identical_cap);
}

float StrokeTessellator::InitialAlmostZeroEpsilon() {
    return 0.00000001f;  // CPU friendly, GPU might need slightly larger value.
}

StrokeTessellator::StrokeTessellator()
    : almost_zero_epsilon(InitialAlmostZeroEpsilon())
{}
