rays 0.1.46 → 0.1.48

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. checksums.yaml +4 -4
  2. data/.doc/ext/rays/bitmap.cpp +499 -0
  3. data/.doc/ext/rays/camera.cpp +2 -2
  4. data/.doc/ext/rays/defs.cpp +35 -11
  5. data/.doc/ext/rays/font.cpp +50 -2
  6. data/.doc/ext/rays/native.cpp +2 -4
  7. data/.doc/ext/rays/painter.cpp +111 -6
  8. data/.doc/ext/rays/polygon.cpp +152 -41
  9. data/.doc/ext/rays/polyline.cpp +89 -10
  10. data/.doc/ext/rays/rays.cpp +91 -11
  11. data/.doc/ext/rays/{noise.cpp → util.cpp} +2 -2
  12. data/.github/workflows/test.yml +0 -1
  13. data/ChangeLog.md +38 -0
  14. data/Rakefile +4 -4
  15. data/VERSION +1 -1
  16. data/ext/rays/bitmap.cpp +501 -0
  17. data/ext/rays/camera.cpp +2 -2
  18. data/ext/rays/defs.cpp +35 -11
  19. data/ext/rays/defs.h +56 -3
  20. data/ext/rays/font.cpp +56 -4
  21. data/ext/rays/native.cpp +2 -4
  22. data/ext/rays/painter.cpp +125 -11
  23. data/ext/rays/polygon.cpp +161 -41
  24. data/ext/rays/polyline.cpp +95 -9
  25. data/ext/rays/rays.cpp +91 -11
  26. data/ext/rays/{noise.cpp → util.cpp} +2 -2
  27. data/include/rays/defs.h +24 -0
  28. data/include/rays/font.h +17 -3
  29. data/include/rays/matrix.h +2 -0
  30. data/include/rays/painter.h +29 -1
  31. data/include/rays/polygon.h +57 -33
  32. data/include/rays/polyline.h +20 -1
  33. data/include/rays/ruby/polygon.h +0 -11
  34. data/include/rays/ruby/rays.h +4 -0
  35. data/include/rays/{noise.h → util.h} +2 -2
  36. data/lib/rays/color.rb +1 -1
  37. data/lib/rays/font.rb +1 -1
  38. data/lib/rays/image.rb +1 -1
  39. data/lib/rays/painter.rb +13 -2
  40. data/lib/rays/point.rb +1 -1
  41. data/lib/rays/polygon.rb +54 -16
  42. data/lib/rays/polyline.rb +54 -8
  43. data/lib/rays.rb +0 -1
  44. data/rays.gemspec +2 -2
  45. data/src/color_space.cpp +2 -2
  46. data/src/font.cpp +24 -2
  47. data/src/font.h +8 -1
  48. data/src/ios/font.mm +88 -27
  49. data/src/matrix.cpp +8 -0
  50. data/src/osx/font.mm +90 -28
  51. data/src/osx/helper.h +2 -2
  52. data/src/osx/helper.mm +2 -2
  53. data/src/painter.cpp +227 -90
  54. data/src/painter.h +11 -3
  55. data/src/polygon.cpp +588 -205
  56. data/src/polyline.cpp +154 -28
  57. data/src/polyline.h +3 -5
  58. data/src/shader.cpp +36 -4
  59. data/src/shader.h +1 -1
  60. data/src/texture.cpp +2 -2
  61. data/src/{noise.cpp → util.cpp} +1 -1
  62. data/src/win32/font.cpp +1 -1
  63. data/test/test_bitmap.rb +16 -2
  64. data/test/test_color.rb +4 -0
  65. data/test/test_font.rb +20 -2
  66. data/test/test_image.rb +18 -18
  67. data/test/test_point.rb +1 -1
  68. data/test/test_polygon.rb +52 -45
  69. data/test/test_polyline.rb +191 -72
  70. metadata +11 -17
  71. data/.doc/ext/rays/polygon_line.cpp +0 -97
  72. data/ext/rays/polygon_line.cpp +0 -100
  73. data/lib/rays/polygon_line.rb +0 -33
  74. data/test/test_polygon_line.rb +0 -164
