perfect-shape 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +31 -4
- data/VERSION +1 -1
- data/lib/perfect_shape/ellipse.rb +78 -0
- data/perfect-shape.gemspec +4 -3
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b287e3d8aee766314feeccc80abe127dc1ec6e8d169af61e8c6efc1097a2b5c2
|
4
|
+
data.tar.gz: 96b934dde2686223634244d6ff550b578c15971b2198cb94fb0cec3ded97e06c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6743fed8d87b2ceb4bd69b91fd2ecc3b6655eca986e4a67c2aa755d53f29de60ffbb6fcc539fc45e480f55e06c176cad1885dd3c4af0330a42218b8291837763
|
7
|
+
data.tar.gz: b3669ef0aabb19553bad2dc51cdca4b1c188d05cca41c73c13570f0faff19d03d373f7727c423531700cd85e562b340003995558f2c7e4c8c195947e44b232fa
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
# Perfect Shape 0.0.
|
1
|
+
# Perfect Shape 0.0.5
|
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
|
|
5
|
-
`PerfectShape` is a collection of pure Ruby geometric algorithms that are mostly useful for GUI (Graphical User Interface) 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,
|
5
|
+
`PerfectShape` is a collection of pure Ruby geometric algorithms that are mostly useful for GUI (Graphical User Interface) 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.
|
6
6
|
|
7
7
|
Additionally, `PerfectShape::Math` contains some purely mathematical algorithms.
|
8
8
|
|
@@ -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.5
|
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.5'
|
23
23
|
```
|
24
24
|
|
25
25
|
And, run:
|
@@ -43,6 +43,8 @@ bundle
|
|
43
43
|
|
44
44
|
### `PerfectShape::Rectangle`
|
45
45
|
|
46
|
+
Includes `PerfectShape::RectangularShape`
|
47
|
+
|
46
48
|
![rectangle](images/rectangle.png)
|
47
49
|
|
48
50
|
- `::new(x: 0, y: 0, width: 1, height: 1)`: constructs a rectangle
|
@@ -56,6 +58,8 @@ bundle
|
|
56
58
|
|
57
59
|
### `PerfectShape::Square`
|
58
60
|
|
61
|
+
Extends `PerfectShape::Rectangle`
|
62
|
+
|
59
63
|
![square](images/square.png)
|
60
64
|
|
61
65
|
- `::new(x: 0, y: 0, length: 1)`: constructs a square
|
@@ -70,6 +74,8 @@ bundle
|
|
70
74
|
|
71
75
|
### `PerfectShape::Arc`
|
72
76
|
|
77
|
+
Includes `PerfectShape::RectangularShape`
|
78
|
+
|
73
79
|
Arcs can be of type `:open`, `:chord`, or `:pie`
|
74
80
|
|
75
81
|
Open Arc | Chord Arc | Pie Arc
|
@@ -77,6 +83,7 @@ Open Arc | Chord Arc | Pie Arc
|
|
77
83
|
![arc-open](images/arc-open.png) | ![arc-chord](images/arc-chord.png) | ![arc-pie](images/arc-pie.png)
|
78
84
|
|
79
85
|
- `::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
|
+
- `#type`: `:open`, `:chord`, or `:pie`
|
80
87
|
- `#x`: top-left x of arc
|
81
88
|
- `#y`: top-left y of arc
|
82
89
|
- `#width`: width of arc
|
@@ -89,6 +96,26 @@ Open Arc | Chord Arc | Pie Arc
|
|
89
96
|
- `#radius_y`: radius along the y-axis
|
90
97
|
- `#contain?(x_or_point, y=nil)`: checks if point is inside
|
91
98
|
|
99
|
+
### `PerfectShape::Ellipse`
|
100
|
+
|
101
|
+
Extends `PerfectShape::Arc`
|
102
|
+
|
103
|
+
![ellipse](images/ellipse.png)
|
104
|
+
|
105
|
+
- `::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 of arc
|
107
|
+
- `#y`: top-left y of arc
|
108
|
+
- `#width`: width of arc
|
109
|
+
- `#height`: height of arc
|
110
|
+
- `#center_x`: center x
|
111
|
+
- `#center_y`: center y
|
112
|
+
- `#radius_x`: radius along the x-axis
|
113
|
+
- `#radius_y`: radius along the y-axis
|
114
|
+
- `#type`: always `:open`
|
115
|
+
- `#start`: always `0`
|
116
|
+
- `#extent`: always `360`
|
117
|
+
- `#contain?(x_or_point, y=nil)`: checks if point is inside
|
118
|
+
|
92
119
|
## Process
|
93
120
|
|
94
121
|
[Glimmer Process](https://github.com/AndyObtiva/glimmer/blob/master/PROCESS.md)
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.5
|
@@ -0,0 +1,78 @@
|
|
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/arc'
|
23
|
+
|
24
|
+
module PerfectShape
|
25
|
+
# Mostly ported from java.awt.geom: https://docs.oracle.com/javase/8/docs/api/java/awt/geom/Ellipse2D.html
|
26
|
+
class Ellipse < Arc
|
27
|
+
MESSAGE_CANNOT_UPDATE_ATTRIUBTE = "Ellipse %s cannot be updated. If you want to update type, use Arc instead!"
|
28
|
+
|
29
|
+
def initialize(x: 0, y: 0, width: 1, height: 1, center_x: nil, center_y: nil, radius_x: nil, radius_y: nil)
|
30
|
+
super
|
31
|
+
@initialized = true
|
32
|
+
end
|
33
|
+
|
34
|
+
def type=(value)
|
35
|
+
if @initialized
|
36
|
+
raise MESSAGE_CANNOT_UPDATE_ATTRIUBTE % 'type'
|
37
|
+
else
|
38
|
+
super
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def start=(value)
|
43
|
+
if @initialized
|
44
|
+
raise MESSAGE_CANNOT_UPDATE_ATTRIUBTE % 'start'
|
45
|
+
else
|
46
|
+
super
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def extent=(value)
|
51
|
+
if @initialized
|
52
|
+
raise MESSAGE_CANNOT_UPDATE_ATTRIUBTE % 'extent'
|
53
|
+
else
|
54
|
+
super
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
# Checks if ellipse contains point denoted by point (two-number Array or x, y args)
|
59
|
+
#
|
60
|
+
# @param x The X coordinate of the point to test.
|
61
|
+
# @param y The Y coordinate of the point to test.
|
62
|
+
#
|
63
|
+
# @return {@code true} if the point lies within the bound of
|
64
|
+
# the ellipse, {@code false} if the point lies outside of the
|
65
|
+
# ellipse's bounds.
|
66
|
+
def contain?(x_or_point, y = nil)
|
67
|
+
x, y = normalize_point(x_or_point, y)
|
68
|
+
return unless x && y
|
69
|
+
ellw = self.width
|
70
|
+
return false if ellw <= 0.0
|
71
|
+
normx = (x - self.x) / ellw - 0.5
|
72
|
+
ellh = self.height
|
73
|
+
return false if ellh <= 0.0
|
74
|
+
normy = (y - self.y) / ellh - 0.5
|
75
|
+
(normx * normx + normy * normy) < 0.25
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
data/perfect-shape.gemspec
CHANGED
@@ -2,17 +2,17 @@
|
|
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.5 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.5"
|
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
14
|
s.date = "2021-12-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,
|
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 = [
|
18
18
|
"CHANGELOG.md",
|
@@ -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/ellipse.rb",
|
29
30
|
"lib/perfect_shape/line.rb",
|
30
31
|
"lib/perfect_shape/math.rb",
|
31
32
|
"lib/perfect_shape/rectangle.rb",
|
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.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andy Maleh
|
@@ -83,9 +83,9 @@ dependencies:
|
|
83
83
|
description: Perfect Shape is a collection of pure Ruby geometric algorithms that
|
84
84
|
are mostly useful for GUI manipulation like checking containment of a mouse click
|
85
85
|
point in popular geometry shapes such as rectangle, square, arc (open, chord, and
|
86
|
-
pie), ellipse, circle, polygon, polyline,
|
87
|
-
bezier curves, and quadratic curves. Additionally, it contains some purely
|
88
|
-
algorithms like IEEEremainder (also known as IEEE-754 remainder).
|
86
|
+
pie), ellipse, circle, polygon, polyline, polyquad, polycubic, and paths containing
|
87
|
+
lines, bezier curves, and quadratic curves. Additionally, it contains some purely
|
88
|
+
mathematical algorithms like IEEEremainder (also known as IEEE-754 remainder).
|
89
89
|
email: andy.am@gmail.com
|
90
90
|
executables: []
|
91
91
|
extensions: []
|
@@ -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/ellipse.rb
|
103
104
|
- lib/perfect_shape/line.rb
|
104
105
|
- lib/perfect_shape/math.rb
|
105
106
|
- lib/perfect_shape/rectangle.rb
|