<commit_before>#pragma once

#include "glm/vec2.hpp"
#include "glm/mat4x4.hpp"
#include <climits> // needed in aabb.h
#include "isect2d.h"
#include "glm_vec.h" // for isect2d.h
#include "fadeEffect.h"
#include "util/types.h"
#include "util/hash.h"
#include "data/properties.h"

#include <string>
#include <limits>
#include <memory>

namespace {
// Conversion factors for Label::Vertex attributes
constexpr float position_scale = 4.0f;
constexpr float extrusion_scale = 256.0f;
constexpr float rotation_scale = 4096.0f;
constexpr float alpha_scale = 32767.f;
}

namespace Tangram {

class LabelMesh;

class Label {

public:

    using OBB = isect2d::OBB<glm::vec2>;
    using AABB = isect2d::AABB<glm::vec2>;

    enum class Type {
        point,
        line,
        debug
    };

    enum State {
        fading_in       = 1,
        fading_out      = 1 << 1,
        visible         = 1 << 2,
        sleep           = 1 << 3,
        out_of_screen   = 1 << 4,
        wait_occ        = 1 << 5, // state waiting for first occlusion result
        skip_transition = 1 << 6,
        dead            = 1 << 7,
    };

    struct Vertex {
        // Constructor for TextStyle vertices
        Vertex(glm::vec2 pos, glm::vec2 uv, uint32_t color, uint32_t stroke)
            : pos(glm::round(pos * position_scale)), uv(uv),
              color(color), stroke(stroke) {}

        // Constructor for PointStyle vertices
        Vertex(glm::vec2 pos, glm::vec2 uv, glm::vec2 extrude, uint32_t color)
            : pos(glm::round(pos * position_scale)), uv(uv),
              color(color),
              extrude(extrude * extrusion_scale) {}

        glm::i16vec2 pos;
        glm::u16vec2 uv;
        uint32_t color;
        union {
            glm::i16vec2 extrude;
            uint32_t stroke;
        };
        struct State {
            State() {}
            State(glm::vec2 pos, float alpha, float rotation)
                : screenPos(pos * position_scale),
                  alpha(alpha * alpha_scale),
                  rotation(rotation * rotation_scale) {}

            glm::i16vec2 screenPos;
            short alpha = 0;
            short rotation = 0;
        } state;
    };

    struct Transform {
        Transform(glm::vec2 _pos) : modelPosition1(_pos), modelPosition2(_pos) {}
        Transform(glm::vec2 _pos1, glm::vec2 _pos2) : modelPosition1(_pos1), modelPosition2(_pos2) {}

        glm::vec2 modelPosition1;
        glm::vec2 modelPosition2;

        struct {
            glm::vec2 screenPos;
            float alpha = 0.f;
            float rotation = 0.f;
            Vertex::State vertex() { return Vertex::State(screenPos, alpha, rotation); }
        } state;
    };

    struct Transition {
        FadeEffect::Interpolation ease = FadeEffect::Interpolation::sine;
        float time = 0.2;
    };

    struct Options {
        glm::vec2 offset;
        uint32_t priority = std::numeric_limits<uint32_t>::max();
        bool interactive = false;
        std::shared_ptr<Properties> properties;
        bool collide = true;
        Transition selectTransition;
        Transition hideTransition;
        Transition showTransition;
        size_t repeatGroup = 0;
        float repeatDistance = 0;
        float buffer = 0.f;

        // the label hash based on its styling parameters
        size_t paramHash = 0;
    };

    Label(Transform _transform, glm::vec2 _size, Type _type, LabelMesh& _mesh, Range _vertexRange,
            Options _options);

    virtual ~Label();

    bool update(const glm::mat4& _mvp, const glm::vec2& _screenSize, float _zoomFract);

    /* Push the pending transforms to the vbo by updating the vertices */
    void pushTransform();

    bool evalState(const glm::vec2& _screenSize, float _dt);

    /* Update the screen position of the label */
    bool updateScreenTransform(const glm::mat4& _mvp, const glm::vec2& _screenSize,
                               bool _testVisibility = true);

    virtual void updateBBoxes(float _zoomFract) = 0;

    /* Occlude the label */
    void occlude(bool _occlusion = true);

