gui_geometry 0.0.4 → 0.0.5

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/README.md CHANGED
@@ -27,37 +27,39 @@ require "gui_geometry"
27
27
  include GuiGeometry::Tools
28
28
 
29
29
  # create point x == y == 0
30
- > point
31
- => point(0,0)
30
+ point
31
+ # => point(0,0)
32
32
 
33
33
  # create a point x=3, y=4
34
- > my_point = point(3,4)
35
- => point(3,4)
34
+ my_point = point(3,4)
35
+ # => point(3,4)
36
36
 
37
- > [my_point.x, my_point.y]
38
- => [3, 4]
37
+ [my_point.x, my_point.y]
38
+ # => [3, 4]
39
39
 
40
- # create a rectangle with location (top-left corner) = poiunt(4,5), width=100, height=80
41
- > rect(4,5,100,80)
42
- => rect(4,5,100,80)
43
- > my_rect = rect point(4,5), point(100,80) # alternate form
44
- => rect(4,5,100,80)
40
+ # create a rectangle - x, y, w, h form
41
+ rect(4,5,100,80)
42
+ # => rect(4,5,100,80)
45
43
 
46
- # create a rect with location == point(0,0), size = point(30,50) (width = 30, height = 50)
47
- > rect point(30,50)
48
- => rect(0,0,30,50)
44
+ # create rectangle - location, size form
45
+ my_rect = rect point(4,5), point(100,80)
46
+ # => rect(4,5,100,80)
47
+
48
+ # create rectangle - size form (location defaults to 0,0
49
+ rect point(30,50)
50
+ # => rect(0,0,30,50)
49
51
 
50
52
  # get loc and size:
51
- > [my_rect.loc, my_rect.size]
52
- => [point(4,5), point(100,80)]
53
+ [my_rect.loc, my_rect.size]
54
+ # => [point(4,5), point(100,80)]
53
55
 
54
56
  # get x, y, width and height
55
- > [my_rect.x, my_rect.y, my_rect.w, my_rect.h]
56
- => [4, 5, 100, 80]
57
+ [my_rect.x, my_rect.y, my_rect.w, my_rect.h]
58
+ # => [4, 5, 100, 80]
57
59
 
58
60
  # get the 4 corners:
59
- > [my_rect.tl, my_rect.tr, my_rect.bl, my_rect.br]
60
- => [point(4,5), point(104,5), point(4,85), point(104,85)]
61
+ [my_rect.tl, my_rect.tr, my_rect.bl, my_rect.br]
62
+ # => [point(4,5), point(104,5), point(4,85), point(104,85)]
61
63
 
62
64
  ```
63
65
 
data/lib/gui_geometry.rb CHANGED
@@ -7,7 +7,3 @@
7
7
  }.each do |file|
8
8
  require File.join(File.dirname(__FILE__),"gui_geometry",file)
9
9
  end
10
-
11
- module GuiGeometry
12
- # Your code goes here...
13
- end
@@ -2,7 +2,14 @@ module GuiGeometry
2
2
  module Tools
3
3
  def min(a,b) a < b ? a : b; end
4
4
  def max(a,b) a > b ? a : b; end
5
- def bound(a,bounded,c) bounded < a ? a : (bounded > c) ? c : bounded; end
5
+ def minmax(a,b)
6
+ if a <= b
7
+ return a, b
8
+ else
9
+ return b, a
10
+ end
11
+ end
12
+ def bound(a,bounded,c) max(a,min(bounded,c)); end
6
13
 
7
14
  def point(*args); GuiGeometry::Point.new *args end
8
15
  def rect(*args); GuiGeometry::Rectangle.new *args end
@@ -1,3 +1,3 @@
1
1
  module GuiGeometry
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
data/spec/tools_spec.rb CHANGED
@@ -6,6 +6,29 @@ describe "Tools" do
6
6
 
7
7
  it "min" do
8
8
  min(4,5).should == 4
9
+ min(5,4).should == 4
10
+ end
11
+
12
+ it "max" do
13
+ max(4,5).should == 5
14
+ max(5,4).should == 5
15
+ end
16
+
17
+ it "bound" do
18
+ bound(2,5,7).should == 5
19
+ bound(2,1,7).should == 2
20
+ bound(2,8,7).should == 7
21
+ bound(2,8,1).should == 2
22
+ end
23
+
24
+ it "minmax" do
25
+ minmax(4,5).should == [4,5]
26
+ minmax(5,4).should == [4,5]
27
+ end
28
+
29
+ it "easy constructors" do
30
+ point.class.should == Point
31
+ rect.class.should == Rectangle
9
32
  end
10
33
  end
11
34
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gui_geometry
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-23 00:00:00.000000000 Z
12
+ date: 2013-01-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake