perfect-shape 0.0.10 → 0.0.11

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 373846069228dba8331891ba808511bfdb306bb8e3e29fad2cf053ab6c69fbaf
4
- data.tar.gz: ccbc6e998e1f9809ebebd126ed6c613076fc8ad92cea012c08796e8e129ead28
3
+ metadata.gz: '097e027a1c0c026611e480d05bf6281c74db9228964f6f06c414637bb60af8b0'
4
+ data.tar.gz: e2bab91460ec298a74e4735a13a123bf7b5f0ae9d15f8b5544a77aa7733cd312
5
5
  SHA512:
6
- metadata.gz: 66d9b3a6420a142bc35eaf1dbf80536f743b713eec9dc509764d8bc4dc87d528e214703e24c256977f38263df55cac715db8c6f1366c3d7a05d97fd0d892722c
7
- data.tar.gz: 41c7ea46f7f9607e889f9ec04187a286333e593af6012099b74b19593806ae14e1b9d01e406bc1a4efa2e21035a096b0ca10ba53d9f74ab51721fd50a5ed44c5
6
+ metadata.gz: a532c231809348346907d2f369df7380cbac384772c3fc6d9858bfa423f5da6f0fd15e9eda3f94404f5579ed3572cab87d3c8d99b19c50d776ae6e999a7ff5a1
7
+ data.tar.gz: 4d7b76430666115f21053b7417c290f6260fb99f278eb8397d53ddf1c5c4a84b48b1c87d49c977bdfc54cd513c801be49ca1e586d9c0d7501e4d2a5eb648f8e4
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Change Log
2
2
 
3
+ ## 0.0.11
4
+
5
+ - `PerfectShape::Polygon#==`
6
+ - `PerfectShape::Line#==`
7
+ - `PerfectShape::Point#==`
8
+
3
9
  ## 0.0.10
4
10
 
5
11
  - `PerfectShape::Point`
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Perfect Shape 0.0.10
1
+ # Perfect Shape 0.0.11
2
2
  ## Geometric Algorithms
