ultra_polygons 0.0.0.pre1
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 +7 -0
- data/lib/ultra_polygons.rb +137 -0
- metadata +58 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 0bf44a384a9251ed3c4c1726b8d0359f778712aa
|
|
4
|
+
data.tar.gz: '02830c52c141efbc5831aae37f273e76baf98ddd'
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: '0100485711eff354351468cb3d8ba23e7ca84dd086143b51fd3510f472f6f77305c9d9df37795c90703e2618fb71f64fe3523a959ca4a082e59164411908e019'
|
|
7
|
+
data.tar.gz: efca40481f0b62aab49f989909f812929e5fbb4fe0f94297fdbdede8184c1809581c87c94748bc76a2fb040f8134993d6e75ff16344aecf84365a30296b54fe7
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
require ( 'locationclass' )
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
#Main module.
|
|
5
|
+
module UltraPolygons
|
|
6
|
+
#Base class for errors related to polygons.
|
|
7
|
+
class UltraPolygons::PolygonError < StandardError
|
|
8
|
+
|
|
9
|
+
end
|
|
10
|
+
#Raised when an array of locations passed to a polygon constructor cannot form the specified type of polygon.
|
|
11
|
+
class UltraPolygons::InvalidLocationArrayError < PolygonError
|
|
12
|
+
|
|
13
|
+
end
|
|
14
|
+
#Raised when a polygon is constructed with 2 or more locations in the same place.
|
|
15
|
+
class UltraPolygons::EquivalentLocationsError < PolygonError
|
|
16
|
+
|
|
17
|
+
end
|
|
18
|
+
#Raised when a Path is created with matching endpoints.
|
|
19
|
+
class UltraPolygons::ConnectingPathEndpointsError < PolygonError
|
|
20
|
+
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
#Basic polygon class.
|
|
24
|
+
class UltraPolygons::Polygon
|
|
25
|
+
attr_accessor ( :points )
|
|
26
|
+
|
|
27
|
+
def initialize(point_array=[])
|
|
28
|
+
pts_found = []
|
|
29
|
+
point_array.each() do |p|
|
|
30
|
+
if pts_found.include?(p)
|
|
31
|
+
raise EquivalentLocationsError.new("Multiple locations of the same place found in UltraPolygons::Polygon#initialize")
|
|
32
|
+
end
|
|
33
|
+
pts_found << p
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
@points = point_array
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
#Returns the number of points.
|
|
40
|
+
def num_points()
|
|
41
|
+
return @points.length()
|
|
42
|
+
end
|
|
43
|
+
#This returns false except on circles.
|
|
44
|
+
def infinite_points?()
|
|
45
|
+
return false
|
|
46
|
+
end
|
|
47
|
+
#Opposite of infinite_points?().
|
|
48
|
+
def finite_points?()
|
|
49
|
+
return (not (infinite_points?()))
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
alias number_of_points num_points
|
|
54
|
+
end
|
|
55
|
+
#Represents a straight line.
|
|
56
|
+
class UltraPolygons::StraightLine < Polygon
|
|
57
|
+
def initialize(start_loc, end_loc)
|
|
58
|
+
super([start_loc, end_loc])
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
#Represents a group of StraightLine objects that don't connect at the end.
|
|
62
|
+
class UltraPolygons::Path < Polygon
|
|
63
|
+
#Initializes the object with the given line array. The first line in the list will be the start of the path and
|
|
64
|
+
#the last line will be the end of the path. A ConnectingPathEndpointsError will be raised if the first and last
|
|
65
|
+
#points are the same. If you need them to connect, try using a UltraPolygons::Polygon instead.
|
|
66
|
+
def initialize(point_array)
|
|
67
|
+
#Confirm that it doesn't form a polygon.
|
|
68
|
+
raise ConnectingPathEndpointsError.new("Starting and ending points are equal") if (point_array[0] == point_array[-1])
|
|
69
|
+
super(point_array)
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
#Represents a rectangle.
|
|
74
|
+
class UltraPolygons::Rectangle < Polygon
|
|
75
|
+
#Makes a new rectangle with the specified boundaries. start_loc should be a Location
|
|
76
|
+
#object and length and width parameters should be floats.
|
|
77
|
+
def initialize(start_loc, length, width)
|
|
78
|
+
super([start_loc, Location.new(start_loc.x() + length, start_loc.y() + width)])
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
#Represents a square.
|
|
82
|
+
class UltraPolygons::Square < Rectangle
|
|
83
|
+
#Creates a new square with the specified boundaries. start_loc should be a Location object and
|
|
84
|
+
#side_length should be a float.
|
|
85
|
+
def initialize(start_loc, side_length)
|
|
86
|
+
super(start_loc, side_length, side_length)
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
#Represents a triangle. It can be equilateral, isosceles, or scalene.
|
|
90
|
+
class UltraPolygons::Triangle < Polygon
|
|
91
|
+
#location_array should be an array of location objects. If they don't form a triangle, an
|
|
92
|
+
#InvalidLocationArrayError will be raised.
|
|
93
|
+
def initialize(location_array)
|
|
94
|
+
raise InvalidLocationArrayError.new() unless valid_points?(location_array)0
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
def self.valid_points?(array)
|
|
98
|
+
return false if (array.length() != 3)
|
|
99
|
+
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
#Represents a circle object. Although it extends polygon, @points is not supported. Calls
|
|
103
|
+
#to get or set @points always fail with a NotImplementedError.
|
|
104
|
+
class UltraPolygons::Circle < Polygon
|
|
105
|
+
attr_accessor ( :center )
|
|
106
|
+
attr_accessor ( :radius )
|
|
107
|
+
|
|
108
|
+
#center_loc should be a location and rad should be a float or integer.
|
|
109
|
+
def initialize(center_loc, rad)
|
|
110
|
+
@center = center_loc
|
|
111
|
+
@radius = rad
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
#Always fails.
|
|
115
|
+
def points()
|
|
116
|
+
return 0
|
|
117
|
+
end
|
|
118
|
+
#Always fails.
|
|
119
|
+
def points=(value)
|
|
120
|
+
raise(NotImplementedError.new("Unimplemented method: UltraPolygons::Circle#points="))
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
#Returns true because a circle has infinite points.
|
|
124
|
+
def infinite_points?()
|
|
125
|
+
return true
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
#Returns the diameter.
|
|
129
|
+
def diameter()
|
|
130
|
+
return @radius * 2
|
|
131
|
+
end
|
|
132
|
+
#Sets the diameter.
|
|
133
|
+
def diameter=(value)
|
|
134
|
+
@radius = (value / 2)
|
|
135
|
+
end
|
|
136
|
+
end
|
|
137
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: ultra_polygons
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.0.pre1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- SugarRush
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2018-12-21 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: locationclass
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '1.1'
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '1.1'
|
|
27
|
+
description: Classes representing 2 dimensional polygons. Version 0.0.0 is still in
|
|
28
|
+
development.
|
|
29
|
+
email:
|
|
30
|
+
executables: []
|
|
31
|
+
extensions: []
|
|
32
|
+
extra_rdoc_files: []
|
|
33
|
+
files:
|
|
34
|
+
- lib/ultra_polygons.rb
|
|
35
|
+
homepage: http://rubygems.org/gems/ultra_polygons
|
|
36
|
+
licenses: []
|
|
37
|
+
metadata: {}
|
|
38
|
+
post_install_message:
|
|
39
|
+
rdoc_options: []
|
|
40
|
+
require_paths:
|
|
41
|
+
- lib
|
|
42
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
43
|
+
requirements:
|
|
44
|
+
- - ">="
|
|
45
|
+
- !ruby/object:Gem::Version
|
|
46
|
+
version: '0'
|
|
47
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
48
|
+
requirements:
|
|
49
|
+
- - ">"
|
|
50
|
+
- !ruby/object:Gem::Version
|
|
51
|
+
version: 1.3.1
|
|
52
|
+
requirements: []
|
|
53
|
+
rubyforge_project:
|
|
54
|
+
rubygems_version: 2.6.14.1
|
|
55
|
+
signing_key:
|
|
56
|
+
specification_version: 4
|
|
57
|
+
summary: Polygons classes
|
|
58
|
+
test_files: []
|