rubydraw 0.1.7.1 → 0.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/rubydraw/point.rb +14 -0
- data/lib/rubydraw/rectangle.rb +36 -0
- data/lib/rubydraw.rb +2 -1
- metadata +4 -4
data/lib/rubydraw/point.rb
CHANGED
@@ -18,5 +18,19 @@ module Rubydraw
|
|
18
18
|
end
|
19
19
|
@x, @y = x, y
|
20
20
|
end
|
21
|
+
|
22
|
+
# Returns if this self falls within the given rectangle.
|
23
|
+
def inside?(min, max)
|
24
|
+
(x.between?(min.x, max.x)) and (y.between?(min.y, max.y))
|
25
|
+
end
|
26
|
+
|
27
|
+
# Add this point's x and y positions to other's x and y positions.
|
28
|
+
#
|
29
|
+
# Example:
|
30
|
+
# # This produces #<Rubydraw::Point:0x1010f1958 @y=10, @x=60>
|
31
|
+
# Rubydraw::Point[10, 20] + Rubydraw::Point[50, -10]
|
32
|
+
def +(other)
|
33
|
+
Point[self.x + other.x, self.y + other.y]
|
34
|
+
end
|
21
35
|
end
|
22
36
|
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Rubydraw
|
2
|
+
# A Rectangle is defined by the position, width, and height, and knows if a point
|
3
|
+
# falls inside it. One good use for this class would be a button (will be implemented
|
4
|
+
# in a future version, probably soon)
|
5
|
+
class Rectangle
|
6
|
+
attr_reader(:position, :width, :height)
|
7
|
+
|
8
|
+
# Create a new rectangle with the given dimensions and position.
|
9
|
+
def initialize(width, height, position)
|
10
|
+
@width, @height, @position = width, height, position
|
11
|
+
end
|
12
|
+
|
13
|
+
# Returns the x position for the rectangle
|
14
|
+
def x
|
15
|
+
@position.x
|
16
|
+
end
|
17
|
+
|
18
|
+
# Returns this rectangle's y position
|
19
|
+
def y
|
20
|
+
@position.y
|
21
|
+
end
|
22
|
+
|
23
|
+
# Returns the positon of the top left corner
|
24
|
+
alias top_left position
|
25
|
+
|
26
|
+
# Returns the position at the bottom right
|
27
|
+
def bottom_right
|
28
|
+
Point[x + @width, y + @height]
|
29
|
+
end
|
30
|
+
|
31
|
+
# Returns if the given point is inside this rectangle. See Rubydraw::Point::inside?
|
32
|
+
def contains?(point)
|
33
|
+
point.inside?(top_left, bottom_right)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/lib/rubydraw.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubydraw
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 11
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
|
11
|
-
version: 0.1.7.1
|
9
|
+
- 8
|
10
|
+
version: 0.1.8
|
12
11
|
platform: ruby
|
13
12
|
authors:
|
14
13
|
- J. Wostenberg
|
@@ -60,6 +59,7 @@ files:
|
|
60
59
|
- lib/rubydraw/events.rb
|
61
60
|
- lib/rubydraw/point.rb
|
62
61
|
- lib/rubydraw/color.rb
|
62
|
+
- lib/rubydraw/rectangle.rb
|
63
63
|
- examples/window_ex.rb
|
64
64
|
- examples/image_ex.rb
|
65
65
|
- examples/sound_ex.rb
|