
// StrokeTessellatorSettings.cpp - implementation of global stroke tessellator settings

#include "ct_assert.h"
#include "countof.h"

#include "StrokeTessellatorSettings.hpp"

#include <Cg/radians.hpp>

using namespace Cg;

// Sensible defaults for stroke tessellator settings.
StrokeTessellatorSettings::StrokeTessellatorSettings()
    : trivial_culling(true)
    , min_window_stroke_radius_clamp(true)
    , min_window_stroke_radius(0.5f)    // Don't allow effective stroke width to fall below 1 pixel diameter.
    , max_turning_angle_delta(radians(4.0f/*degrees*/))
    , inside_round_join_mode(AUTOMATIC_INSIDE_ROUND_JOIN)
#if SUPPORT_POLAR_VISUALIZE
    , parameterization(POLAR)
    , uniform_segments(20) // default to twenty steps for UNIFORM mode
    , extra_steps(0)
#endif
{}

// Sensible defaults for stroke tessellator settings.
StrokeTessellatorSettings::StrokeTessellatorSettings(float angle_in_radians)
    : trivial_culling(true)
    , min_window_stroke_radius_clamp(true)
    , min_window_stroke_radius(0.5f)    // Don't allow effective stroke width to fall below 1 pixel diameter.
    , max_turning_angle_delta(angle_in_radians)
    , inside_round_join_mode(AUTOMATIC_INSIDE_ROUND_JOIN)
#if SUPPORT_POLAR_VISUALIZE
    , parameterization(POLAR)
    , uniform_segments(20) // default to twenty steps for UNIFORM mode
    , extra_steps(0)
#endif
{}

const char* StrokeTessellatorSettings::InsideRoundJoinModeString() const
{
    static const char* strings[] = {
        "no inside join",        // NO_INSIDE_ROUND_JOIN
        "force inside join",     // FORCE_INSIDE_ROUND_JOIN
        "automatic inside join"  // AUTOMATIC_INSIDE_ROUND_JOIN
    };
    ct_assert(countof(strings) == INSIDE_ROUND_JOIN_MODES);
    assert(inside_round_join_mode < sizeof(strings));
    return strings[inside_round_join_mode];
}

void StrokeTessellatorSettings::setInsideRoundJoinMode(InsideRoundJoinEnum mode)
{
    inside_round_join_mode = mode;
}

void StrokeTessellatorSettings::cycleInsideRoundJoinMode()
{
    inside_round_join_mode = InsideRoundJoinEnum(int(inside_round_join_mode)+1);
    if (inside_round_join_mode == INSIDE_ROUND_JOIN_MODES) {
        inside_round_join_mode = NO_INSIDE_ROUND_JOIN;
    }
}
