perfect-shape 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -1
- data/README.md +64 -12
- data/VERSION +1 -1
- data/lib/perfect_shape/circle.rb +91 -0
- data/lib/perfect_shape/shape.rb +1 -0
- data/perfect-shape.gemspec +4 -3
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 81aba6992bb9cb98b1ce01764cb4cd0ca8e88690c56066e8282b4c0876421925
|
4
|
+
data.tar.gz: c63f14e43dfa8adff2bd525a77ca25ded5d1381953abb4a728770b22dab43323
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6ff01e388f4fadc337792f45ddfc598fecaeb3816fe13d04f5db4a13ecc78c7e978e2ef9683e33e32711bda62373c77dd1f5f4c07d69cfc23e4867bfbba9ccca
|
7
|
+
data.tar.gz: b32a4c65a4101ffa61cdab257fa1af05d59e7ee1f8e12ac8598dbad92a32dd33299bda92add7781e3f9028278051ebda36d9164cde116d79fc70f6d8b297f8ed
|
data/CHANGELOG.md
CHANGED
@@ -1,9 +1,14 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
+
## 0.0.6
|
4
|
+
|
5
|
+
- `PerfectShape::Circle`
|
6
|
+
- `PerfectShape::Circle#contain?(x_or_point, y=nil)`
|
7
|
+
|
3
8
|
## 0.0.5
|
4
9
|
|
5
10
|
- `PerfectShape::Ellipse`
|
6
|
-
- `PerfectShape::Ellipse#contain
|
11
|
+
- `PerfectShape::Ellipse#contain?(x_or_point, y=nil)`
|
7
12
|
|
8
13
|
## 0.0.4
|
9
14
|
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Perfect Shape 0.0.
|
1
|
+
# Perfect Shape 0.0.6
|
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.
|
16
|
+
gem install perfect-shape -v 0.0.6
|
17
17
|
```
|
18
18
|
|
19
19
|
Or include in Bundler `Gemfile`:
|
20
20
|
|
21
21
|
```ruby
|
22
|
-
gem 'perfect-shape', '~> 0.0.
|
22
|
+
gem 'perfect-shape', '~> 0.0.6'
|
23
23
|
```
|
24
24
|
|
25
25
|
And, run:
|
@@ -32,17 +32,42 @@ bundle
|
|
32
32
|
|
33
33
|
### `PerfectShape::Math`
|
34
34
|
|
35
|
+
Module
|
36
|
+
|
35
37
|
- `::degrees_to_radians(angle)`: converts degrees to radians
|
36
38
|
- `::radians_to_degrees(angle)`: converts radians to degrees
|
37
39
|
- `::normalize_degrees(angle)`: normalizes the specified angle into the range -180 to 180.
|
38
40
|
- `::ieee_remainder(x, y)` (alias: `ieee754_remainder`): [IEEE 754-1985 Remainder](https://en.wikipedia.org/wiki/IEEE_754-1985) (different from standard % modulo operator as it operates on floats and could return a negative result)
|
39
41
|
|
42
|
+
### `PerfectShape::Shape`
|
43
|
+
|
44
|
+
Class
|
45
|
+
|
46
|
+
- `#normalize_point(x_or_point, y = nil)`: normalizes point into an `Array` of (x,y) coordinates
|
47
|
+
|
48
|
+
### `PerfectShape::RectangularShape`
|
49
|
+
|
50
|
+
Module
|
51
|
+
|
52
|
+
- `#initialize(x: 0, y: 0, width: 1, height: 1)`: initializes a rectangular shape
|
53
|
+
- `#x`: top-left x
|
54
|
+
- `#y`: top-left y
|
55
|
+
- `#width`: width
|
56
|
+
- `#height`: height
|
57
|
+
- `#center_x`: center x
|
58
|
+
- `#center_y`: center y
|
59
|
+
|
40
60
|
### `PerfectShape::Line`
|
41
61
|
|
62
|
+
Class
|
63
|
+
Extends `PerfectShape::Shape`
|
64
|
+
|
42
65
|
- `::relative_ccw(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)”.
|
43
66
|
|
44
67
|
### `PerfectShape::Rectangle`
|
45
68
|
|
69
|
+
Class
|
70
|
+
Extends `PerfectShape::Shape`
|
46
71
|
Includes `PerfectShape::RectangularShape`
|
47
72
|
|
48
73
|
![rectangle](images/rectangle.png)
|
@@ -58,6 +83,7 @@ Includes `PerfectShape::RectangularShape`
|
|
58
83
|
|
59
84
|
### `PerfectShape::Square`
|
60
85
|
|
86
|
+
Class
|
61
87
|
Extends `PerfectShape::Rectangle`
|
62
88
|
|
63
89
|
![square](images/square.png)
|
@@ -74,6 +100,8 @@ Extends `PerfectShape::Rectangle`
|
|
74
100
|
|
75
101
|
### `PerfectShape::Arc`
|
76
102
|
|
103
|
+
Class
|
104
|
+
Extends `PerfectShape::Shape`
|
77
105
|
Includes `PerfectShape::RectangularShape`
|
78
106
|
|
79
107
|
Arcs can be of type `:open`, `:chord`, or `:pie`
|
@@ -84,10 +112,10 @@ Open Arc | Chord Arc | Pie Arc
|
|
84
112
|
|
85
113
|
- `::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`
|
86
114
|
- `#type`: `:open`, `:chord`, or `:pie`
|
87
|
-
- `#x`: top-left x
|
88
|
-
- `#y`: top-left y
|
89
|
-
- `#width`: width
|
90
|
-
- `#height`: height
|
115
|
+
- `#x`: top-left x
|
116
|
+
- `#y`: top-left y
|
117
|
+
- `#width`: width
|
118
|
+
- `#height`: height
|
91
119
|
- `#start`: start angle in degrees
|
92
120
|
- `#extent`: extent angle in degrees
|
93
121
|
- `#center_x`: center x
|
@@ -98,15 +126,16 @@ Open Arc | Chord Arc | Pie Arc
|
|
98
126
|
|
99
127
|
### `PerfectShape::Ellipse`
|
100
128
|
|
129
|
+
Class
|
101
130
|
Extends `PerfectShape::Arc`
|
102
131
|
|
103
132
|
![ellipse](images/ellipse.png)
|
104
133
|
|
105
134
|
- `::new(x: 0, y: 0, width: 1, height: 1, center_x: nil, center_y: nil, radius_x: nil, radius_y: nil)`: constructs an ellipse
|
106
|
-
- `#x`: top-left x
|
107
|
-
- `#y`: top-left y
|
108
|
-
- `#width`: width
|
109
|
-
- `#height`: height
|
135
|
+
- `#x`: top-left x
|
136
|
+
- `#y`: top-left y
|
137
|
+
- `#width`: width
|
138
|
+
- `#height`: height
|
110
139
|
- `#center_x`: center x
|
111
140
|
- `#center_y`: center y
|
112
141
|
- `#radius_x`: radius along the x-axis
|
@@ -116,6 +145,29 @@ Extends `PerfectShape::Arc`
|
|
116
145
|
- `#extent`: always `360`
|
117
146
|
- `#contain?(x_or_point, y=nil)`: checks if point is inside
|
118
147
|
|
148
|
+
### `PerfectShape::Circle`
|
149
|
+
|
150
|
+
Class
|
151
|
+
Extends `PerfectShape::Ellipse`
|
152
|
+
|
153
|
+
![circle](images/circle.png)
|
154
|
+
|
155
|
+
- `::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
|
156
|
+
- `#x`: top-left x
|
157
|
+
- `#y`: top-left y
|
158
|
+
- `#diameter`: diameter
|
159
|
+
- `#width`: width (equal to diameter)
|
160
|
+
- `#height`: height (equal to diameter)
|
161
|
+
- `#center_x`: center x
|
162
|
+
- `#center_y`: center y
|
163
|
+
- `#radius`: radius
|
164
|
+
- `#radius_x`: radius along the x-axis (equal to radius)
|
165
|
+
- `#radius_y`: radius along the y-axis (equal to radius)
|
166
|
+
- `#type`: always `:open`
|
167
|
+
- `#start`: always `0`
|
168
|
+
- `#extent`: always `360`
|
169
|
+
- `#contain?(x_or_point, y=nil)`: checks if point is inside
|
170
|
+
|
119
171
|
## Process
|
120
172
|
|
121
173
|
[Glimmer Process](https://github.com/AndyObtiva/glimmer/blob/master/PROCESS.md)
|
@@ -133,7 +185,7 @@ Extends `PerfectShape::Arc`
|
|
133
185
|
|
134
186
|
[CHANGELOG.md](CHANGELOG.md)
|
135
187
|
|
136
|
-
## Contributing
|
188
|
+
## Contributing
|
137
189
|
|
138
190
|
- Check out the latest master to make sure the feature hasn't been
|
139
191
|
implemented or the bug hasn't been fixed yet.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.6
|
@@ -0,0 +1,91 @@
|
|
1
|
+
# Copyright (c) 2021 Andy Maleh
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
# a copy of this software and associated documentation files (the
|
5
|
+
# "Software"), to deal in the Software without restriction, including
|
6
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
# the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be
|
12
|
+
# included in all copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
22
|
+
require 'perfect_shape/ellipse'
|
23
|
+
|
24
|
+
module PerfectShape
|
25
|
+
class Circle < Ellipse
|
26
|
+
MESSAGE_WIDTH_AND_HEIGHT_AND_DIAMETER_NOT_EQUAL = 'Circle width, height, and diameter must all be equal if more than one is specified; or otherwise keep only one of them in arguments!'
|
27
|
+
MESSAGE_RADIUS_X_AND_RADIUS_Y_AND_RADIUS_NOT_EQUAL = 'Circle radius_x, radius_y, and radius must all be equal if more than one is specified; or otherwise keep only one of them in arguments!'
|
28
|
+
|
29
|
+
def initialize(x: 0, y: 0, width: nil, height: nil, diameter: nil, center_x: nil, center_y: nil, radius_x: nil, radius_y: nil, radius: nil)
|
30
|
+
raise MESSAGE_WIDTH_AND_HEIGHT_AND_DIAMETER_NOT_EQUAL if (diameter && width && diameter != width) || (diameter && height && diameter != height) || (width && height && width != height)
|
31
|
+
raise MESSAGE_RADIUS_X_AND_RADIUS_Y_AND_RADIUS_NOT_EQUAL if (radius && radius_x && radius != radius_x) || (radius && radius_y && radius != radius_y) || (radius_x && radius_y && radius_x != radius_y)
|
32
|
+
if center_x && center_y && (radius || radius_x || radius_y)
|
33
|
+
radius ||= radius_x || radius_y
|
34
|
+
self.radius = radius
|
35
|
+
super(center_x: center_x, center_y: center_y, radius_x: self.radius_x, radius_y: self.radius_y)
|
36
|
+
else
|
37
|
+
diameter ||= width || height || 1
|
38
|
+
self.diameter = diameter
|
39
|
+
super(x: x, y: y, width: self.width, height: self.height)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def diameter
|
44
|
+
@radius ? @radius * BigDecimal('2.0') : @diameter
|
45
|
+
end
|
46
|
+
|
47
|
+
def radius
|
48
|
+
@diameter ? @diameter / BigDecimal('2.0') : @radius
|
49
|
+
end
|
50
|
+
|
51
|
+
# Sets length, normalizing to BigDecimal
|
52
|
+
def diameter=(value)
|
53
|
+
@diameter = BigDecimal(value.to_s)
|
54
|
+
@radius = nil
|
55
|
+
self.width = value unless width == value
|
56
|
+
self.height = value unless height == value
|
57
|
+
end
|
58
|
+
|
59
|
+
# Sets radius, normalizing to BigDecimal
|
60
|
+
def radius=(value)
|
61
|
+
@radius = BigDecimal(value.to_s)
|
62
|
+
@diameter = nil
|
63
|
+
self.radius_x = value unless width == value
|
64
|
+
self.radius_y = value unless height == value
|
65
|
+
end
|
66
|
+
|
67
|
+
def width=(value)
|
68
|
+
super
|
69
|
+
self.diameter = value unless diameter == value
|
70
|
+
self.height = value unless height == value
|
71
|
+
end
|
72
|
+
|
73
|
+
def height=(value)
|
74
|
+
super
|
75
|
+
self.diameter = value unless diameter == value
|
76
|
+
self.width = value unless width == value
|
77
|
+
end
|
78
|
+
|
79
|
+
def radius_x=(value)
|
80
|
+
super
|
81
|
+
self.radius = value unless radius == value
|
82
|
+
self.radius_y = value unless radius_y == value
|
83
|
+
end
|
84
|
+
|
85
|
+
def radius_y=(value)
|
86
|
+
super
|
87
|
+
self.radius = value unless radius == value
|
88
|
+
self.radius_x = value unless radius_x == value
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
data/lib/perfect_shape/shape.rb
CHANGED
@@ -20,6 +20,7 @@
|
|
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
24
|
class Shape
|
24
25
|
# Normalizes point args whether two-number Array or x, y args returning
|
25
26
|
# normalized point array of two BigDecimal's
|
data/perfect-shape.gemspec
CHANGED
@@ -2,16 +2,16 @@
|
|
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.
|
5
|
+
# stub: perfect-shape 0.0.6 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "perfect-shape".freeze
|
9
|
-
s.version = "0.0.
|
9
|
+
s.version = "0.0.6"
|
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]
|
13
13
|
s.authors = ["Andy Maleh".freeze]
|
14
|
-
s.date = "2021-12-
|
14
|
+
s.date = "2021-12-16"
|
15
15
|
s.description = "Perfect Shape is a collection of pure Ruby geometric algorithms that are mostly useful for GUI manipulation like checking containment of a mouse click point in popular geometry shapes such as rectangle, square, arc (open, chord, and pie), ellipse, circle, polygon, polyline, polyquad, polycubic, and paths containing lines, bezier curves, and quadratic curves. Additionally, it contains some purely mathematical algorithms like IEEEremainder (also known as IEEE-754 remainder).".freeze
|
16
16
|
s.email = "andy.am@gmail.com".freeze
|
17
17
|
s.extra_rdoc_files = [
|
@@ -26,6 +26,7 @@ Gem::Specification.new do |s|
|
|
26
26
|
"VERSION",
|
27
27
|
"lib/perfect-shape.rb",
|
28
28
|
"lib/perfect_shape/arc.rb",
|
29
|
+
"lib/perfect_shape/circle.rb",
|
29
30
|
"lib/perfect_shape/ellipse.rb",
|
30
31
|
"lib/perfect_shape/line.rb",
|
31
32
|
"lib/perfect_shape/math.rb",
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: perfect-shape
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andy Maleh
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-12-
|
11
|
+
date: 2021-12-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rdoc
|
@@ -100,6 +100,7 @@ files:
|
|
100
100
|
- VERSION
|
101
101
|
- lib/perfect-shape.rb
|
102
102
|
- lib/perfect_shape/arc.rb
|
103
|
+
- lib/perfect_shape/circle.rb
|
103
104
|
- lib/perfect_shape/ellipse.rb
|
104
105
|
- lib/perfect_shape/line.rb
|
105
106
|
- lib/perfect_shape/math.rb
|