odin-blend2d

Odin bindings to Blend2D
Log | Files | Refs | README | LICENSE

shape_data.h (1868B)


      1 // This file is part of Blend2D project <https://blend2d.com>
      2 //
      3 // See LICENSE.md for license and copyright information
      4 // SPDX-License-Identifier: Zlib
      5 
      6 #ifndef BL_BENCH_SHAPE_DATA_H
      7 #define BL_BENCH_SHAPE_DATA_H
      8 
      9 #include <blend2d.h>
     10 
     11 namespace blbench {
     12 
     13 enum class ShapeKind {
     14   kButterfly,
     15   kFish,
     16   kDragon,
     17   kWorld,
     18   kMaxValue = kWorld
     19 };
     20 
     21 struct ShapeData {
     22   size_t size;
     23   const char* commands;
     24   const BLPoint* vertices;
     25 };
     26 
     27 bool get_shape_data(ShapeData& dst, ShapeKind kind);
     28 
     29 class ShapeIterator {
     30 public:
     31   size_t remaining;
     32   const char* commands;
     33   const BLPoint* vertices;
     34 
     35   explicit inline ShapeIterator(ShapeData data) noexcept {
     36     remaining = data.size;
     37     commands = data.commands;
     38     vertices = data.vertices;
     39   }
     40 
     41   inline bool has_command() const noexcept {
     42     return remaining != 0;
     43   }
     44 
     45   inline void next() noexcept {
     46     char command = commands[0];
     47 
     48     remaining--;
     49     commands++;
     50 
     51     switch (command) {
     52       case 'M': vertices += 1; break;
     53       case 'L': vertices += 1; break;
     54       case 'Q': vertices += 2; break;
     55       case 'C': vertices += 3; break;
     56       default:
     57         break;
     58     }
     59   }
     60 
     61   inline bool is_close() const noexcept { return commands[0] == 'Z'; }
     62   inline bool is_move_to() const noexcept { return commands[0] == 'M'; }
     63   inline bool is_line_to() const noexcept { return commands[0] == 'L'; }
     64   inline bool is_quad_to() const noexcept { return commands[0] == 'Q'; }
     65   inline bool is_cubic_to() const noexcept { return commands[0] == 'C'; }
     66 
     67   template<typename Index>
     68   inline BLPoint vertex(const Index& i) const noexcept { return vertices[i]; }
     69 
     70   template<typename Index>
     71   inline double x(const Index& i) const noexcept { return vertices[i].x; }
     72 
     73   template<typename Index>
     74   inline double y(const Index& i) const noexcept { return vertices[i].y; }
     75 };
     76 
     77 } // {blbench}
     78 
     79 #endif // BL_BENCH_SHAPE_DATA_H