Team Ai
Apppublic

CVPR/LIVE

sourceHugging Facegpl-3.0updated 4y agoView on Hugging Face
34likes
shape.h170 linesDownload Raw Back to root
1#pragma once2 3#include "diffvg.h"4#include "color.h"5#include "ptr.h"6#include "vector.h"7#include "matrix.h"8 9enum class ShapeType {10    Circle,11    Ellipse,12    Path,13    Rect14};15 16struct Circle {17    float radius;18    Vector2f center;19 20    ptr<void> get_ptr() {21        return ptr<void>(this);22    }23};24 25struct Ellipse {26    Vector2f radius;27    Vector2f center;28 29    ptr<void> get_ptr() {30        return ptr<void>(this);31    }32};33 34struct Path {35    Path(ptr<int> num_control_points,36         ptr<float> points,37         ptr<float> thickness,38         int num_base_points,39         int num_points,40         bool is_closed,41         bool use_distance_approx) :42        num_control_points(num_control_points.get()),43        points(points.get()),44        thickness(thickness.get()),45        num_base_points(num_base_points),46        num_points(num_points),47        is_closed(is_closed),48        use_distance_approx(use_distance_approx) {}49 50    int *num_control_points;51    float *points;52    float *thickness;53    int num_base_points;54    int num_points;55    bool is_closed;56    bool use_distance_approx;57 58    bool has_thickness() const {59        return thickness != nullptr;60    }61    void copy_to(ptr<float> points, ptr<float> thickness) const;62 63    ptr<void> get_ptr() {64        return ptr<void>(this);65    }66};67 68struct Rect {69    Vector2f p_min;70    Vector2f p_max;71 72    ptr<void> get_ptr() {73        return ptr<void>(this);74    }75};76 77struct Shape {78    Shape() {}79    Shape(const ShapeType &type,80          ptr<void> shape_ptr,81          float stroke_width)    82        : type(type), ptr(shape_ptr.get()), stroke_width(stroke_width) {}83 84    Circle as_circle() const {85        return *(Circle*)ptr;86    }87 88    Ellipse as_ellipse() const {89        return *(Ellipse*)ptr;90    }91 92    Path as_path() const {93        return *(Path*)ptr;94    }95 96    Rect as_rect() const {97        return *(Rect*)ptr;98    }99 100    ShapeType type;101    void *ptr;102    float stroke_width;103};104 105struct ShapeGroup {106    ShapeGroup() {}107    ShapeGroup(ptr<int> shape_ids,108               int num_shapes,109               const ColorType &fill_color_type,110               ptr<void> fill_color,111               const ColorType &stroke_color_type,112               ptr<void> stroke_color,113               bool use_even_odd_rule,114               ptr<float> shape_to_canvas)115        : shape_ids(shape_ids.get()),116          num_shapes(num_shapes),117          fill_color_type(fill_color_type),118          fill_color(fill_color.get()),119          stroke_color_type(stroke_color_type),120          stroke_color(stroke_color.get()),121          use_even_odd_rule(use_even_odd_rule),122          shape_to_canvas(shape_to_canvas.get()) {123        canvas_to_shape = inverse(this->shape_to_canvas);124    }125 126    bool has_fill_color() const {127        return fill_color != nullptr;128    }129 130    Constant fill_color_as_constant() const {131        return *(Constant*)fill_color;132    }133 134    LinearGradient fill_color_as_linear_gradient() const {135        return *(LinearGradient*)fill_color;136    }137 138    RadialGradient fill_color_as_radial_gradient() const {139        return *(RadialGradient*)fill_color;140    }141 142    bool has_stroke_color() const {143        return stroke_color != nullptr;144    }145 146    Constant stroke_color_as_constant() const {147        return *(Constant*)stroke_color;148    }149 150    LinearGradient stroke_color_as_linear_gradient() const {151        return *(LinearGradient*)stroke_color;152    }153 154    RadialGradient stroke_color_as_radial_gradient() const {155        return *(RadialGradient*)stroke_color;156    }157 158    void copy_to(ptr<float> shape_to_canvas) const;159 160    int *shape_ids;161    int num_shapes;162    ColorType fill_color_type;163    void *fill_color;164    ColorType stroke_color_type;165    void *stroke_color;166    bool use_even_odd_rule;167    Matrix3x3f canvas_to_shape;168    Matrix3x3f shape_to_canvas;169};170