simple-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.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/main.rb +61 -0
  3. metadata +59 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9174abcc106d336daf94ba4ecf6948478a829927
4
+ data.tar.gz: 8460fe9d1f3513f5fe7db9dc8ffd0b50db69562a
5
+ SHA512:
6
+ metadata.gz: a0bf5516d53ac611d15c67dc35560d197e899ac48d2400440a740b4407dcf3428bc92cf07e3dd9b8b308f772ce8e7c510f45156beffc87174ada34f94520b039
7
+ data.tar.gz: 17426e4de06ec2f9fb2a078fc447071afa558b5321ef0c7fbceac5969f8e29059ddce9bb7b62d898ea6bde86ca8672c9c0dbd7768caf539abb10e1f4c1df2edc
data/lib/main.rb ADDED
@@ -0,0 +1,61 @@
1
+ module SimplePolygons
2
+ class InvalidLocationArrayError < StandardError
3
+
4
+ end
5
+
6
+ class Location
7
+ attr_accessor ( :x )
8
+ attr_accessor ( :y )
9
+
10
+ def initialize(x, y)
11
+ @x = x
12
+ @y = y
13
+ end
14
+
15
+ def move(x, y)
16
+ @x += x
17
+ @y += y
18
+ end
19
+ end
20
+
21
+ class Polygon
22
+ attr_accessor ( :points )
23
+
24
+ #point_array should be an array of Location objects.
25
+ def initialize(point_array=[])
26
+ @points = point_array
27
+ end
28
+ #Returns the number of points.
29
+ def number_of_points()
30
+ return @points.length()
31
+ end
32
+ end
33
+ class Rectangle < Polygon
34
+ #Makes a new rectangle with the specified boundaries. start_loc should be a Location
35
+ #object and length and width parameters should be floats.
36
+ def initialize(start_loc, length, width)
37
+ super([start_loc, Location.new(start_loc.x() + length, start_loc.y() + width)])
38
+ end
39
+ end
40
+ class Square < Rectangle
41
+ #Creates a new square with the specified boundaries. start_loc should be a Location object and
42
+ #side_length should be a float.
43
+ def initialize(start_loc, side_length)
44
+ super(start_loc, side_length, side_length)
45
+ end
46
+ end
47
+ #STILL IN PROGRESS.
48
+ class Triangle < Polygon
49
+ #All parameters should be Location objects.
50
+ def initialize(loc1, loc2, loc3)
51
+ if not Triangle.valid_points?(loc1, loc2, loc3)
52
+ raise InvalidLocationArrayError.new("Invalid points for triangle initialization.")
53
+ end
54
+ super([loc1, loc2, loc3])
55
+ end
56
+ #STILL IN PROGRESS.
57
+ def self.valid_points?(loc1, loc2, loc3)
58
+ return true
59
+ end
60
+ end
61
+ end
metadata ADDED
@@ -0,0 +1,59 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: simple-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-10-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: simplelocation
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: "A gem that has several classes representing 2D polygons. The first full
28
+ release will be out by \n October 20."
29
+ email:
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - lib/main.rb
35
+ homepage: http://rubygems.org/gems/simple-polygons
36
+ licenses:
37
+ - None
38
+ metadata: {}
39
+ post_install_message:
40
+ rdoc_options: []
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ required_rubygems_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">"
51
+ - !ruby/object:Gem::Version
52
+ version: 1.3.1
53
+ requirements: []
54
+ rubyforge_project:
55
+ rubygems_version: 2.6.14.1
56
+ signing_key:
57
+ specification_version: 4
58
+ summary: Polygons classes
59
+ test_files: []