perfect-shape 0.5.3 → 0.5.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +20 -5
- data/README.md +8 -4
- data/VERSION +1 -1
- data/lib/perfect_shape/rectangle.rb +19 -0
- data/lib/perfect_shape/square.rb +6 -2
- data/perfect-shape.gemspec +2 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 98226e1aac4fbac06b162630c2dbaa5ca2f749d24590cc0bd0cca9924f760635
|
4
|
+
data.tar.gz: 3d7d5be2905838db9ff1b3f2876e8437e0df90d9ac6b2316c1347aa4f58db626
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 686a5054b13bd3adf1176e779e80d2ef758c4cf9cc25625633151628a724c1b802c03847301a447fb14155b570ee0fe0fdf8fe4d357b92186bdd7df83d6de240
|
7
|
+
data.tar.gz: e05c4a2eb8d2efa7feef615dc5dd3d522778d8aa98b60845726de0d3a0e68bf84ffa173984d0a907401838a16432b725ed1e0ac5ac1d4239ed66596181dac324
|
data/CHANGELOG.md
CHANGED
@@ -1,21 +1,36 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
+
## 0.5.4
|
4
|
+
|
5
|
+
- `PerfectShape::Rectangle#intersect?(rectangle)`
|
6
|
+
- `PerfectShape::Square#intersect?(rectangle)`
|
7
|
+
- `PerfectShape::Rectangle#empty?`
|
8
|
+
- `PerfectShape::Square#empty?`
|
9
|
+
- `PerfectShape::Square#size`/`PerfectShape::Square#size=` aliases for `#length`/`#length=`
|
10
|
+
|
3
11
|
## 0.5.3
|
4
12
|
|
5
|
-
- `CubicBezierCurve#intersect?(rectangle)`
|
13
|
+
- `PerfectShape::CubicBezierCurve#intersect?(rectangle)`
|
14
|
+
- `PerfectShape::CubicBezierCurve#rectangle_crossings(rectangle)`
|
15
|
+
- `PerfectShape::CubicBezierCurve#rect_crossings(rxmin, rymin, rxmax, rymax, level, crossings = 0)`
|
16
|
+
- `PerfectShape::Line#rect_crossings(rxmin, rymin, rxmax, rymax, crossings = 0)`
|
6
17
|
|
7
18
|
## 0.5.2
|
8
19
|
|
9
|
-
- `QuadraticBezierCurve#intersect?(rectangle)`
|
20
|
+
- `PerfectShape::QuadraticBezierCurve#intersect?(rectangle)`
|
21
|
+
- `PerfectShape::QuadraticBezierCurve::tag(coord, low, high)`
|
22
|
+
- `PerfectShape::QuadraticBezierCurve::eqn(val, c1, cp, c2)`
|
23
|
+
- `PerfectShape::QuadraticBezierCurve::solve_quadratic(eqn)`
|
24
|
+
- `PerfectShape::QuadraticBezierCurve::eval_quadratic(vals, num, include0, include1, inflect, c1, ctrl, c2)`
|
10
25
|
|
11
26
|
## 0.5.1
|
12
27
|
|
13
|
-
- `Point#intersect?(rectangle)` (equivalent to `Rectangle#contain?(point)`)
|
28
|
+
- `PerfectShape::Point#intersect?(rectangle)` (equivalent to `PerfectShape::Rectangle#contain?(point)`)
|
14
29
|
|
15
30
|
## 0.5.0
|
16
31
|
|
17
|
-
- `Line#intersect?(rectangle)`
|
18
|
-
- `Rectangle#out_state(x_or_point, y = nil)`
|
32
|
+
- `PerfectShape::Line#intersect?(rectangle)`
|
33
|
+
- `PerfectShape::Rectangle#out_state(x_or_point, y = nil)`
|
19
34
|
|
20
35
|
## 0.4.0
|
21
36
|
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Perfect Shape 0.5.
|
1
|
+
# Perfect Shape 0.5.4
|
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
|
[![Test](https://github.com/AndyObtiva/perfect-shape/actions/workflows/ruby.yml/badge.svg)](https://github.com/AndyObtiva/perfect-shape/actions/workflows/ruby.yml)
|
@@ -14,13 +14,13 @@ To ensure high accuracy, this library does all its mathematical operations with
|
|
14
14
|
Run:
|
15
15
|
|
16
16
|
```
|
17
|
-
gem install perfect-shape -v 0.5.
|
17
|
+
gem install perfect-shape -v 0.5.4
|
18
18
|
```
|
19
19
|
|
20
20
|
Or include in Bundler `Gemfile`:
|
21
21
|
|
22
22
|
```ruby
|
23
|
-
gem 'perfect-shape', '~> 0.5.
|
23
|
+
gem 'perfect-shape', '~> 0.5.4'
|
24
24
|
```
|
25
25
|
|
26
26
|
And, run:
|
@@ -372,8 +372,10 @@ Includes `PerfectShape::RectangularShape`
|
|
372
372
|
- `#bounding_box`: bounding box is a rectangle with x = min x, y = min y, and width/height of shape
|
373
373
|
- `#==(other)`: Returns `true` if equal to `other` or `false` otherwise
|
374
374
|
- `#contain?(x_or_point, y=nil, outline: false, distance_tolerance: 0)`: checks if point is inside when `outline` is `false` or if point is on the outline when `outline` is `true`. `distance_tolerance` can be used as a fuzz factor when `outline` is `true`, for example, to help GUI users mouse-click-select a rectangle shape from its outline more successfully
|
375
|
+
- `#intersect?(rectangle)`: Returns `true` if intersecting with interior of rectangle or `false` otherwise. This is useful for GUI optimization checks of whether a shape appears in a GUI viewport rectangle and needs redrawing
|
375
376
|
- `#edges`: edges of rectangle as `PerfectShape::Line` objects
|
376
377
|
- `#out_state(x_or_point, y = nil)`: Returns "out state" of specified point (x,y) (whether it lies to the left, right, top, bottom of rectangle). If point is outside rectangle, it returns a bit mask combination of `Rectangle::OUT_LEFT`, `Rectangle::OUT_RIGHT`, `Rectangle::OUT_TOP`, or `Rectangle::OUT_BOTTOM`. Otherwise, it returns `0` if point is inside the rectangle.
|
378
|
+
- `#empty?`: Returns `true` if width or height are 0 (or negative) and `false` otherwise
|
377
379
|
|
378
380
|
Example:
|
379
381
|
|
@@ -402,7 +404,7 @@ Extends `PerfectShape::Rectangle`
|
|
402
404
|
|
403
405
|
![square](https://raw.githubusercontent.com/AndyObtiva/perfect-shape/master/images/square.png)
|
404
406
|
|
405
|
-
- `::new(x: 0, y: 0, length: 1)
|
407
|
+
- `::new(x: 0, y: 0, length: 1)` (`length` alias: `size`): constructs a square
|
406
408
|
- `#x`: top-left x
|
407
409
|
- `#y`: top-left y
|
408
410
|
- `#length`: length
|
@@ -418,7 +420,9 @@ Extends `PerfectShape::Rectangle`
|
|
418
420
|
- `#bounding_box`: bounding box is a rectangle with x = min x, y = min y, and width/height of shape
|
419
421
|
- `#==(other)`: Returns `true` if equal to `other` or `false` otherwise
|
420
422
|
- `#contain?(x_or_point, y=nil, outline: false, distance_tolerance: 0)`: checks if point is inside when `outline` is `false` or if point is on the outline when `outline` is `true`. `distance_tolerance` can be used as a fuzz factor when `outline` is `true`, for example, to help GUI users mouse-click-select a square shape from its outline more successfully
|
423
|
+
- `#intersect?(rectangle)`: Returns `true` if intersecting with interior of rectangle or `false` otherwise. This is useful for GUI optimization checks of whether a shape appears in a GUI viewport rectangle and needs redrawing
|
421
424
|
- `#edges`: edges of square as `PerfectShape::Line` objects
|
425
|
+
- `#empty?`: Returns `true` if length is 0 (or negative) and `false` otherwise
|
422
426
|
|
423
427
|
Example:
|
424
428
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.5.
|
1
|
+
0.5.4
|
@@ -97,5 +97,24 @@ module PerfectShape
|
|
97
97
|
end
|
98
98
|
out
|
99
99
|
end
|
100
|
+
|
101
|
+
# A rectangle is empty if its width or height is 0 (or less)
|
102
|
+
def empty?
|
103
|
+
width <= 0.0 || height <= 0.0
|
104
|
+
end
|
105
|
+
|
106
|
+
def intersect?(rectangle)
|
107
|
+
x = rectangle.x
|
108
|
+
y = rectangle.y
|
109
|
+
w = rectangle.width
|
110
|
+
h = rectangle.height
|
111
|
+
return false if empty? || w <= 0 || h <= 0
|
112
|
+
x0 = self.x
|
113
|
+
y0 = self.y
|
114
|
+
(x + w) > x0 &&
|
115
|
+
(y + h) > y0 &&
|
116
|
+
x < (x0 + self.width) &&
|
117
|
+
y < (y0 + self.height)
|
118
|
+
end
|
100
119
|
end
|
101
120
|
end
|
data/lib/perfect_shape/square.rb
CHANGED
@@ -23,12 +23,15 @@ require 'perfect_shape/rectangle'
|
|
23
23
|
|
24
24
|
module PerfectShape
|
25
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!'
|
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 constructor arguments!'
|
27
27
|
|
28
28
|
attr_reader :length
|
29
|
+
alias size length
|
29
30
|
|
30
31
|
# 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
|
+
def initialize(x: 0, y: 0, length: nil, size: nil, width: nil, height: nil)
|
33
|
+
raise MESSAGE_WIDTH_AND_HEIGHT_AND_LENGTH_NOT_EQUAL if (length && size && length != size)
|
34
|
+
length ||= size
|
32
35
|
raise MESSAGE_WIDTH_AND_HEIGHT_AND_LENGTH_NOT_EQUAL if (length && width && length != width) || (length && height && length != height) || (width && height && width != height)
|
33
36
|
length ||= width || height || 1
|
34
37
|
super(x: x, y: y, width: length, height: length)
|
@@ -40,6 +43,7 @@ module PerfectShape
|
|
40
43
|
self.width = value unless width == value
|
41
44
|
self.height = value unless height == value
|
42
45
|
end
|
46
|
+
alias size= length=
|
43
47
|
|
44
48
|
def width=(value)
|
45
49
|
super
|
data/perfect-shape.gemspec
CHANGED
@@ -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.5.
|
5
|
+
# stub: perfect-shape 0.5.4 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "perfect-shape".freeze
|
9
|
-
s.version = "0.5.
|
9
|
+
s.version = "0.5.4"
|
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]
|