    /* Checks whether the label is in a state where it can occlusion */
    bool canOcclude();
<commit_msg>Label: make pushTransform virtual, cleanups<commit_after>#pragma once

#include "glm/vec2.hpp"
#include "glm/mat4x4.hpp"
#include <climits> // needed in aabb.h
#include "isect2d.h"
#include "glm_vec.h" // for isect2d.h
#include "fadeEffect.h"
#include "util/types.h"
#include "util/hash.h"
#include "data/properties.h"

#include <string>
#include <limits>
#include <memory>

namespace {
// Conversion factors for Label::Vertex attributes
constexpr float position_scale = 4.0f;
constexpr float extrusion_scale = 256.0f;
constexpr float rotation_scale = 4096.0f;
constexpr float alpha_scale = 32767.f;
}

namespace Tangram {

class LabelMesh;

class Label {

public:

    using OBB = isect2d::OBB<glm::vec2>;
    using AABB = isect2d::AABB<glm::vec2>;

    enum class Type {
        point,
        line,
        debug
    };

    enum State {
        fading_in       = 1,
        fading_out      = 1 << 1,
        visible         = 1 << 2,
        sleep           = 1 << 3,
        out_of_screen   = 1 << 4,
        wait_occ        = 1 << 5, // state waiting for first occlusion result
        skip_transition = 1 << 6,
        dead            = 1 << 7,
    };

    struct Vertex {
        // Constructor for TextStyle vertices
        Vertex(glm::vec2 pos, glm::vec2 uv, uint32_t color, uint32_t stroke)
            : pos(glm::round(pos * position_scale)), uv(uv),
              color(color), stroke(stroke) {}

        // Constructor for PointStyle vertices
        Vertex(glm::vec2 pos, glm::vec2 uv, glm::vec2 extrude, uint32_t color)
            : pos(glm::round(pos * position_scale)), uv(uv),
              color(color),
              extrude(extrude * extrusion_scale) {}

        glm::i16vec2 pos;
        glm::u16vec2 uv;
        uint32_t color;
        union {
            glm::i16vec2 extrude;
            uint32_t stroke;
        };
        struct State {
            State() {}
            State(glm::vec2 pos, float alpha, float rotation)
                : screenPos(pos * position_scale),
                  alpha(alpha * alpha_scale),
                  rotation(rotation * rotation_scale) {}

            glm::i16vec2 screenPos;
            short alpha = 0;
            short rotation = 0;
        } state;
    };

    struct Transform {
        Transform(glm::vec2 _pos) : modelPosition1(_pos), modelPosition2(_pos) {}
        Transform(glm::vec2 _pos1, glm::vec2 _pos2) : modelPosition1(_pos1), modelPosition2(_pos2) {}

        glm::vec2 modelPosition1;
        glm::vec2 modelPosition2;

        struct {
            glm::vec2 screenPos;
            float alpha = 0.f;
            float rotation = 0.f;
            Vertex::State vertex() { return Vertex::State(screenPos, alpha, rotation); }
        } state;
    };

    struct Transition {
        FadeEffect::Interpolation ease = FadeEffect::Interpolation::sine;
        float time = 0.2;
    };

    struct Options {
        glm::vec2 offset;
        uint32_t priority = std::numeric_limits<uint32_t>::max();
        bool interactive = false;
        std::shared_ptr<Properties> properties;
        bool collide = true;
        Transition selectTransition;
        Transition hideTransition;
        Transition showTransition;
        size_t repeatGroup = 0;
        float repeatDistance = 0;
        float buffer = 0.f;

        // the label hash based on its styling parameters
        size_t paramHash = 0;
    };

    Label(Transform _transform, glm::vec2 _size, Type _type, LabelMesh& _mesh, Range _vertexRange,
            Options _options);

    virtual ~Label();

    bool update(const glm::mat4& _mvp, const glm::vec2& _screenSize, float _zoomFract);

    /* Push the pending transforms to the vbo by updating the vertices */
    virtual void pushTransform();

    bool evalState(const glm::vec2& _screenSize, float _dt);

    /* Update the screen position of the label */
    bool updateScreenTransform(const glm::mat4& _mvp, const glm::vec2& _screenSize,
                               bool _testVisibility = true);

    virtual void updateBBoxes(float _zoomFract) = 0;

    /* Occlude the label */
    void occlude(bool _occlusion = true);

    /* Checks whether the label is in a state where it can occlusion */
    bool canOcclude();

{'fraction_non_alphanumeric': 0.105, 'fraction_numerical': 0.025238095238095237, 'mean_word_length': 2.2187739463601535, 'pattern_counts': {'":': 0, '<': 47, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5966951', 'n_tokens_mistral': 2710, 'n_tokens_neox': 2521, 'n_words': 687}