geometry-in-ruby 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.
- checksums.yaml +8 -8
- data/geometry-in-ruby.gemspec +1 -1
- data/lib/geometry/arc.rb +76 -76
- data/lib/geometry/circle.rb +6 -2
- data/lib/geometry/edge.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZDBiMTc5MWYyZTU4Nzk3YjIwYjE4N2I5ODQ1Njc0Njk3MTU2YjIxYg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ZTFkMjM4M2I0ZGI1MDRiY2EwOWY0NGI4ZWIxMzg1OGQ5M2RkZTM2OA==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YTJlMjJjN2JhYzM3YmViNWRhOGRmNWJmYjI2YjIzOTRkZmIyNDUxNjIyZTZh
|
10
|
+
ZGJjMGRlNzk0MTMzZjRlZTk2ZDMxYjY2OTQ1MmFjNWE0OTExZjlmNjYxYTZm
|
11
|
+
MDcyNmJmNzU0ZTI1OWVjZDZiNDk1MzBmZDkzMDJjYzBmMWZkZGQ=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
Y2ZhZTYzM2FhMDlhYmFhOWEzMDNhNjg2YWY2N2I4YWMyYzQ5ZWE2NmQ2ZTE0
|
14
|
+
OTFlM2RiZmM4YWY4MDZiMTQ5MGQ0ZjBlYTdjMmQxOWIyYWE3OTIzZjE1M2Ni
|
15
|
+
NWNjNmU0ZDE4YThmZDkyYzhjNjljOGRhMTc4MmJkNDg0ZDhkZTk=
|
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.5'
|
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/arc.rb
CHANGED
@@ -13,87 +13,87 @@ An {Arc} with its center at [1,1] and a radius of 2 that starts at the X-axis an
|
|
13
13
|
arc = Geometry::Arc.new center:[1,1], radius:2, start:0, end:90
|
14
14
|
=end
|
15
15
|
|
16
|
-
|
17
|
-
|
16
|
+
class Arc
|
17
|
+
include ClusterFactory
|
18
|
+
|
19
|
+
attr_reader :center
|
20
|
+
attr_reader :radius
|
21
|
+
attr_reader :start_angle, :end_angle
|
22
|
+
attr_writer :options
|
23
|
+
def options
|
24
|
+
@options = {} if !@options
|
25
|
+
@options
|
26
|
+
end
|
18
27
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
@
|
25
|
-
@
|
28
|
+
# @overload new(center, start, end)
|
29
|
+
# Create a new {Arc} given center, start and end {Point}s
|
30
|
+
# @option options [Point] :center (PointZero) The {Point} at the center
|
31
|
+
# @option options [Point] :start The {Arc} starts at the start {Point}
|
32
|
+
# @option options [Point] :end The {Point} where it all ends
|
33
|
+
# @return [Arc]
|
34
|
+
# @overload new(center, radius, start, end)
|
35
|
+
# Create a new {Arc} given a center {Point}, a radius and start and end angles
|
36
|
+
# @option options [Point] :center (PointZero) The {Point} at the center of it all
|
37
|
+
# @option options [Numeric] :radius Radius
|
38
|
+
# @option options [Numeric] :start Starting angle
|
39
|
+
# @option options [Numeric] :end Ending angle
|
40
|
+
# @return [ThreePointArc]
|
41
|
+
def self.new(options={})
|
42
|
+
center = options.delete(:center) || PointZero.new
|
43
|
+
|
44
|
+
if options.has_key?(:radius)
|
45
|
+
original_new(center, options[:radius], options[:start], options[:end])
|
46
|
+
else
|
47
|
+
ThreePointArc.new(center, options[:start], options[:end])
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
# Construct a new {Arc}
|
52
|
+
# @overload initialize(center, radius, start_angle, end_angle)
|
53
|
+
# @param [Point] center The {Point} at the center of it all
|
54
|
+
# @param [Numeric] radius Radius
|
55
|
+
# @param [Numeric] start_angle Starting angle
|
56
|
+
# @param [Numeric] end_angle Ending angle
|
57
|
+
def initialize(center, radius, start_angle, end_angle)
|
58
|
+
@center = Point[center]
|
59
|
+
@radius = radius
|
60
|
+
@start_angle = start_angle
|
61
|
+
@end_angle = end_angle
|
62
|
+
end
|
63
|
+
|
64
|
+
# @return [Point] The starting point of the {Arc}
|
65
|
+
def first
|
66
|
+
@center + @radius * Vector[Math.cos(@start_angle), Math.sin(@start_angle)]
|
67
|
+
end
|
68
|
+
|
69
|
+
# @return [Point] The end point of the {Arc}
|
70
|
+
def last
|
71
|
+
@center + @radius * Vector[Math.cos(@end_angle), Math.sin(@end_angle)]
|
72
|
+
end
|
26
73
|
end
|
27
74
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
# @option options [Point] :start The {Arc} starts at the start {Point}
|
32
|
-
# @option options [Point] :end The {Point} where it all ends
|
33
|
-
# @return [Arc]
|
34
|
-
# @overload new(center, radius, start, end)
|
35
|
-
# Create a new {Arc} given a center {Point}, a radius and start and end angles
|
36
|
-
# @option options [Point] :center (PointZero) The {Point} at the center of it all
|
37
|
-
# @option options [Numeric] :radius Radius
|
38
|
-
# @option options [Numeric] :start Starting angle
|
39
|
-
# @option options [Numeric] :end Ending angle
|
40
|
-
# @return [ThreePointArc]
|
41
|
-
def self.new(options={})
|
42
|
-
center = options.delete(:center) || PointZero.new
|
75
|
+
class ThreePointArc < Arc
|
76
|
+
attr_reader :center
|
77
|
+
attr_reader :start, :end
|
43
78
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
79
|
+
# Contruct a new {Arc} given center, start and end {Point}s
|
80
|
+
# Always assumes that the {Arc} is counter-clockwise. Reverse the order
|
81
|
+
# of the start and end points to get an {Arc} that goes around the other way.
|
82
|
+
# @overload initialize(center_point, start_point, end_point)
|
83
|
+
# @param [Point] center_point The {Point} at the center
|
84
|
+
# @param [Point] start_point The {Arc} starts at the start {Point}
|
85
|
+
# @param [Point] end_point The {Point} where it all ends
|
86
|
+
def initialize(center_point, start_point, end_point)
|
87
|
+
@center, @start, @end = [center_point, start_point, end_point].map {|p| Point[p]}
|
88
|
+
raise ArgumentError unless [@center, @start, @end].all? {|p| p.is_a?(Point)}
|
89
|
+
end
|
50
90
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
# @param [Numeric] radius Radius
|
55
|
-
# @param [Numeric] start_angle Starting angle
|
56
|
-
# @param [Numeric] end_angle Ending angle
|
57
|
-
def initialize(center, radius, start_angle, end_angle)
|
58
|
-
@center = Point[center]
|
59
|
-
@radius = radius
|
60
|
-
@start_angle = start_angle
|
61
|
-
@end_angle = end_angle
|
62
|
-
end
|
91
|
+
# The starting point of the {Arc}
|
92
|
+
# @return [Point]
|
93
|
+
alias :first :start
|
63
94
|
|
64
|
-
|
65
|
-
|
66
|
-
|
95
|
+
# The end point of the {Arc}
|
96
|
+
# @return [Point]
|
97
|
+
alias :last :end
|
67
98
|
end
|
68
|
-
|
69
|
-
# @return [Point] The end point of the {Arc}
|
70
|
-
def last
|
71
|
-
@center + @radius * Vector[Math.cos(@end_angle), Math.sin(@end_angle)]
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
class ThreePointArc < Arc
|
76
|
-
attr_reader :center
|
77
|
-
attr_reader :start, :end
|
78
|
-
|
79
|
-
# Contruct a new {Arc} given center, start and end {Point}s
|
80
|
-
# Always assumes that the {Arc} is counter-clockwise. Reverse the order
|
81
|
-
# of the start and end points to get an {Arc} that goes around the other way.
|
82
|
-
# @overload initialize(center_point, start_point, end_point)
|
83
|
-
# @param [Point] center_point The {Point} at the center
|
84
|
-
# @param [Point] start_point The {Arc} starts at the start {Point}
|
85
|
-
# @param [Point] end_point The {Point} where it all ends
|
86
|
-
def initialize(center_point, start_point, end_point)
|
87
|
-
@center, @start, @end = [center_point, start_point, end_point].map {|p| Point[p]}
|
88
|
-
raise ArgumentError unless [@center, @start, @end].all? {|p| p.is_a?(Point)}
|
89
|
-
end
|
90
|
-
|
91
|
-
# The starting point of the {Arc}
|
92
|
-
# @return [Point]
|
93
|
-
alias :first :start
|
94
|
-
|
95
|
-
# The end point of the {Arc}
|
96
|
-
# @return [Point]
|
97
|
-
alias :last :end
|
98
|
-
end
|
99
99
|
end
|
data/lib/geometry/circle.rb
CHANGED
@@ -13,7 +13,7 @@ Circles come in all shapes and sizes, but they're usually round.
|
|
13
13
|
circle = Geometry::Circle.new diameter:6
|
14
14
|
=end
|
15
15
|
|
16
|
-
|
16
|
+
class Circle
|
17
17
|
include ClusterFactory
|
18
18
|
|
19
19
|
# @return [Point] The {Circle}'s center point
|
@@ -21,7 +21,11 @@ Circles come in all shapes and sizes, but they're usually round.
|
|
21
21
|
|
22
22
|
# @return [Number] The {Circle}'s radius
|
23
23
|
attr_reader :radius
|
24
|
-
|
24
|
+
attr_writer :options
|
25
|
+
def options
|
26
|
+
@options = {} if !@options
|
27
|
+
@options
|
28
|
+
end
|
25
29
|
# @overload new(center, radius)
|
26
30
|
# Construct a {Circle} using a centerpoint and radius
|
27
31
|
# @param [Point] center The center point of the {Circle}
|
data/lib/geometry/edge.rb
CHANGED