rays 0.1.46 → 0.1.47

Sign up to get free protection for your applications and to get access to all the features.
data/lib/rays/polygon.rb CHANGED
@@ -24,29 +24,58 @@ module Rays
24
24
  !(self & obj).empty?
25
25
  end
26
26
 
27
- def self.line(*args, loop: false)
28
- new(*args, loop: loop)
27
+ def self.points(*args)
28
+ points! args
29
+ end
30
+
31
+ def self.lines(*args)
32
+ lines! args
33
+ end
34
+
35
+ def self.line_strip(*args, loop: false)
36
+ line_strip! args, loop
29
37
  end
30
38
 
31
39
  def self.rect(
32
- *args, round: nil, lt: nil, rt: nil, lb: nil, rb: nil, nsegment: nil)
40
+ *args, round: nil, lt: nil, rt: nil, lb: nil, rb: nil,
41
+ nsegment: nil)
33
42
 
34
- create_rect args, round, lt, rt, lb, rb, nsegment
43
+ rect! args, round, lt, rt, lb, rb, nsegment
35
44
  end
36
45
 
37
46
  def self.ellipse(
38
47
  *args, center: nil, radius: nil, hole: nil, from: nil, to: nil,
39
48
  nsegment: nil)
40
49
 
41
- create_ellipse args, center, radius, hole, from, to, nsegment
50
+ ellipse! args, center, radius, hole, from, to, nsegment
51
+ end
52
+
53
+ def self.triangles(*args, loop: true)
54
+ triangles! args, loop
55
+ end
56
+
57
+ def self.triangle_strip(*args)
58
+ triangle_strip! args
59
+ end
60
+
61
+ def self.triangle_fan(*args)
62
+ triangle_fan! args
63
+ end
64
+
65
+ def self.quads(*args, loop: true)
66
+ quads! args, loop
67
+ end
68
+
69
+ def self.quad_strip(*args)
70
+ quad_strip! args
42
71
  end
43
72
 
44
73
  def self.curve(*args, loop: false)
45
- create_curve args, loop
74
+ curve! args, loop
46
75
  end
47
76
 
48
77
  def self.bezier(*args, loop: false)
49
- create_bezier args, loop
78
+ bezier! args, loop
50
79
  end
51
80
 
52
81
  end# Polygon
data/rays.gemspec CHANGED
@@ -25,8 +25,8 @@ Gem::Specification.new do |s|
25
25
  s.platform = Gem::Platform::RUBY
26
26
  s.required_ruby_version = '>= 3.0.0'
27
27
 
28
- s.add_runtime_dependency 'xot', '~> 0.1.40'
29
- s.add_runtime_dependency 'rucy', '~> 0.1.41'
28
+ s.add_runtime_dependency 'xot', '~> 0.1.41'
29
+ s.add_runtime_dependency 'rucy', '~> 0.1.42'
30
30
 
31
31
  s.files = `git ls-files`.split $/
32
32
  s.executables = s.files.grep(%r{^bin/}) {|f| File.basename f}
data/src/color_space.cpp CHANGED
@@ -70,8 +70,8 @@ namespace Rays
70
70
  static const int BPPS[] =
71
71
  {
72
72
  0, // UNKNOWN
73
- 8, 16, 24, 32, 32, // GRAY
74
- 8, 16, 24, 32, 32, // ALPHA
73
+ 8, 16, 24, 32, 32, // GRAY
74
+ 8, 16, 24, 32, 32, // ALPHA
75
75
  24, 32, 32, 32, 32, // RGB(A)
76
76
  24, 32, 32, 32, 32, // BGR(A)
77
77
  96, 128, 128, // RGB(A) float
data/src/matrix.cpp CHANGED
@@ -32,6 +32,14 @@ namespace Rays
32
32
  reset(elements, size);
33
33
  }
34
34
 
35
+ Matrix::Matrix (void* null)
36
+ {
37
+ if (null != NULL)
38
+ argument_error(__FILE__, __LINE__);
39
+
40
+ // do nothing to avoid initialization
41
+ }
42
+
35
43
  Matrix
36
44
  Matrix::dup () const