3
3
  [![Gem Version](https://badge.fury.io/rb/perfect-shape.svg)](http://badge.fury.io/rb/perfect-shape)
4
4
 
@@ -13,13 +13,13 @@ To ensure high accuracy, this library does all its mathematical operations with
13
13
  Run:
14
14
 
15
15
  ```
16
- gem install perfect-shape -v 0.0.10
16
+ gem install perfect-shape -v 0.0.11
17
17
  ```
18
18
 
19
19
  Or include in Bundler `Gemfile`:
20
20
 
21
21
  ```ruby
22
- gem 'perfect-shape', '~> 0.0.10'
22
+ gem 'perfect-shape', '~> 0.0.11'
23
23
  ```
24
24
 
25
25
  And, run:
@@ -43,6 +43,8 @@ Module
43
43
 
44
44
  Class
45
45
 
46
+ This is a base class for all shapes. It is not meant to be used directly. Subclasses implement/override its methods as needed.
47
+
46
48
  - `#min_x`: min x
47
49
  - `#min_y`: min y
48
50
  - `#max_x`: max x
@@ -53,6 +55,7 @@ Class
53
55
  - `#center_y`: center y
54
56
  - `#bounding_box`: bounding box is a rectangle with x = min x, y = min y, and width/height just as those of shape
55
57
  - `#normalize_point(x_or_point, y = nil)`: normalizes point into an `Array` of (x,y) coordinates
58
+ - `#==(other)`: Returns `true` if equal to `other` or `false` otherwise
56
59
 
57
60
  ### `PerfectShape::PointLocation`
58
61
 
@@ -68,6 +71,8 @@ Module
68
71
 
69
72
  Module
70
73
 
74
+ Includes `PerfectShape::PointLocation`
75
+
71
76
  - `#initialize(x: 0, y: 0, width: 1, height: 1)`: initializes a rectangular shape
72
77
  - `#x`: top-left x
73
78
  - `#y`: top-left y
@@ -87,12 +92,14 @@ Class
87
92
 
88
93
  Extends `PerfectShape::Shape`
89
94
 
90
- ![point](images/point.png)
95
+ Includes `PerfectShape::PointLocation`
96
+
97
+ ![point](https://raw.githubusercontent.com/AndyObtiva/perfect-shape/master/images/point.png)
91
98
 
92
99
  Points are simply represented by an `Array` of (x,y) coordinates when used within other shapes, but when needing point-specific operations like `point_distance`, the `PerfectShape::Point` class can come in handy.
93
100
 
94
101
  - `::point_distance(x, y, px, py)`: Returns the distance from a point to another point
95
- - `::new(x_or_point=0, y=0, x: nil, y: nil)`: constructs a point with (x,y) pair whether specified as `Array` of (x,y) pair, flat `x,y` args, or `x:, y:` kwargs.
102
+ - `::new(x_or_point=nil, y_arg=nil, x: nil, y: nil)`: constructs a point with (x,y) pair (default: 0,0) whether specified as `Array` of (x,y) pair, flat `x,y` args, or `x:, y:` kwargs.
96
103
  - `#min_x`: min x (always x)
97
104
  - `#min_y`: min y (always y)
98
105
  - `#max_x`: max x (always x)
@@ -104,6 +111,7 @@ Points are simply represented by an `Array` of (x,y) coordinates when used withi
104
111
  - `#bounding_box`: bounding box is a rectangle with x = min x, y = min y, and width/height of shape
105
112
  - `#contain?(x_or_point, y=nil, distance: 0)`: checks if point matches self, with a distance tolerance (0 by default). Distance tolerance provides a fuzz factor that for example enables GUI users to mouse-click-select a point shape in a GUI more successfully.
106
113
  - `#point_distance(x_or_point, y=nil)`: Returns the distance from a point to another point
114
+ - `#==(other)`: Returns `true` if equal to `other` or `false` otherwise
107
115
 
108
116
  ### `PerfectShape::Line`
109
117
 
@@ -111,7 +119,7 @@ Class
111
119
 
112
120
  Extends `PerfectShape::Shape`
113
121
 
114
- ![line](images/line.png)
122
+ ![line](https://raw.githubusercontent.com/AndyObtiva/perfect-shape/master/images/line.png)
115
123
 
116
124
  - `::relative_counterclockwise(x1, y1, x2, y2, px, py)`: Returns an indicator of where the specified point (px,py) lies with respect to the line segment from (x1,y1) to (x2,y2). The return value can be either 1, -1, or 0 and indicates in which direction the specified line must pivot around its first end point, (x1,y1), in order to point at the specified point (px,py). A return value of 1 indicates that the line segment must turn in the direction that takes the positive X axis towards the negative Y axis. In the default coordinate system used by Java 2D, this direction is counterclockwise. A return value of -1 indicates that the line segment must turn in the direction that takes the positive X axis towards the positive Y axis. In the default coordinate system, this direction is clockwise. A return value of 0 indicates that the point lies exactly on the line segment. Note that an indicator value of 0 is rare and not useful for determining collinearity because of floating point rounding issues. If the point is colinear with the line segment, but not between the end points, then the value will be -1 if the point lies “beyond (x1,y1)” or 1 if the point lies “beyond (x2,y2)”.
117
125
  - `::point_segment_distance_square(x1, y1, x2, y2, px, py)`: Returns the square of distance from a point to a line segment.
@@ -129,6 +137,7 @@ Extends `PerfectShape::Shape`
129
137
  - `#contain?(x_or_point, y=nil, distance: 0)`: checks if point lies on line, with a distance tolerance (0 by default). Distance tolerance provides a fuzz factor that for example enables GUI users to mouse-click-select a line shape in a GUI more successfully.
130
138
  - `#relative_counterclockwise(x_or_point, y=nil)`: Returns an indicator of where the specified point (px,py) lies with respect to the line segment from (x1,y1) to (x2,y2). The return value can be either 1, -1, or 0 and indicates in which direction the specified line must pivot around its first end point, (x1,y1), in order to point at the specified point (px,py). A return value of 1 indicates that the line segment must turn in the direction that takes the positive X axis towards the negative Y axis. In the default coordinate system used by Java 2D, this direction is counterclockwise. A return value of -1 indicates that the line segment must turn in the direction that takes the positive X axis towards the positive Y axis. In the default coordinate system, this direction is clockwise. A return value of 0 indicates that the point lies exactly on the line segment. Note that an indicator value of 0 is rare and not useful for determining collinearity because of floating point rounding issues. If the point is colinear with the line segment, but not between the end points, then the value will be -1 if the point lies “beyond (x1,y1)” or 1 if the point lies “beyond (x2,y2)”.
131
139
  - `#point_segment_distance(x_or_point, y=nil)`: Returns the distance from a point to a line segment.
140
+ - `#==(other)`: Returns `true` if equal to `other` or `false` otherwise
132
141
 
133
142
  ### `PerfectShape::Rectangle`
134
143
 
@@ -138,7 +147,7 @@ Extends `PerfectShape::Shape`
138
147
 
139
148
  Includes `PerfectShape::RectangularShape`
140
149
 
141
- ![rectangle](images/rectangle.png)
150
+ ![rectangle](https://raw.githubusercontent.com/AndyObtiva/perfect-shape/master/images/rectangle.png)
142
151
 
143
152
  - `::new(x: 0, y: 0, width: 1, height: 1)`: constructs a rectangle
144
153
  - `#x`: top-left x
@@ -153,6 +162,7 @@ Includes `PerfectShape::RectangularShape`
153
162
  - `#max_y`: max y
154
163
  - `#bounding_box`: bounding box is a rectangle with x = min x, y = min y, and width/height of shape
155
164
  - `#contain?(x_or_point, y=nil)`: checks if point is inside
165
+ - `#==(other)`: Returns `true` if equal to `other` or `false` otherwise
156
166
 
157
167
  ### `PerfectShape::Square`
158
168
 
@@ -160,7 +170,7 @@ Class
160
170
 
161
171
  Extends `PerfectShape::Rectangle`
162
172
 
163
- ![square](images/square.png)
173
+ ![square](https://raw.githubusercontent.com/AndyObtiva/perfect-shape/master/images/square.png)
164
174
 
165
175
  - `::new(x: 0, y: 0, length: 1)`: constructs a square
166
176
  - `#x`: top-left x
@@ -176,6 +186,7 @@ Extends `PerfectShape::Rectangle`
176
186
  - `#max_y`: max y
177
187
  - `#bounding_box`: bounding box is a rectangle with x = min x, y = min y, and width/height of shape
178
188
  - `#contain?(x_or_point, y=nil)`: checks if point is inside
189
+ - `#==(other)`: Returns `true` if equal to `other` or `false` otherwise
179
190
 
180
191
  ### `PerfectShape::Arc`
181
192
 
@@ -189,7 +200,7 @@ Arcs can be of type `:open`, `:chord`, or `:pie`
189
200
 
190
201
  Open Arc | Chord Arc | Pie Arc
191
202
  ---------|-----------|--------
192
- ![arc-open](images/arc-open.png) | ![arc-chord](images/arc-chord.png) | ![arc-pie](images/arc-pie.png)
203
+ ![arc-open](https://raw.githubusercontent.com/AndyObtiva/perfect-shape/master/images/arc-open.png) | ![arc-chord](https://raw.githubusercontent.com/AndyObtiva/perfect-shape/master/images/arc-chord.png) | ![arc-pie](https://raw.githubusercontent.com/AndyObtiva/perfect-shape/master/images/arc-pie.png)
193
204
 
194
205
  - `::new(type: :open, x: 0, y: 0, width: 1, height: 1, start: 0, extent: 360, center_x: nil, center_y: nil, radius_x: nil, radius_y: nil)`: constructs an arc of type `:open` (default), `:chord`, or `:pie`
195
206
  - `#type`: `:open`, `:chord`, or `:pie`
@@ -209,6 +220,7 @@ Open Arc | Chord Arc | Pie Arc
209
220
  - `#max_y`: max y
210
221
  - `#bounding_box`: bounding box is a rectangle with x = min x, y = min y, and width/height of shape
211
222
  - `#contain?(x_or_point, y=nil)`: checks if point is inside
223
+ - `#==(other)`: Returns `true` if equal to `other` or `false` otherwise
212
224
 
213
225
  ### `PerfectShape::Ellipse`
214
226
 
@@ -216,7 +228,7 @@ Class
216
228
 
217
229
  Extends `PerfectShape::Arc`
218
230
 
219
- ![ellipse](images/ellipse.png)
231
+ ![ellipse](https://raw.githubusercontent.com/AndyObtiva/perfect-shape/master/images/ellipse.png)
220
232
 
221
233
  - `::new(x: 0, y: 0, width: 1, height: 1, center_x: nil, center_y: nil, radius_x: nil, radius_y: nil)`: constructs an ellipse
222
234
  - `#x`: top-left x
@@ -236,6 +248,7 @@ Extends `PerfectShape::Arc`
236
248
  - `#max_y`: max y
237
249
  - `#bounding_box`: bounding box is a rectangle with x = min x, y = min y, and width/height of shape
238
250
  - `#contain?(x_or_point, y=nil)`: checks if point is inside
251
+ - `#==(other)`: Returns `true` if equal to `other` or `false` otherwise
239
252
 
240
253
  ### `PerfectShape::Circle`
241
254
 
@@ -243,7 +256,7 @@ Class
243
256
 
244
257
  Extends `PerfectShape::Ellipse`
245
258
 
246
- ![circle](images/circle.png)
259
+ ![circle](https://raw.githubusercontent.com/AndyObtiva/perfect-shape/master/images/circle.png)
247
260
 
248
261
  - `::new(x: 0, y: 0, diameter: 1, width: 1, height: 1, center_x: nil, center_y: nil, radius: nil, radius_x: nil, radius_y: nil)`: constructs a circle
249
262
  - `#x`: top-left x
@@ -265,6 +278,7 @@ Extends `PerfectShape::Ellipse`
265
278
  - `#max_y`: max y
266
279
  - `#bounding_box`: bounding box is a rectangle with x = min x, y = min y, and width/height of shape
267
280
  - `#contain?(x_or_point, y=nil)`: checks if point is inside
281
+ - `#==(other)`: Returns `true` if equal to `other` or `false` otherwise
268
282
 
269
283
  ### `PerfectShape::Polygon`
270
284
 
@@ -272,7 +286,7 @@ Class
272
286
 
273
287
  Extends `PerfectShape::Shape`
274
288
 
275
- ![polygon](images/polygon.png)
289
+ ![polygon](https://raw.githubusercontent.com/AndyObtiva/perfect-shape/master/images/polygon.png)
276
290
 
277
291
  - `::new(points: nil)`: constructs a polygon with `points` as `Array` of `Array`s of (x,y) pairs or flattened `Array` of alternating x and y values
278
292
  - `#min_x`: min x
@@ -285,6 +299,7 @@ Extends `PerfectShape::Shape`
285
299
  - `#center_y`: center y
286
300
  - `#bounding_box`: bounding box is a rectangle with x = min x, y = min y, and width/height of shape
287
301
  - `#contain?(x_or_point, y=nil)`: checks if point is inside using the [Ray Casting Algorithm](https://en.wikipedia.org/wiki/Point_in_polygon) (aka [Even-Odd Rule](https://en.wikipedia.org/wiki/Even%E2%80%93odd_rule))
302
+ - `#==(other)`: Returns `true` if equal to `other` or `false` otherwise
288
303
 
289
304
  ## Process
290
305
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.10
1
+ 0.0.11
@@ -185,6 +185,7 @@ module PerfectShape
185
185
  end
186
186
 
187
187
  include MultiPoint
188
+ include Equalizer.new(:points)
188
189
 
189
190
  # Checks if line contains point (two-number Array or x, y args), with distance tolerance (0 by default)
190
191
  #
@@ -35,6 +35,7 @@ module PerfectShape
35
35
  end
36
36
 
37
37
  include PointLocation
38
+ include Equalizer.new(:x, :y)
38
39
 
39
40
  def initialize(x_or_point = nil, y_arg = nil, x: nil, y: nil)
40
41
  if x_or_point.is_a?(Array)
@@ -26,6 +26,7 @@ module PerfectShape
26
26
  # Mostly ported from java.awt.geom: https://docs.oracle.com/javase/8/docs/api/java/awt/Polygon.html
27
27
  class Polygon < Shape
28
28
  include MultiPoint
29
+ include Equalizer.new(:points)
29
30
 
30
31
  # Checks if polygon contains point (two-number Array or x, y args)
31
32
  # using the Ray Casting Algorithm (aka Even-Odd Rule): https://en.wikipedia.org/wiki/Point_in_polygon
@@ -20,7 +20,8 @@
20
20
  # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
21
 
22
22
  module PerfectShape
23
- # Superclass of all shapes
23
+ # Superclass of all shapes. Not meant to be used directly.
24
+ # Subclasses must implement/override methods as needed.
24
25
  class Shape
25
26
  # Subclasses must implement
26
27
  def min_x
@@ -82,5 +83,9 @@ module PerfectShape
82
83
  y = BigDecimal(y.to_s)
83
84
  [x, y]
84
85
  end
86
+
87
+ # Subclasses must implement
88
+ def ==(other)
89
+ end
85
90
  end
86
91
  end
@@ -2,11 +2,11 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Juwelier::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: perfect-shape 0.0.10 ruby lib
5
+ # stub: perfect-shape 0.0.11 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "perfect-shape".freeze
9
- s.version = "0.0.10"
9
+ s.version = "0.0.11"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib".freeze]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: perfect-shape
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.10
4
+ version: 0.0.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Maleh