
// CPUStrokeTessellatorPrint.cpp - print state of CPUStrokeTessellator

#include <math.h>
#include <stdio.h>

#include "countof.h"

#include "CPUStrokeTessellator.hpp"

// Initialize all values to bogus value.
CPUStrokeTessellatorInterface::CPUStrokeTessellatorInterface()
{
    const int bogus_value = -666;
    const float bogus_valuef = -666.0f;  // Avoids conversion issues.

    for (size_t i=0; i<icountof(vertex_id); i++) {
        vertex_id[i] = bogus_value;
    }
    for (size_t i=0; i<icountof(hpos); i++) {
        hpos[i] = float3(bogus_valuef);
    }
    for (size_t i=0; i<icountof(v); i++) {
        v[i] = float3(bogus_valuef);
    }
    for (size_t i=0; i<icountof(v_orig); i++) {
        v_orig[i] = float3(bogus_valuef);
    }

    const int num_threads = NUM_THREADS;

    for (size_t i=0; i<icountof(cp); i++) {
        cp[i] = CPtype(bogus_valuef);
    }

    for (int i=0; i<num_threads; i++) {
        delta[i] = bogus_value;
    }
    for (int i=0; i<num_threads; i++) {
        theta[i] = bogus_value;
    }
    for (int i=0; i<num_threads; i++) {
        tbounds[i] = bogus_value;
    }
    for (int i=0; i<num_threads; i++) {
        link_state[i] = bogus_value;
    }
    for (int i=0; i<num_threads; i++) {
        A_C[i] = bogus_value;
    }
    for (int i=0; i<num_threads; i++) {
        B_bogus[i] = bogus_value;
    }
    for (int i=0; i<num_threads; i++) {
        row_columns_orientationBitMask_steps[i] = bogus_value;
    }
    for (int i=0; i<num_threads; i++) {
        int_tmp[i] = bogus_value;
    }
    for (int i=0; i<num_threads; i++) {
        delta_alt[i] = bogus_value;
    }
    for (int i=0; i<num_threads; i++) {
        v1[i] = VECTOR(bogus_value);
    }
    for (int i=0; i<num_threads; i++) {
        v2[i] = SCALAR(bogus_value);
    }

    for (int i=0; i<num_threads; i++) {
        delta_steps[i] = bogus_value;
    }
    for (int i=0; i<num_threads; i++) {
        dtheta_dsteps[i] = bogus_value;
    }

    pervertex_offset = vec2(bogus_valuef);  // Normal vector.
    pervertex_radius = vec2(bogus_valuef);  // vec2(-radius,radius) or, for joins and caps, vec2(0,+/-radius);
    pervertex_p = CPtype(bogus_valuef);
}

void CPUStrokeTessellatorInterface::print(FILE* fp) const
{
    printf("CPUStrokeTessellatorInterface: 0x%p\n", this);

    for (int i=0; i<icountof(vertex_id); i++) {
        printf("vertex_id[%d] = %d\n", i, vertex_id[i]);
    }
    for (int i=0; i<icountof(hpos); i++) {
        printf("hpos[%d] = %g,%g,%g\n", i,
            float(hpos[i].x),
            float(hpos[i].y),
            float(hpos[i][2]));
    }
    for (int i=0; i<icountof(v); i++) {
        printf("v[%d] = %g,%g,%g\n", i,
            float(v[i].x),
            float(v[i].y),
            float(v[i][2]));
    }
    for (int i=0; i<icountof(v_orig); i++) {
        printf("v_orig[%d] = %g,%g,%g\n", i,
            float(v_orig[i].x),
            float(v_orig[i].y),
            float(v_orig[i][2]));
    }

    int num_threads = NUM_THREADS;
    num_threads = 4;

    for (int i=0; i<num_threads; i++) {
        printf("delta[%d] = %g\n", i, delta[i]);
    }
    for (int i=0; i<num_threads; i++) {
        printf("theta[%d] = %g\n", i, theta[i]);
    }
    for (int i=0; i<num_threads; i++) {
        printf("tbounds[%d] = %g\n", i, tbounds[i]);
    }

    for (int i=0; i<num_threads; i++) {
        printf("link_state[%d] = %d\n", i, link_state[i]);
    }

    for (int i=0; i<num_threads; i++) {
        printf("A_C[%d] = %g\n", i, A_C[i]);
    }
    for (int i=0; i<num_threads; i++) {
        printf("B_bogus[%d] = %g\n", i, B_bogus[i]);
    }
    for (int i=0; i<num_threads; i++) {
        printf("row_columns_orientationBitMask_steps[%d] = %d\n", i, row_columns_orientationBitMask_steps[i]);
    }
    for (int i=0; i<num_threads; i++) {
        printf("int_tmp[%d] = %d\n", i, int_tmp[i]);
    }
    for (int i=0; i<num_threads; i++) {
        printf("delta_alt[%d] = %g\n", i, delta_alt[i]);
    }
    for (int i=0; i<num_threads; i++) {
        printf("v1[%d].x = %g\n", i, double(v1[i].x));
        printf("v1[%d].y = %g\n", i, double(v1[i].y));
    }
    for (int i=0; i<num_threads; i++) {
        printf("v2[%d] = %g\n", i, v2[i]);
    }
    for (int i=0; i<num_threads; i++) {
        printf("primitiveID_x_x_x[%u] = %u\n", i, primitiveID_x_x_x[i]);
    }
    for (int i=0; i<num_threads; i++) {
        printf("delta_steps[%d] = %g\n", i, delta_steps[i]);
    }

    printf("A.xy = %g,%g\n", float(A_C[0]), float(A_C[2]));
    printf("C.xy = %g,%g\n", float(A_C[1]), float(A_C[3]));

    printf("B.xy = %g,%g\n", float(B_bogus[0]), float(B_bogus[1]));
}

void CPUStrokeTessellator::print(FILE* fp) const
{
    printf("CPUStrokeTessellator: 0x%p\n", this);

    CPUStrokeTessellatorInterface::print(fp);

    printf("stashed_D0AB1 = %g\n", stashed_D0AB1);
    printf("stashed_link_type = %d\n", stashed_link_type);

    for (int i=0; i<icountof(angleDelta_stash); i++) {
        printf("angleDelta_stash[%d] = %g\n", i, angleDelta_stash[i]);
    }
    for (int i=0; i<icountof(grad_cp); i++) {
        printf("grad_cp[%d].xy = %g,%g\n", i, float(grad_cp[i].x), float(grad_cp[i].y));
    }
}
