simple-polygons 0.0.0 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/simple-polygons.rb +42 -3
  3. metadata +5 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fc6fcadcf4ca827ba3c74a34d09e83931b4258a5
4
- data.tar.gz: 857fd2f142fb860cb72da58971d4a818983549f0
3
+ metadata.gz: 8c91ad54da3d72c94acde5e8049c4c5340e5dcc0
4
+ data.tar.gz: '069fa48df969bbe97efb18685c58780b6bae0706'
5
5
  SHA512:
6
- metadata.gz: 9d765fd9acbddb5726aaa0c91410740c58dd27cc20a3176c25c53ac1c694e26baf387298f5df8bcc74e373de72800bea3ecf98061397f632f800d13068b97b82
7
- data.tar.gz: 9a8b5c4fc4c127a7ddab47055d116b709dfdf2da1a27ee876e854399bd92e01934ca4c5e7a50f6946db702a897815ad10ab94419a5c155d9e79316c9a025ec45
6
+ metadata.gz: 7f0db22b943024df85af746cca2cebcd1d028da8a692277396341c24252f95eb16e7534d108f4a85bcee67ae6554aa78104ffc3f0a8c53e13f7a7d9cb14956b2
7
+ data.tar.gz: '09479c6793079a7ea00e0f8f27b94ef73671faa940752642e30ce59360670729a09582ce3a0e57d1e31f254a8729d9387d40b6769665c0928c88f208b87c625f'
@@ -3,9 +3,11 @@ require ( 'locationclass' )
3
3
 
4
4
  #Main module.
5
5
  module SimplePolygons
6
+ #Base class for errors related to polygons.
6
7
  class SimplePolygons::PolygonError < StandardError
7
8
 
8
9
  end
10
+ #Raised when an array of locations passed to a polygon constructor cannot form the specified type of polygon.
9
11
  class SimplePolygons::InvalidLocationArrayError < PolygonError
10
12
 
11
13
  end
@@ -14,6 +16,7 @@ module SimplePolygons
14
16
 
15
17
  end
16
18
 
19
+ #Basic polygon class.
17
20
  class SimplePolygons::Polygon
18
21
  attr_accessor ( :points )
19
22
 
@@ -29,16 +32,19 @@ module SimplePolygons
29
32
 
30
33
  @points = point_array
31
34
  end
35
+
32
36
  #Returns the number of points.
33
37
  def number_of_points()
34
38
  return @points.length()
35
39
  end
36
40
  end
41
+ #Represents a line.
37
42
  class SimplePolygons::Line < Polygon
38
43
  def initialize(start_loc, end_loc)
39
44
  super([start_loc, end_loc])
40
45
  end
41
46
  end
47
+ #Represents a rectangle.
42
48
  class SimplePolygons::Rectangle < Polygon
43
49
  #Makes a new rectangle with the specified boundaries. start_loc should be a Location
44
50
  #object and length and width parameters should be floats.
@@ -46,6 +52,7 @@ module SimplePolygons
46
52
  super([start_loc, Location.new(start_loc.x() + length, start_loc.y() + width)])
47
53
  end
48
54
  end
55
+ #Represents a square.
49
56
  class SimplePolygons::Square < Rectangle
50
57
  #Creates a new square with the specified boundaries. start_loc should be a Location object and
51
58
  #side_length should be a float.
@@ -55,9 +62,41 @@ module SimplePolygons
55
62
  end
56
63
  #NOT YET IMPLEMENTED. Represents a triangle. It can be any of the 3 kinds.
57
64
  class SimplePolygons::Triangle < Polygon
58
- #All parameters should be Location objects.
59
- def initialize(loc1, loc2, loc3)
60
- raise NotImplementedError.new("SimplePolygons::Triangle is not yet implemented.")
65
+ #location_array should be an array of location objects. If they don't form a triangle, an
66
+ #InvalidLocationArrayError will be raised.
67
+ def initialize(location_array)
68
+ raise InvalidLocationArrayError.new() unless valid_points?(location_array)
69
+ end
70
+
71
+ def self.valid_points?(array)
72
+ return true
73
+ end
74
+ end
75
+ #Represents a circle object. Although it extends polygon, @points is never used and cannot be modified.
76
+ class SimplePolygons::Circle
77
+ attr_accessor ( :center )
78
+ attr_accessor ( :radius )
79
+
80
+ #center_loc should be a location and rad should be a float or integer.
81
+ def initialize(center_loc, rad)
82
+ @center = center_loc
83
+ @radius = rad
84
+ end
85
+
86
+ #Always returns 0.
87
+ def points()
88
+ return 0
89
+ end
90
+ #This does not do anything.
91
+ def points=(value)
92
+
93
+ end
94
+
95
+ def diameter()
96
+ return @radius * 2
97
+ end
98
+ def diameter=(value)
99
+ @radius = (value / 2)
61
100
  end
62
101
  end
63
102
  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.1.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-19 00:00:00.000000000 Z
11
+ date: 2018-10-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: locationclass
@@ -16,15 +16,15 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1'
19
+ version: '1.1'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1'
27
- description: Simple polygon classes.
26
+ version: '1.1'
27
+ description: Simple polygon classes. Development is being moved to ultra_polygons.
28
28
  email:
29
29
  executables: []
30
30
  extensions: []