simple-polygons 0.0.0.pre6 → 0.0.0
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 +4 -4
- data/lib/simple-polygons.rb +29 -62
- metadata +6 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fc6fcadcf4ca827ba3c74a34d09e83931b4258a5
|
4
|
+
data.tar.gz: 857fd2f142fb860cb72da58971d4a818983549f0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9d765fd9acbddb5726aaa0c91410740c58dd27cc20a3176c25c53ac1c694e26baf387298f5df8bcc74e373de72800bea3ecf98061397f632f800d13068b97b82
|
7
|
+
data.tar.gz: 9a8b5c4fc4c127a7ddab47055d116b709dfdf2da1a27ee876e854399bd92e01934ca4c5e7a50f6946db702a897815ad10ab94419a5c155d9e79316c9a025ec45
|
data/lib/simple-polygons.rb
CHANGED
@@ -1,96 +1,63 @@
|
|
1
1
|
require ( 'locationclass' )
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
|
4
|
+
#Main module.
|
5
|
+
module SimplePolygons
|
6
|
+
class SimplePolygons::PolygonError < StandardError
|
6
7
|
|
7
|
-
self.each() do |v|
|
8
|
-
greatest = v if (greatest == nil) or (v > greatest)
|
9
|
-
end
|
10
|
-
|
11
|
-
return greatest
|
12
8
|
end
|
13
|
-
|
14
|
-
least = nil
|
15
|
-
|
16
|
-
self.each() do |v|
|
17
|
-
least = v if (least == nil) or (v < least)
|
18
|
-
end
|
19
|
-
|
20
|
-
return least
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
module SimplePolygons
|
25
|
-
class InvalidLocationArrayError < StandardError
|
9
|
+
class SimplePolygons::InvalidLocationArrayError < PolygonError
|
26
10
|
|
11
|
+
end
|
12
|
+
#Raised when a polygon is constructed with 2 or more locations in the same place.
|
13
|
+
class SimplePolygons::EquivalentLocationsError < PolygonError
|
14
|
+
|
27
15
|
end
|
28
16
|
|
29
|
-
class Polygon
|
17
|
+
class SimplePolygons::Polygon
|
30
18
|
attr_accessor ( :points )
|
31
19
|
|
32
20
|
#point_array should be an array of Location objects.
|
33
21
|
def initialize(point_array=[])
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
22
|
+
pts_found = []
|
23
|
+
point_array.each() do |p|
|
24
|
+
if pts_found.include?(p)
|
25
|
+
raise EquivalentLocationsError.new("Multiple locations of the same place found in SimplePolygons::Polygon#initialize")
|
26
|
+
end
|
27
|
+
pts_found << p
|
40
28
|
end
|
41
|
-
|
42
|
-
|
43
|
-
#Returns false if @points includes loc.
|
44
|
-
def not_include?(loc)
|
45
|
-
return !include?(loc)
|
29
|
+
|
30
|
+
@points = point_array
|
46
31
|
end
|
47
32
|
#Returns the number of points.
|
48
33
|
def number_of_points()
|
49
34
|
return @points.length()
|
50
35
|
end
|
51
36
|
end
|
52
|
-
class
|
37
|
+
class SimplePolygons::Line < Polygon
|
38
|
+
def initialize(start_loc, end_loc)
|
39
|
+
super([start_loc, end_loc])
|
40
|
+
end
|
41
|
+
end
|
42
|
+
class SimplePolygons::Rectangle < Polygon
|
53
43
|
#Makes a new rectangle with the specified boundaries. start_loc should be a Location
|
54
44
|
#object and length and width parameters should be floats.
|
55
45
|
def initialize(start_loc, length, width)
|
56
46
|
super([start_loc, Location.new(start_loc.x() + length, start_loc.y() + width)])
|
57
47
|
end
|
58
48
|
end
|
59
|
-
class Square < Rectangle
|
49
|
+
class SimplePolygons::Square < Rectangle
|
60
50
|
#Creates a new square with the specified boundaries. start_loc should be a Location object and
|
61
51
|
#side_length should be a float.
|
62
52
|
def initialize(start_loc, side_length)
|
63
53
|
super(start_loc, side_length, side_length)
|
64
54
|
end
|
65
55
|
end
|
66
|
-
#Represents a triangle. It can be any of the 3 kinds.
|
67
|
-
class Triangle < Polygon
|
56
|
+
#NOT YET IMPLEMENTED. Represents a triangle. It can be any of the 3 kinds.
|
57
|
+
class SimplePolygons::Triangle < Polygon
|
68
58
|
#All parameters should be Location objects.
|
69
59
|
def initialize(loc1, loc2, loc3)
|
70
|
-
|
71
|
-
raise InvalidLocationArrayError.new("Invalid points for triangle initialization.")
|
72
|
-
end
|
73
|
-
super([loc1, loc2, loc3])
|
74
|
-
end
|
75
|
-
#Returns true if a, b, and c can form a triangle. a, b, and c should be locations.
|
76
|
-
def self.valid_points?(a, b, c)
|
77
|
-
return (self.valid?(a.x(), b.x(), c.x()) and (self.valid?(a.y(), b.y(), c.y())))
|
78
|
-
end
|
79
|
-
|
80
|
-
private
|
81
|
-
def self.valid?(a, b, c)
|
82
|
-
place_list = [a,b,c].sort()
|
83
|
-
|
84
|
-
least = place_list[0]
|
85
|
-
middle = place_list[1]
|
86
|
-
greatest = place_list[2]
|
87
|
-
|
88
|
-
return false unless middle === (place_list.greatest_val()..place_list.least_val())
|
89
|
-
|
90
|
-
return true
|
60
|
+
raise NotImplementedError.new("SimplePolygons::Triangle is not yet implemented.")
|
91
61
|
end
|
92
62
|
end
|
93
|
-
end
|
94
|
-
|
95
|
-
include SimplePolygons
|
96
|
-
puts Triangle.valid_points?(Location.new(10, 10), Location.new(20, 20), Location.new(30, 30))
|
63
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple-polygons
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.0
|
4
|
+
version: 0.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- SugarRush
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-10-
|
11
|
+
date: 2018-10-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: locationclass
|
@@ -24,8 +24,7 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1'
|
27
|
-
description:
|
28
|
-
release will be out by \n October 20. This is the final pre-release."
|
27
|
+
description: Simple polygon classes.
|
29
28
|
email:
|
30
29
|
executables: []
|
31
30
|
extensions: []
|
@@ -33,8 +32,7 @@ extra_rdoc_files: []
|
|
33
32
|
files:
|
34
33
|
- lib/simple-polygons.rb
|
35
34
|
homepage: http://rubygems.org/gems/simple-polygons
|
36
|
-
licenses:
|
37
|
-
- None
|
35
|
+
licenses: []
|
38
36
|
metadata: {}
|
39
37
|
post_install_message:
|
40
38
|
rdoc_options: []
|
@@ -47,9 +45,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
47
45
|
version: '0'
|
48
46
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
49
47
|
requirements:
|
50
|
-
- - "
|
48
|
+
- - ">="
|
51
49
|
- !ruby/object:Gem::Version
|
52
|
-
version:
|
50
|
+
version: '0'
|
53
51
|
requirements: []
|
54
52
|
rubyforge_project:
|
55
53
|
rubygems_version: 2.6.14.1
|