37
45
  {
data/src/painter.cpp CHANGED
@@ -49,6 +49,8 @@ namespace Rays
49
49
 
50
50
  coord stroke_width;
51
51
 
52
+ float stroke_outset;
53
+
52
54
  CapType stroke_cap;
53
55
 
54
56
  JoinType stroke_join;
@@ -71,6 +73,7 @@ namespace Rays
71
73
  colors[FILL] .reset(1, 1);
72
74
  colors[STROKE] .reset(1, 0);
73
75
  stroke_width = 0;
76
+ stroke_outset = 0;
74
77
  stroke_cap = CAP_DEFAULT;
75
78
  stroke_join = JOIN_DEFAULT;
76
79
  miter_limit = JOIN_DEFAULT_MITER_LIMIT;
@@ -797,25 +800,77 @@ namespace Rays
797
800
  #endif
798
801
  }
799
802
 
800
- void
801
- Painter::polygon (const Polygon& polygon)
803
+ static void
804
+ draw_polygon (
805
+ Painter* painter, const Polygon& polygon,
806
+ coord x, coord y, coord width = 0, coord height = 0, bool resize = false)
802
807
  {
808
+ Painter::Data* self = painter->self.get();
809
+
803
810
  if (!self->painting)
804
811
  invalid_state_error(__FILE__, __LINE__, "painting flag should be true.");
805
812
 
806
813
  if (!self->state.has_color())
807
814
  return;
808
815
 
816
+ bool translate = x != 0 || y != 0;
817
+ Matrix matrix(nullptr);
818
+ bool backup = false;
819
+
820
+ if (translate || resize)
821
+ {
822
+ matrix = self->position_matrix;
823
+ backup = true;
824
+
825
+ if (translate)
826
+ self->position_matrix.translate(x, y);
827
+
828
+ if (resize)
829
+ {
830
+ const Bounds& b = polygon.bounds();
831
+ self->position_matrix.scale(width / b.width, height / b.height);
832
+ }
833
+ }
834
+
809
835
  Color color;
810
836
 
811
837
  if (self->get_color(&color, FILL))
812
838
  {
813
- Polygon_fill(polygon, this, color);
814
- debug_draw_triangulation(this, polygon, color);
839
+ Polygon_fill(polygon, painter, color);
840
+ debug_draw_triangulation(painter, polygon, color);
815
841
  }
816
842
 
817
843
  if (self->get_color(&color, STROKE))
818
- Polygon_stroke(polygon, this, color);
844
+ Polygon_stroke(polygon, painter, color);
845
+
846
+ if (backup)
847
+ self->position_matrix = matrix;
848
+ }
849
+
850
+ void
851
+ Painter::polygon (const Polygon& polygon, const coord x, coord y)
852
+ {
853
+ draw_polygon(this, polygon, x, y);
854
+ }
855
+
856
+ void
857
+ Painter::polygon (const Polygon& polygon, const Point& position)
858
+ {
859
+ draw_polygon(this, polygon, position.x, position.y);
860
+ }
861
+
862
+ void
863
+ Painter::polygon (
864
+ const Polygon& polygon, coord x, coord y, coord width, coord height)
865
+ {
866
+ draw_polygon(this, polygon, x, y, width, height, true);
867
+ }
868
+
869
+ void
870
+ Painter::polygon (const Polygon& polygon, const Bounds& bounds)
871
+ {
872
+ draw_polygon(
873
+ this, polygon, bounds.x, bounds.y, bounds.width, bounds.height, true);
819
874
  }
820
875
 
821
876
  void
@@ -1310,6 +1365,18 @@ namespace Rays
1310
1365
  return self->state.stroke_width;
1311
1366
  }
1312
1367
 
1368
+ void
1369
+ Painter::set_stroke_outset (float outset)
1370
+ {
1371
+ self->state.stroke_outset = outset;
1372
+ }
1373
+
1374
+ float
1375
+ Painter::stroke_outset () const
1376
+ {
1377
+ return self->state.stroke_outset;
1378
+ }
1379
+
1313
1380
  void
1314
1381
  Painter::set_stroke_cap (CapType cap)
1315
1382
  {