@@ -9,6 +9,8 @@
9
9
  RUCY_DEFINE_CONVERT_TO(Rays::CapType)
10
10
  RUCY_DEFINE_CONVERT_TO(Rays::JoinType)
11
11
  RUCY_DEFINE_CONVERT_TO(Rays::BlendMode)
12
+ RUCY_DEFINE_CONVERT_TO(Rays::TexCoordMode)
13
+ RUCY_DEFINE_CONVERT_TO(Rays::TexCoordWrap)
12
14
 
13
15
 
14
16
  template <typename T>
@@ -16,7 +18,7 @@ struct EnumType
16
18
  {
17
19
  const char* name;
18
20
  const char* short_name;
19
- T type;
21
+ T value;
20
22
  };
21
23
 
22
24
  static std::vector<EnumType<Rays::CapType>> CAP_TYPES({
@@ -43,6 +45,16 @@ static std::vector<EnumType<Rays::BlendMode>> BLEND_MODES({
43
45
  {"BLEND_REPLACE", "REPLACE", Rays::BLEND_REPLACE},
44
46
  });
45
47
 
48
+ static std::vector<EnumType<Rays::TexCoordMode>> TEXCOORD_MODES({
49
+ {"TEXCOORD_IMAGE", "IMAGE", Rays::TEXCOORD_IMAGE},
50
+ {"TEXCOORD_NORMAL", "NORMAL", Rays::TEXCOORD_NORMAL},
51
+ });
52
+
53
+ static std::vector<EnumType<Rays::TexCoordWrap>> TEXCOORD_WRAPS({
54
+ {"TEXCOORD_CLAMP", "CLAMP", Rays::TEXCOORD_CLAMP},
55
+ {"TEXCOORD_REPEAT", "REPEAT", Rays::TEXCOORD_REPEAT},
56
+ });
57
+
46
58
 
47
59
  static
48
60
  VALUE init(VALUE self)
@@ -70,13 +82,19 @@ Init_rays ()
70
82
  mRays.define_singleton_method("fin!", fin);
71
83
 
72
84
  for (auto it = CAP_TYPES.begin(); it != CAP_TYPES.end(); ++it)
73
- mRays.define_const(it->name, it->type);
85
+ mRays.define_const(it->name, it->value);
74
86
 
75
87
  for (auto it = JOIN_TYPES.begin(); it != JOIN_TYPES.end(); ++it)
76
- mRays.define_const(it->name, it->type);
88
+ mRays.define_const(it->name, it->value);
77
89
 
78
90
  for (auto it = BLEND_MODES.begin(); it != BLEND_MODES.end(); ++it)
79
- mRays.define_const(it->name, it->type);
91
+ mRays.define_const(it->name, it->value);
92
+
93
+ for (auto it = TEXCOORD_MODES.begin(); it != TEXCOORD_MODES.end(); ++it)
94
+ mRays.define_const(it->name, it->value);
95
+
96
+ for (auto it = TEXCOORD_WRAPS.begin(); it != TEXCOORD_WRAPS.end(); ++it)
97
+ mRays.define_const(it->name, it->value);
80
98
  }
81
99
 
82
100
 
@@ -100,7 +118,7 @@ namespace Rucy
100
118
  strcasecmp(str, it->name) == 0 ||
101
119
  strcasecmp(str, it->short_name) == 0)
102
120
  {
103
- return it->type;
121
+ return it->value;
104
122
  }
105
123
  }
106
124
  argument_error(__FILE__, __LINE__, "invalid cap type -- %s", str);
@@ -131,7 +149,7 @@ namespace Rucy
131
149
  strcasecmp(str, it->name) == 0 ||
