
// PathStyle.cpp - style properties of SVG paths

#include <assert.h>

#include "sg/PathStyle.hpp"

// Default constructor
PathStyle::PathStyle()
    : fill_rule(NON_ZERO)
    , non_scaling_stroke(false)
    , stroke_width(1)
    , line_cap(BUTT_CAP)
    , line_join(MITER_REVERT_JOIN)
    , miter_limit(4)
    , allow_dilation(true)
    , color_interpolation(LINEAR_RGB)
    , color_interpolation_filters(LINEAR_RGB)
{}

// Copy constructor
PathStyle::PathStyle(const PathStyle &src)
    : DashStyle(src)
{
    fill_rule = src.fill_rule;
    non_scaling_stroke = src.non_scaling_stroke;
    stroke_width = src.stroke_width;
    line_cap = src.line_cap;
    line_join = src.line_join;
    miter_limit = src.miter_limit;
    allow_dilation = src.allow_dilation;
    color_interpolation = src.color_interpolation;
    color_interpolation_filters = src.color_interpolation_filters;
}

bool PathStyle::compatibleWithTwoEdgeQuadraticStrokeDiscardShader() const
{
    if (line_join == ROUND_JOIN) {
        switch (line_cap) {
        case ROUND_CAP:
        case SQUARE_CAP:
            return true;
        default:
            return false;
        }
    }
    return false;
}

bool PathStyle::operator < (const PathStyle& other) const
{
    if (non_scaling_stroke != other.non_scaling_stroke)
        return non_scaling_stroke < other.non_scaling_stroke;
    if (stroke_width != other.stroke_width)
        return stroke_width < other.stroke_width;
    if (line_cap != other.line_cap)
        return line_cap < other.line_cap;
    if (line_join != other.line_join)
        return line_join < other.line_join;
    if (miter_limit != other.miter_limit)
        return miter_limit < other.miter_limit;
    if (color_interpolation != other.color_interpolation)
        return color_interpolation < other.color_interpolation;
    if (color_interpolation_filters != other.color_interpolation_filters)
        return color_interpolation_filters < other.color_interpolation_filters;
    return static_cast<const DashStyle&>(*this) < static_cast<const DashStyle&>(other);
}

bool PathStyle::operator == (const PathStyle& other) const
{
    if (non_scaling_stroke != other.non_scaling_stroke)
        return false;
    if (stroke_width != other.stroke_width)
        return false;
    if (line_cap != other.line_cap)
        return false;
    if (line_join != other.line_join)
        return false;
    if (miter_limit != other.miter_limit)
        return false;
    if (color_interpolation != other.color_interpolation)
        return false;
    if (color_interpolation_filters != other.color_interpolation_filters)
        return false;
    return static_cast<const DashStyle&>(*this) == static_cast<const DashStyle&>(other);
}
