perfect-shape 1.0.5 → 1.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +11 -0
- data/README.md +19 -3
- data/VERSION +1 -1
- data/lib/perfect_shape/multi_point.rb +4 -0
- data/lib/perfect_shape/path.rb +19 -10
- data/lib/perfect_shape/point_location.rb +4 -0
- data/perfect-shape.gemspec +4 -4
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8ccdbd2ecf2cb7dea672b46aa23831ade4b09acfd37242edfc7fb8bb030c574c
|
4
|
+
data.tar.gz: 485341606037a3ac14527338c657afcfad977646318358d56aca2b07e72e498a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9912d75a61a947eea2d993764ed5802d986eb1775169444c798be0e2a51061998a81a7a36c2329c6da0581c38ccbe0dd8aa94f78a771f97e961dc5abcadaca71
|
7
|
+
data.tar.gz: 458e6674b93e4f4eabdba4769927b10ef7292f54bcb6795768e4419e8ded479de5183a3f8a273b82cd7fd4aa388d937a60f31e8577dcff159d88cc102bfa6cba
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,16 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
+
## 1.0.7
|
4
|
+
|
5
|
+
- Support constructing `PerfectShape::Path` without a point at the beginning
|
6
|
+
- Support `first_point` method on all shapes to return first point in a shape
|
7
|
+
- Fix issue in using `Path#contain?` with `outline: true` when `line_to_complex_shapes: true` and path starts with a `Line` instead of a point.
|
8
|
+
|
9
|
+
## 1.0.6
|
10
|
+
|
11
|
+
- Fix issue with `Path#contain?` algorithm not working correclty when `Path` contains non-basic shapes because `shapes.count` is checked instead of `basic_shapes.count`
|
12
|
+
- Document `PerfectShape::MultiPoint`
|
13
|
+
|
3
14
|
## 1.0.5
|
4
15
|
|
5
16
|
- Support Ruby 3.1 by including bundled 'matrix' gem ('>= 0.4.2', '< 1.1.0')
|
data/README.md
CHANGED
@@ -1,8 +1,10 @@
|
|
1
|
-
# Perfect Shape 1.0.
|
1
|
+
# Perfect Shape 1.0.7
|
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)
|
5
5
|
|
6
|
+
([Used by Fukuoka 2022 Special Award Winning Glimmer DSL for LibUI Ruby Desktop Development GUI Library](https://github.com/AndyObtiva/glimmer-dsl-libui))
|
7
|
+
|
6
8
|
[`PerfectShape`](https://rubygems.org/gems/perfect-shape) is a collection of pure Ruby geometric algorithms that are mostly useful for GUI (Graphical User Interface) manipulation like checking viewport rectangle intersection or containment of a mouse click [point](#perfectshapepoint) in popular geometry shapes such as [rectangle](#perfectshaperectangle), [square](#perfectshapesquare), [arc](#perfectshapearc) (open, chord, and pie), [ellipse](#perfectshapeellipse), [circle](#perfectshapecircle), [polygon](#perfectshapepolygon), and [paths](#perfectshapepath) containing [lines](#perfectshapeline), [quadratic bézier curves](#perfectshapequadraticbeziercurve), and [cubic bezier curves](#perfectshapecubicbeziercurve), potentially with [affine transforms](#perfectshapeaffinetransform) applied like translation, scale, rotation, shear/skew, and inversion (including both the [Ray Casting Algorithm](https://en.wikipedia.org/wiki/Point_in_polygon#Ray_casting_algorithm), aka [Even-odd Rule](https://en.wikipedia.org/wiki/Even%E2%80%93odd_rule), and the [Winding Number Algorithm](https://en.wikipedia.org/wiki/Point_in_polygon#Winding_number_algorithm), aka [Nonzero Rule](https://en.wikipedia.org/wiki/Nonzero-rule)).
|
7
9
|
|
8
10
|
Additionally, [`PerfectShape::Math`](#perfectshapemath) contains some purely mathematical algorithms, like [IEEE 754-1985 Remainder](https://en.wikipedia.org/wiki/IEEE_754-1985).
|
@@ -14,13 +16,13 @@ To ensure accuracy and precision, this library does all its mathematical operati
|
|
14
16
|
Run:
|
15
17
|
|
16
18
|
```
|
17
|
-
gem install perfect-shape -v 1.0.
|
19
|
+
gem install perfect-shape -v 1.0.7
|
18
20
|
```
|
19
21
|
|
20
22
|
Or include in Bundler `Gemfile`:
|
21
23
|
|
22
24
|
```ruby
|
23
|
-
gem 'perfect-shape', '~> 1.0.
|
25
|
+
gem 'perfect-shape', '~> 1.0.7'
|
24
26
|
```
|
25
27
|
|
26
28
|
And, run:
|
@@ -68,6 +70,7 @@ Module
|
|
68
70
|
- `#y`: top-left y
|
69
71
|
- `#min_x`: min x (x by default)
|
70
72
|
- `#min_y`: min y (y by default)
|
73
|
+
- `#first_point`: first point for shape including this module (always assumes top-left corner)
|
71
74
|
|
72
75
|
### `PerfectShape::RectangularShape`
|
73
76
|
|
@@ -85,6 +88,19 @@ Includes `PerfectShape::PointLocation`
|
|
85
88
|
- `#max_x`: max x
|
86
89
|
- `#max_y`: max y
|
87
90
|
|
91
|
+
### `PerfectShape::MultiPoint`
|
92
|
+
|
93
|
+
Module
|
94
|
+
|
95
|
+
- `::normalize_point_array`: normalizes `Array` of multiple points into (x,y) point coordinate `Array` format per point
|
96
|
+
- `#initialize(points: [])`: initializes `points` with `Array` of multiple points (e.g. useful for shapes like `Line` and `Polygon`).
|
97
|
+
- `#points`: `Array` of multiple points
|
98
|
+
- `#min_x`: min x of all points
|
99
|
+
- `#min_y`: min y of all points
|
100
|
+
- `#max_x`: max x of all points
|
101
|
+
- `#max_y`: max y of all points
|
102
|
+
- `#first_point`: first point for shape including this module
|
103
|
+
|
88
104
|
### `PerfectShape::AffineTransform`
|
89
105
|
|
90
106
|
Class
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0.
|
1
|
+
1.0.7
|
data/lib/perfect_shape/path.rb
CHANGED
@@ -64,14 +64,20 @@ module PerfectShape
|
|
64
64
|
|
65
65
|
def points
|
66
66
|
the_points = []
|
67
|
-
basic_shapes.
|
67
|
+
basic_shapes.each_with_index do |shape, i|
|
68
68
|
case shape
|
69
69
|
when Point
|
70
70
|
the_points << shape.to_a
|
71
71
|
when Array
|
72
72
|
the_points << shape.map {|n| BigDecimal(n.to_s)}
|
73
73
|
when Line
|
74
|
-
|
74
|
+
if i == 0
|
75
|
+
shape.points.each do |point|
|
76
|
+
the_points << point.to_a
|
77
|
+
end
|
78
|
+
else
|
79
|
+
the_points << shape.points.last.to_a
|
80
|
+
end
|
75
81
|
when QuadraticBezierCurve
|
76
82
|
shape.points.each do |point|
|
77
83
|
the_points << point.to_a
|
@@ -82,7 +88,7 @@ module PerfectShape
|
|
82
88
|
end
|
83
89
|
end
|
84
90
|
end
|
85
|
-
the_points << basic_shapes.first.
|
91
|
+
the_points << basic_shapes.first.first_point if closed?
|
86
92
|
the_points
|
87
93
|
end
|
88
94
|
|
@@ -91,14 +97,14 @@ module PerfectShape
|
|
91
97
|
end
|
92
98
|
|
93
99
|
def drawing_types
|
94
|
-
the_drawing_shapes = basic_shapes.
|
100
|
+
the_drawing_shapes = basic_shapes.each_with_index.flat_map do |shape, i|
|
95
101
|
case shape
|
96
102
|
when Point
|
97
103
|
:move_to
|
98
104
|
when Array
|
99
105
|
:move_to
|
100
106
|
when Line
|
101
|
-
:line_to
|
107
|
+
(i == 0) ? [:move_to, :line_to] : :line_to
|
102
108
|
when QuadraticBezierCurve
|
103
109
|
:quad_to
|
104
110
|
when CubicBezierCurve
|
@@ -134,7 +140,7 @@ module PerfectShape
|
|
134
140
|
if (x * 0.0 + y * 0.0) == 0.0
|
135
141
|
# N * 0.0 is 0.0 only if N is finite.
|
136
142
|
# Here we know that both x and y are finite.
|
137
|
-
return false if
|
143
|
+
return false if basic_shapes.count < 2
|
138
144
|
mask = winding_rule == :wind_non_zero ? -1 : 1
|
139
145
|
(point_crossings(x, y) & mask) != 0
|
140
146
|
else
|
@@ -161,14 +167,14 @@ module PerfectShape
|
|
161
167
|
def point_crossings(x_or_point, y = nil)
|
162
168
|
x, y = Point.normalize_point(x_or_point, y)
|
163
169
|
return unless x && y
|
164
|
-
return 0 if
|
170
|
+
return 0 if basic_shapes.count == 0
|
165
171
|
movx = movy = curx = cury = endx = endy = 0
|
166
172
|
coords = points.flatten
|
167
173
|
curx = movx = coords[0]
|
168
174
|
cury = movy = coords[1]
|
169
175
|
crossings = 0
|
170
176
|
ci = 2
|
171
|
-
1.upto(
|
177
|
+
1.upto(basic_shapes.count - 1).each do |i|
|
172
178
|
case drawing_types[i]
|
173
179
|
when :move_to
|
174
180
|
if cury != movy
|
@@ -244,7 +250,9 @@ module PerfectShape
|
|
244
250
|
# Lastly, if the path is closed, an extra shape is
|
245
251
|
# added to represent the line connecting the last point to the first
|
246
252
|
def disconnected_shapes
|
247
|
-
|
253
|
+
# TODO it seems basic_shapes.first should always return a point, but there is a case with CompositeShape that results in a line (shape) not point returned
|
254
|
+
first_point = basic_shapes.first.is_a?(Array) ? basic_shapes.first : basic_shapes.first.first_point
|
255
|
+
initial_point = start_point = first_point.map {|n| BigDecimal(n.to_s)}
|
248
256
|
final_point = nil
|
249
257
|
the_disconnected_shapes = basic_shapes.drop(1).map do |shape|
|
250
258
|
case shape
|
@@ -388,9 +396,10 @@ module PerfectShape
|
|
388
396
|
# decomposed from complex shapes like Arc, Ellipse, and Circle by calling their `#to_path_shapes` method
|
389
397
|
def basic_shapes
|
390
398
|
the_shapes = []
|
391
|
-
@shapes.
|
399
|
+
@shapes.each_with_index do |shape, i|
|
392
400
|
if shape.respond_to?(:to_path_shapes)
|
393
401
|
shape_basic_shapes = shape.to_path_shapes
|
402
|
+
the_shapes << shape.first_point if i == 0
|
394
403
|
if @line_to_complex_shapes
|
395
404
|
first_basic_shape = shape_basic_shapes.shift
|
396
405
|
new_first_basic_shape = PerfectShape::Line.new(points: [first_basic_shape.to_a])
|
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 1.0.
|
5
|
+
# stub: perfect-shape 1.0.7 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "perfect-shape".freeze
|
9
|
-
s.version = "1.0.
|
9
|
+
s.version = "1.0.7"
|
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 = "2022-
|
14
|
+
s.date = "2022-11-19"
|
15
15
|
s.description = "Perfect Shape is a collection of pure Ruby geometric algorithms that are mostly useful for GUI manipulation like checking viewport rectangle intersection or containment of a mouse click point in popular geometry shapes such as rectangle, square, arc (open, chord, and pie), ellipse, circle, polygon, and paths containing lines, quadratic b\u00E9zier curves, and cubic bezier curves, potentially with affine transforms applied like translation, scale, rotation, shear/skew, and inversion (including both the Ray Casting Algorithm, aka Even-odd Rule, and the Winding Number Algorithm, aka Nonzero Rule). 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 = [
|
@@ -47,7 +47,7 @@ Gem::Specification.new do |s|
|
|
47
47
|
]
|
48
48
|
s.homepage = "http://github.com/AndyObtiva/perfect-shape".freeze
|
49
49
|
s.licenses = ["MIT".freeze]
|
50
|
-
s.rubygems_version = "3.3.
|
50
|
+
s.rubygems_version = "3.3.16".freeze
|
51
51
|
s.summary = "Perfect Shape - Geometric Algorithms".freeze
|
52
52
|
|
53
53
|
if s.respond_to? :specification_version then
|
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: 1.0.
|
4
|
+
version: 1.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andy Maleh
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-11-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: matrix
|
@@ -180,7 +180,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
180
180
|
- !ruby/object:Gem::Version
|
181
181
|
version: '0'
|
182
182
|
requirements: []
|
183
|
-
rubygems_version: 3.3.
|
183
|
+
rubygems_version: 3.3.16
|
184
184
|
signing_key:
|
185
185
|
specification_version: 4
|
186
186
|
summary: Perfect Shape - Geometric Algorithms
|