132
150
  strcasecmp(str, it->short_name) == 0)
133
151
  {
134
- return it->type;
152
+ return it->value;
135
153
  }
136
154
  }
137
155
  argument_error(__FILE__, __LINE__, "invalid join type -- %s", str);
@@ -162,18 +180,80 @@ namespace Rucy
162
180
  strcasecmp(str, it->name) == 0 ||
163
181
  strcasecmp(str, it->short_name) == 0)
164
182
  {
165
- return it->type;
183
+ return it->value;
166
184
  }
167
185
  }
168
186
  argument_error(__FILE__, __LINE__, "invalid blend mode -- %s", str);
169
187
  }
170
188
  }
171
189
 
172
- int type = value_to<int>(*argv, convert);
173
- if (type < 0 || Rays::BLEND_MAX <= type)
174
- argument_error(__FILE__, __LINE__, "invalid blend mode -- %d", type);
190
+ int mode = value_to<int>(*argv, convert);
191
+ if (mode < 0 || Rays::BLEND_MAX <= mode)
192
+ argument_error(__FILE__, __LINE__, "invalid blend mode -- %d", mode);
193
+
194
+ return (Rays::BlendMode) mode;
195
+ }
196
+
197
+
198
+ template <> Rays::TexCoordMode
199
+ value_to<Rays::TexCoordMode> (int argc, const Value* argv, bool convert)
200
+ {
201
+ assert(argc > 0 && argv);
202
+
203
+ if (convert)
204
+ {
205
+ if (argv->is_s() || argv->is_sym())
206
+ {
207
+ const char* str = argv->c_str();
208
+ for (auto it = TEXCOORD_MODES.begin(); it != TEXCOORD_MODES.end(); ++it)
209
+ {
210
+ if (
211
+ strcasecmp(str, it->name) == 0 ||
212
+ strcasecmp(str, it->short_name) == 0)
213
+ {
214
+ return it->value;
215
+ }
216
+ }
217
+ argument_error(__FILE__, __LINE__, "invalid texcoord mode -- %s", str);
218
+ }
219
+ }
220
+
221
+ int mode = value_to<int>(*argv, convert);
222
+ if (mode < 0 || Rays::TEXCOORD_MODE_MAX <= mode)
223
+ argument_error(__FILE__, __LINE__, "invalid texcoord mode -- %d", mode);
224
+
225
+ return (Rays::TexCoordMode) mode;
226
+ }
227
+
228
+
229
+ template <> Rays::TexCoordWrap
230
+ value_to<Rays::TexCoordWrap> (int argc, const Value* argv, bool convert)
231
+ {
232
+ assert(argc > 0 && argv);
233
+
234
+ if (convert)
235
+ {
236
+ if (argv->is_s() || argv->is_sym())
237
+ {
238
+ const char* str = argv->c_str();
239
+ for (auto it = TEXCOORD_WRAPS.begin(); it != TEXCOORD_WRAPS.end(); ++it)
240
+ {
241
+ if (
242
+ strcasecmp(str, it->name) == 0 ||
243
+ strcasecmp(str, it->short_name) == 0)
244
+ {
245
+ return it->value;
246
+ }
247
+ }
248
+ argument_error(__FILE__, __LINE__, "invalid texcoord wrap -- %s", str);
249
+ }
250
+ }
251
+
252
+ int wrap = value_to<int>(*argv, convert);
253
+ if (wrap < 0 || Rays::TEXCOORD_WRAP_MAX <= wrap)
254
+ argument_error(__FILE__, __LINE__, "invalid texcoord wrap -- %d", wrap);
175
255
 
176
- return (Rays::BlendMode) type;
256
+ return (Rays::TexCoordWrap) wrap;
177
257
  }
178
258
 
179
259
 
@@ -1,4 +1,4 @@
1
- #include "rays/noise.h"
1
+ #include "rays/util.h"
2
2
  #include "rays/ruby/point.h"
