summaryrefslogtreecommitdiffhomepage
path: root/lib
diff options
context:
space:
mode:
authorTom Black <[email protected]>2019-01-06 02:22:14 -0800
committerTom Black <[email protected]>2019-01-06 02:22:14 -0800
commit9994b770686428ebbde636081156abb5a50dc6c2 (patch)
tree745d89e4d017b4b6dda4056d98c6a8fbcc956a72 /lib
parent742bb574dc506fbb7a8d1774c44736ad0e228c54 (diff)
downloadruby2d-9994b770686428ebbde636081156abb5a50dc6c2.tar.gz
ruby2d-9994b770686428ebbde636081156abb5a50dc6c2.zip
Tests and fixes to the public API
Namely to ensure attribute getters/setters are consistent
Diffstat (limited to 'lib')
-rw-r--r--lib/ruby2d/circle.rb2
-rw-r--r--lib/ruby2d/line.rb6
-rw-r--r--lib/ruby2d/music.rb4
-rw-r--r--lib/ruby2d/quad.rb2
-rw-r--r--lib/ruby2d/renderable.rb2
-rw-r--r--lib/ruby2d/sprite.rb1
-rw-r--r--lib/ruby2d/text.rb4
-rw-r--r--lib/ruby2d/triangle.rb7
8 files changed, 14 insertions, 14 deletions
diff --git a/lib/ruby2d/circle.rb b/lib/ruby2d/circle.rb
index d232d68..7951db7 100644
--- a/lib/ruby2d/circle.rb
+++ b/lib/ruby2d/circle.rb
@@ -4,7 +4,7 @@ module Ruby2D
class Circle
include Renderable
- attr_accessor :radius, :sectors
+ attr_accessor :x, :y, :radius, :sectors
def initialize(opts = {})
@x = opts[:x] || 25
diff --git a/lib/ruby2d/line.rb b/lib/ruby2d/line.rb
index fa3535d..ebbb0d9 100644
--- a/lib/ruby2d/line.rb
+++ b/lib/ruby2d/line.rb
@@ -4,15 +4,15 @@ module Ruby2D
class Line
include Renderable
- attr_accessor :x1, :x2, :y1, :y2
+ attr_accessor :x1, :x2, :y1, :y2, :width
def initialize(opts = {})
@x1 = opts[:x1] || 0
@y1 = opts[:y1] || 0
@x2 = opts[:x2] || 100
@y2 = opts[:y2] || 100
- @width = opts[:width] || 2
@z = opts[:z] || 0
+ @width = opts[:width] || 2
self.color = opts[:color] || 'white'
self.opacity = opts[:opacity] if opts[:opacity]
add
@@ -53,7 +53,7 @@ module Ruby2D
@c3 = c[2]
@c4 = c[3]
else
- raise ArgumentError, "Lines require 4 colors, one for each vertex. #{c.length} were given."
+ raise ArgumentError, "`#{self.class}` requires 4 colors, one for each vertex. #{c.length} were given."
end
else
@c1 = c
diff --git a/lib/ruby2d/music.rb b/lib/ruby2d/music.rb
index 46aab0a..3c9406f 100644
--- a/lib/ruby2d/music.rb
+++ b/lib/ruby2d/music.rb
@@ -6,12 +6,12 @@ module Ruby2D
attr_reader :path
attr_accessor :loop, :data
- def initialize(path)
+ def initialize(path, opts = {})
unless File.exist? path
raise Error, "Cannot find audio file `#{path}`"
end
@path = path
- @loop = false
+ @loop = opts[:loop] || false
unless ext_init(@path)
raise Error, "Music `#{@path}` cannot be created"
end
diff --git a/lib/ruby2d/quad.rb b/lib/ruby2d/quad.rb
index 6315ae7..08cee84 100644
--- a/lib/ruby2d/quad.rb
+++ b/lib/ruby2d/quad.rb
@@ -62,7 +62,7 @@ module Ruby2D
@c3 = c[2]
@c4 = c[3]
else
- raise ArgumentError, "Quads require 4 colors, one for each vertex. #{c.length} were given."
+ raise ArgumentError, "`#{self.class}` requires 4 colors, one for each vertex. #{c.length} were given."
end
else
@c1 = c
diff --git a/lib/ruby2d/renderable.rb b/lib/ruby2d/renderable.rb
index 2861c70..d6e7ae8 100644
--- a/lib/ruby2d/renderable.rb
+++ b/lib/ruby2d/renderable.rb
@@ -49,7 +49,7 @@ module Ruby2D
# Add a contains method stub
def contains?(x, y)
- x > @x && x < (@x + @width) && y > @y && y < (@y + @height)
+ x >= @x && x <= (@x + @width) && y >= @y && y <= (@y + @height)
end
end
diff --git a/lib/ruby2d/sprite.rb b/lib/ruby2d/sprite.rb
index 8405e5f..ca64e0b 100644
--- a/lib/ruby2d/sprite.rb
+++ b/lib/ruby2d/sprite.rb
@@ -4,6 +4,7 @@ module Ruby2D
class Sprite
include Renderable
+ attr_reader :path
attr_accessor :rotate, :loop, :clip_x, :clip_y, :clip_width, :clip_height, :data
def initialize(path, opts = {})
diff --git a/lib/ruby2d/text.rb b/lib/ruby2d/text.rb
index d62bc0b..10fdabe 100644
--- a/lib/ruby2d/text.rb
+++ b/lib/ruby2d/text.rb
@@ -4,8 +4,8 @@ module Ruby2D
class Text
include Renderable
- attr_reader :text, :size, :font
- attr_accessor :x, :y, :rotate, :data
+ attr_reader :text, :font
+ attr_accessor :x, :y, :size, :rotate, :data
def initialize(text, opts = {})
@x = opts[:x] || 0
diff --git a/lib/ruby2d/triangle.rb b/lib/ruby2d/triangle.rb
index a4d6d27..63c570b 100644
--- a/lib/ruby2d/triangle.rb
+++ b/lib/ruby2d/triangle.rb
@@ -26,9 +26,8 @@ module Ruby2D
update_color(@color)
end
- # Point is inside a triangle if
- # the area of 3 triangles, constructed from triangle sides and that point
- # is equal to the area of triangle.
+ # A point is inside a triangle if the area of 3 triangles, constructed from
+ # triangle sides and the given point, is equal to the area of triangle.
def contains?(x, y)
self_area = triangle_area(@x1, @y1, @x2, @y2, @x3, @y3)
questioned_area =
@@ -52,7 +51,7 @@ module Ruby2D
@c2 = c[1]
@c3 = c[2]
else
- raise ArgumentError, "Triangles require 3 colors, one for each vertex. #{c.length} were given."
+ raise ArgumentError, "`#{self.class}` requires 3 colors, one for each vertex. #{c.length} were given."
end
else
@c1 = c