geometry-in-ruby 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/geometry-in-ruby.gemspec +1 -1
- data/lib/geometry/edge.rb +5 -0
- data/lib/geometry/line.rb +105 -87
- data/lib/geometry/polygon.rb +5 -1
- data/lib/geometry/polyline.rb +5 -0
- data/lib/geometry/rectangle.rb +5 -1
- data/lib/geometry/square.rb +5 -1
- data/lib/geometry/text.rb +5 -0
- metadata +5 -7
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
MTBkMWEwZmMyZDA3ZDRjM2U5MTA1MTYzZjk0OWUzOTYzZTdmMDMzNg==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
YWM5NTNhNWY0ZDMzZjEzNzc4MGNmYmFhZTZjZTg5NTZkZTZhOThjYw==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
YzdlMmNkNWRhZmFiZTkzYzNjZGYzMTUzMmVmOTBhNmE1ZDQwZDlkYThmZTBk
|
10
|
+
NzkxYzFkMWUwYzFkMzc0NTI0NDk0MDlhYjczZjc5YzljMWY2ZGE5ZGYzZDI0
|
11
|
+
N2Y0NWIxMWQ5ZWI5NGY3MjlhMGI2MTBjYjUzYjlhMTMyMTNiODg=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
MzU0NTk0MjMwOWEzN2FkZDY0NGU5N2I5NmRjYjhhNWVkMDkzYWI1ZTVlZmIw
|
14
|
+
Y2Y1YmU1ZTU2OWZlMmI0N2I4NWE4NGFkNjRlMTAxY2YxZGMzMzU5ZGZkOTM3
|
15
|
+
Y2IwMGE3ZDBhZTk2YTQxZjg2N2ZkZGJlZTczOWEwYTk0MmQ5Nzg=
|
data/geometry-in-ruby.gemspec
CHANGED
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
|
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "geometry-in-ruby"
|
6
|
-
s.version = '0.0.
|
6
|
+
s.version = '0.0.2'
|
7
7
|
s.authors = ["Brandon Fosdick", "Meseker Yohannes"]
|
8
8
|
s.email = ["meseker.yohannes@gmail.com"]
|
9
9
|
s.homepage = "http://github.com/meseker/geometry"
|
data/lib/geometry/edge.rb
CHANGED
@@ -14,6 +14,11 @@ An edge. It's a line segment between 2 points. Generally part of a {Polygon}.
|
|
14
14
|
|
15
15
|
class Edge
|
16
16
|
attr_reader :first, :last
|
17
|
+
attr_writer :options
|
18
|
+
def options
|
19
|
+
@options = {} if !@options
|
20
|
+
@options
|
21
|
+
end
|
17
22
|
|
18
23
|
# Construct a new {Edge} object from any two things that can be converted
|
19
24
|
# to a {Point}.
|
data/lib/geometry/line.rb
CHANGED
@@ -28,9 +28,17 @@ Supports two-point, slope-intercept, and point-slope initializer forms
|
|
28
28
|
Geometry::Line.vertical(x=0)
|
29
29
|
=end
|
30
30
|
|
31
|
-
|
31
|
+
############
|
32
|
+
#/# Line #/#
|
33
|
+
############
|
34
|
+
class Line
|
32
35
|
include ClusterFactory
|
33
|
-
|
36
|
+
attr_writer :options
|
37
|
+
def options
|
38
|
+
@options = {} if !@options
|
39
|
+
@options
|
40
|
+
end
|
41
|
+
|
34
42
|
# @overload [](Array, Array)
|
35
43
|
# @return [TwoPointLine]
|
36
44
|
# @overload [](Point, Point)
|
@@ -42,20 +50,20 @@ Supports two-point, slope-intercept, and point-slope initializer forms
|
|
42
50
|
# @overload [](point, slope)
|
43
51
|
# @return [PointSlopeLine]
|
44
52
|
def self.[](*args)
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
53
|
+
if( 2 == args.size )
|
54
|
+
args.map! {|x| x.is_a?(Array) ? Point[*x] : x}
|
55
|
+
|
56
|
+
# If both args are Points, create a TwoPointLine
|
57
|
+
return TwoPointLine.new(*args) if args.all? {|x| x.is_a?(Vector)}
|
58
|
+
|
59
|
+
# If only the first arg is a Point, create a PointSlopeLine
|
60
|
+
return PointSlopeLine.new(*args) if args.first.is_a?(Vector)
|
61
|
+
|
62
|
+
# Otherise, create a SlopeInterceptLine
|
63
|
+
return SlopeInterceptLine.new(*args)
|
64
|
+
else
|
65
|
+
nil
|
66
|
+
end
|
59
67
|
end
|
60
68
|
|
61
69
|
# @overload new(from, to)
|
@@ -67,16 +75,16 @@ Supports two-point, slope-intercept, and point-slope initializer forms
|
|
67
75
|
# @option options [Point] :end An end {Point}
|
68
76
|
# @return [TwoPointLine]
|
69
77
|
def self.new(options={})
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
78
|
+
from = options[:from] || options[:start]
|
79
|
+
to = options[:end] || options[:to]
|
80
|
+
|
81
|
+
if from and to
|
82
|
+
TwoPointLine.new(from, to)
|
83
|
+
else
|
84
|
+
raise ArgumentError, "Start and end Points must be provided"
|
77
85
|
end
|
78
86
|
end
|
79
|
-
|
87
|
+
|
80
88
|
def self.horizontal(y_intercept=0)
|
81
89
|
SlopeInterceptLine.new(0, y_intercept)
|
82
90
|
end
|
@@ -84,71 +92,81 @@ Supports two-point, slope-intercept, and point-slope initializer forms
|
|
84
92
|
SlopeInterceptLine.new(1/0.0, x_intercept)
|
85
93
|
end
|
86
94
|
end
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
class SlopeInterceptLine < Line
|
104
|
-
# @return [Number] the slope of the {Line}
|
105
|
-
attr_reader :slope
|
106
|
-
|
107
|
-
def initialize(slope, intercept)
|
108
|
-
@slope = slope
|
109
|
-
@intercept = intercept
|
95
|
+
|
96
|
+
######################
|
97
|
+
#/# PointSlopeLine #/#
|
98
|
+
######################
|
99
|
+
# @private
|
100
|
+
class PointSlopeLine < Line
|
101
|
+
# @return [Number] the slope of the {Line}
|
102
|
+
attr_reader :slope
|
103
|
+
|
104
|
+
def initialize(point, slope)
|
105
|
+
@point = Point[point]
|
106
|
+
@slope = slope
|
107
|
+
end
|
108
|
+
def to_s
|
109
|
+
'Line(' + @slope.to_s + ',' + @point.to_s + ')'
|
110
|
+
end
|
110
111
|
end
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
# @group Accessors
|
146
|
-
# !@attribute [r[ slope
|
147
|
-
# @return [Number] the slope of the {Line}
|
148
|
-
def slope
|
149
|
-
(last.y - first.y)/(last.x - first.x)
|
112
|
+
|
113
|
+
##########################
|
114
|
+
#/# SlopeInterceptLine #/#
|
115
|
+
##########################
|
116
|
+
# @private
|
117
|
+
class SlopeInterceptLine < Line
|
118
|
+
# @return [Number] the slope of the {Line}
|
119
|
+
attr_reader :slope
|
120
|
+
|
121
|
+
def initialize(slope, intercept)
|
122
|
+
@slope = slope
|
123
|
+
@intercept = intercept
|
124
|
+
end
|
125
|
+
|
126
|
+
def horizontal?
|
127
|
+
0 == @slope
|
128
|
+
end
|
129
|
+
|
130
|
+
def vertical?
|
131
|
+
(1/0.0) == @slope
|
132
|
+
end
|
133
|
+
|
134
|
+
def intercept(axis=:y)
|
135
|
+
case axis
|
136
|
+
when :x
|
137
|
+
vertical? ? @intercept : (horizontal? ? nil : (-@intercept/@slope))
|
138
|
+
when :y
|
139
|
+
vertical? ? nil : @intercept
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
def to_s
|
144
|
+
'Line(' + @slope.to_s + ',' + @intercept.to_s + ')'
|
145
|
+
end
|
150
146
|
end
|
147
|
+
|
148
|
+
####################
|
149
|
+
#/# TwoPointLine #/#
|
150
|
+
####################
|
151
|
+
# @private
|
152
|
+
class TwoPointLine < Line
|
153
|
+
attr_reader :first, :last
|
154
|
+
|
155
|
+
def initialize(point0, point1)
|
156
|
+
@first, @last = [Point[point0], Point[point1]]
|
157
|
+
end
|
158
|
+
def inspect
|
159
|
+
'Line(' + @first.inspect + ', ' + @last.inspect + ')'
|
160
|
+
end
|
161
|
+
alias :to_s :inspect
|
162
|
+
|
163
|
+
# @group Accessors
|
164
|
+
# !@attribute [r[ slope
|
165
|
+
# @return [Number] the slope of the {Line}
|
166
|
+
def slope
|
167
|
+
(last.y - first.y)/(last.x - first.x)
|
168
|
+
end
|
151
169
|
# @endgroup
|
152
|
-
|
170
|
+
end
|
153
171
|
end
|
154
172
|
|
data/lib/geometry/polygon.rb
CHANGED
@@ -16,7 +16,11 @@ but there's currently nothing that enforces simplicity.
|
|
16
16
|
=end
|
17
17
|
|
18
18
|
class Polygon < Polyline
|
19
|
-
|
19
|
+
attr_writer :options
|
20
|
+
def options
|
21
|
+
@options = {} if !@options
|
22
|
+
@options
|
23
|
+
end
|
20
24
|
# Construct a new Polygon from Points and/or Edges
|
21
25
|
# The constructor will try to convert all of its arguments into Points and
|
22
26
|
# Edges. Then successive Points will be collpased into Edges. Successive
|
data/lib/geometry/polyline.rb
CHANGED
@@ -14,6 +14,11 @@ also like a {Path} in that it isn't necessarily closed.
|
|
14
14
|
|
15
15
|
class Polyline
|
16
16
|
attr_reader :edges, :vertices
|
17
|
+
attr_writer :options
|
18
|
+
def options
|
19
|
+
@options = {} if !@options
|
20
|
+
@options
|
21
|
+
end
|
17
22
|
|
18
23
|
# Construct a new Polyline from Points and/or Edges
|
19
24
|
# @note The constructor will try to convert all of its arguments into {Point}s and
|
data/lib/geometry/rectangle.rb
CHANGED
@@ -35,7 +35,11 @@ The {Rectangle} class cluster represents your typical arrangement of 4 corners a
|
|
35
35
|
attr_reader :size
|
36
36
|
# @return [Number] Width of the {Rectangle}
|
37
37
|
attr_reader :width
|
38
|
-
|
38
|
+
attr_writer :options
|
39
|
+
def options
|
40
|
+
@options = {} if !@options
|
41
|
+
end
|
42
|
+
|
39
43
|
# @overload new(width, height)
|
40
44
|
# Creates a {Rectangle} of the given width and height, centered on the origin
|
41
45
|
# @param [Number] height Height
|
data/lib/geometry/square.rb
CHANGED
@@ -13,7 +13,11 @@ The {Square} class cluster is like the {Rectangle} class cluster, but not longer
|
|
13
13
|
=end
|
14
14
|
class Square
|
15
15
|
attr_reader :origin
|
16
|
-
|
16
|
+
attr_writer :options
|
17
|
+
def options
|
18
|
+
@options = {} if !@options
|
19
|
+
end
|
20
|
+
|
17
21
|
# Creates a {Square} given two {Point}s
|
18
22
|
# @option options [Point] :from A corner (ie. bottom-left)
|
19
23
|
# @option options [Point] :to The other corner (ie. top-right)
|
data/lib/geometry/text.rb
CHANGED
metadata
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: geometry-in-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.0.2
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Brandon Fosdick
|
@@ -10,7 +9,7 @@ authors:
|
|
10
9
|
autorequire:
|
11
10
|
bindir: bin
|
12
11
|
cert_chain: []
|
13
|
-
date: 2014-03-
|
12
|
+
date: 2014-03-21 00:00:00.000000000 Z
|
14
13
|
dependencies: []
|
15
14
|
description: Geometric primitives and algorithms for Ruby
|
16
15
|
email:
|
@@ -71,27 +70,26 @@ files:
|
|
71
70
|
- test/geometry/vector.rb
|
72
71
|
homepage: http://github.com/meseker/geometry
|
73
72
|
licenses: []
|
73
|
+
metadata: {}
|
74
74
|
post_install_message:
|
75
75
|
rdoc_options: []
|
76
76
|
require_paths:
|
77
77
|
- lib
|
78
78
|
required_ruby_version: !ruby/object:Gem::Requirement
|
79
|
-
none: false
|
80
79
|
requirements:
|
81
80
|
- - ! '>='
|
82
81
|
- !ruby/object:Gem::Version
|
83
82
|
version: '0'
|
84
83
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
85
|
-
none: false
|
86
84
|
requirements:
|
87
85
|
- - ! '>='
|
88
86
|
- !ruby/object:Gem::Version
|
89
87
|
version: '0'
|
90
88
|
requirements: []
|
91
89
|
rubyforge_project: aurora_geometry
|
92
|
-
rubygems_version:
|
90
|
+
rubygems_version: 2.2.2
|
93
91
|
signing_key:
|
94
|
-
specification_version:
|
92
|
+
specification_version: 4
|
95
93
|
summary: Geometric primitives and algoritms
|
96
94
|
test_files:
|
97
95
|
- test/geometry.rb
|