perfect-shape 0.0.2 → 0.0.3
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 +15 -5
- data/VERSION +1 -1
- data/lib/perfect_shape/rectangle.rb +1 -1
- data/lib/perfect_shape/square.rb +58 -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: 5f13ff7665704c6183553e3ba4391c1890b9ac9846177e8c31226689da7a13bf
|
4
|
+
data.tar.gz: 427d591daa1567bd4336aef61b35423cf63a8c41d9b8e9d7d3099b07db14ec41
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 87314aced3ca151bdefcf6e23af5ba3c3b340503d0b194c93e4b46cce2d1f7375fe79edecc588d394ccfcb7d915282dde45c6eb1f7c7ad8e8e22608876dd05ad
|
7
|
+
data.tar.gz: ad32f360bc0d2a3bab95b826a7946dc81f6fa0900c29fabbe93a67d238d0b449adc3d46ec26324bdfb9f3a3d61373192cc27b5ffa169c103dfcf1865dede58e5
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Perfect Shape 0.0.
|
1
|
+
# Perfect Shape 0.0.3
|
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.3
|
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.3'
|
23
23
|
```
|
24
24
|
|
25
25
|
And, run:
|
@@ -47,7 +47,17 @@ bundle
|
|
47
47
|
- `#y`: top-left y
|
48
48
|
- `#width`: width
|
49
49
|
- `#height`: height
|
50
|
-
- `#contain?(x_or_point, y=nil)`: checks if point inside
|
50
|
+
- `#contain?(x_or_point, y=nil)`: checks if point is inside
|
51
|
+
|
52
|
+
### `PerfectShape::Square`
|
53
|
+
|
54
|
+
- `::new(x: 0, y: 0, length: 1)`: constructs a square
|
55
|
+
- `#x`: top-left x
|
56
|
+
- `#y`: top-left y
|
57
|
+
- `#length`: length
|
58
|
+
- `#width`: width (equal to length)
|
59
|
+
- `#height`: height (equal to length)
|
60
|
+
- `#contain?(x_or_point, y=nil)`: checks if point is inside
|
51
61
|
|
52
62
|
### `PerfectShape::Arc`
|
53
63
|
|
@@ -58,7 +68,7 @@ bundle
|
|
58
68
|
- `#height`: height of arc
|
59
69
|
- `#start`: start angle in degrees
|
60
70
|
- `#extent`: extent angle in degrees
|
61
|
-
- `#contain?(x_or_point, y=nil)`: checks if point is
|
71
|
+
- `#contain?(x_or_point, y=nil)`: checks if point is inside
|
62
72
|
|
63
73
|
## Process
|
64
74
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.3
|
@@ -38,7 +38,7 @@ module PerfectShape
|
|
38
38
|
def contain?(x_or_point, y = nil)
|
39
39
|
x, y = normalize_point(x_or_point, y)
|
40
40
|
return unless x && y
|
41
|
-
x.between?(
|
41
|
+
x.between?(self.x, self.x + self.width) && y.between?(self.y, self.y + self.height)
|
42
42
|
end
|
43
43
|
end
|
44
44
|
end
|
@@ -0,0 +1,58 @@
|
|
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/rectangle'
|
23
|
+
|
24
|
+
module PerfectShape
|
25
|
+
class Square < Rectangle
|
26
|
+
MESSAGE_WIDTH_AND_HEIGHT_AND_LENGTH_NOT_EQUAL = 'Square width, height, and length must all be equal if more than one is specified; or otherwise keep only one of them in arguments!'
|
27
|
+
|
28
|
+
attr_reader :length
|
29
|
+
|
30
|
+
# Constructs with x, y, length (optionally width or height can be passed as alias for length)
|
31
|
+
def initialize(x: 0, y: 0, length: nil, width: nil, height: nil)
|
32
|
+
raise MESSAGE_WIDTH_AND_HEIGHT_AND_LENGTH_NOT_EQUAL if (length && width && length != width) || (length && height && length != height) || (width && height && width != height)
|
33
|
+
length ||= width || height || 1
|
34
|
+
super(x: x, y: y, width: length, height: length)
|
35
|
+
end
|
36
|
+
|
37
|
+
# Sets length, normalizing to BigDecimal
|
38
|
+
def length=(value)
|
39
|
+
@length = BigDecimal(value.to_s)
|
40
|
+
end
|
41
|
+
|
42
|
+
def width=(value)
|
43
|
+
self.length = value
|
44
|
+
end
|
45
|
+
|
46
|
+
def height=(value)
|
47
|
+
self.length = value
|
48
|
+
end
|
49
|
+
|
50
|
+
def width
|
51
|
+
length
|
52
|
+
end
|
53
|
+
|
54
|
+
def height
|
55
|
+
length
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
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.3 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.3"
|
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-13"
|
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, ellipse, circle, polygon, polyline, polybezier, 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 = [
|
@@ -31,6 +31,7 @@ Gem::Specification.new do |s|
|
|
31
31
|
"lib/perfect_shape/rectangle.rb",
|
32
32
|
"lib/perfect_shape/rectangular_shape.rb",
|
33
33
|
"lib/perfect_shape/shape.rb",
|
34
|
+
"lib/perfect_shape/square.rb",
|
34
35
|
"perfect-shape.gemspec"
|
35
36
|
]
|
36
37
|
s.homepage = "http://github.com/AndyObtiva/perfect-shape".freeze
|
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.3
|
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-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rdoc
|
@@ -105,6 +105,7 @@ files:
|
|
105
105
|
- lib/perfect_shape/rectangle.rb
|
106
106
|
- lib/perfect_shape/rectangular_shape.rb
|
107
107
|
- lib/perfect_shape/shape.rb
|
108
|
+
- lib/perfect_shape/square.rb
|
108
109
|
- perfect-shape.gemspec
|
109
110
|
homepage: http://github.com/AndyObtiva/perfect-shape
|
110
111
|
licenses:
|