3
3
  #include "defs.h"
4
4
 
@@ -45,7 +45,7 @@ VALUE simplex(VALUE self)
45
45
 
46
46
 
47
47
  void
48
- Init_rays_noise ()
48
+ Init_rays_util ()
49
49
  {
50
50
  Module mRays = rb_define_module("Rays");
51
51
  rb_define_singleton_method(mRays, "perlin", RUBY_METHOD_FUNC(perlin), -1);
@@ -4,7 +4,6 @@ on:
4
4
  push:
5
5
  branches: [master]
6
6
  pull_request:
7
- branches: [master]
8
7
 
9
8
  jobs:
10
9
  test:
data/ChangeLog.md CHANGED
@@ -1,6 +1,44 @@
1
1
  # rays ChangeLog
2
2
 
3
3
 
4
+ ## [v0.1.48] - 2024-01-08
5
+
6
+ - Add Bitmap#pixels=
7
+ - Add Font#dup, Font#size=, Font.families, and Font.load
8
+ - Add Polyline#with
9
+ - Add Painter#texture, Painter#texcoord_mode, and Painter#texcoord_wrap
10
+
11
+ - Delete Polygon::Line because it was merged into Polyline
12
+
13
+ - Polygon and Polyline can take colors and texcoords for each vertex
14
+ - Polyline.new can take 'hole' parameter
15
+ - 'polygonA + polygonB' means Polygon.new(*polygonA.to_a, *polygonB.to_a)
16
+ - Polygon with only holes raises an ArgumentError
17
+ - Image delegates 'pixels' accessors to Bitmap
18
+ - Use GL_CLAMP_TO_EDGE for texturing
19
+ - Refine Point#inspect(), Color#inspect(), and Font#inspect()
20
+ - default_font() -> get_default_font()
21
+ - rays/include/noise.h -> rays/include/util.h
22
+
23
+ - Fix Polygon.bezier() returns broken object
24
+ - Fix get_pixels() does not work with float colors
25
+
26
+
27
+ ## [v0.1.47] - 2023-12-09
28
+
29
+ - Add Polygon's singleton methods: points(), lines(), triangles(), triangle_strip(), triangle_fan(), quads(), quad_strip()
30
+ - Add create_polygon(DrawMode, ...)
31
+ - Add Painter#stroke_outset
32
+ - Add Bitmap#pixels
33
+ - Use earcut.hpp for polygon triangulation and delete poly2tri
34
+ - Painter#polygon() can take x, y, width, and height
35
+ - Polygon#bounds() caches bounds
36
+ - Polygon.line() -> Polygon.line_strip()
37
+ - Rays::Polygon.new() can take DrawMode
38
+ - Matrix(nullptr) avoids initialization
39
+ - Trigger github actions on all pull_request
40
+
41
+
4
42
  ## [v0.1.46] - 2023-11-09
5
43
 
6
44
  - Use Gemfile to install gems for development instead of add_development_dependency in gemspec
data/Rakefile CHANGED
@@ -25,10 +25,10 @@ use_external_library 'https://github.com/skyrpex/clipper',
25
25
  srcdirs: 'cpp',
26
26
  excludes: 'clipper/cpp/cpp_'
27
27
 
28
- use_external_library 'https://github.com/greenm01/poly2tri',
29
- commit: '88de49021b6d9bef6faa1bc94ceb3fbd85c3c204',
30
- incdirs: 'poly2tri',
31
- srcdirs: 'poly2tri'
28
+ use_external_library 'https://github.com/mapbox/earcut.hpp',
29
+ tag: 'v2.2.4',
30
+ incdirs: 'include/mapbox',
31
+ srcdirs: 'NOSRC'
32
32
 
33
33
  use_external_library 'https://github.com/andrewwillmott/splines-lib',
34
34
  commit: '11e7240d57b0d22871aec3308186a5fcf915ba77',
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.46
1
+ 0.1.48