perfect-shape 1.0.2 → 1.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 +6 -1
- data/README.md +8 -6
- data/VERSION +1 -1
- data/lib/perfect_shape/arc.rb +0 -9
- data/lib/perfect_shape/cubic_bezier_curve.rb +0 -2
- data/lib/perfect_shape/rectangle.rb +38 -0
- data/perfect-shape.gemspec +3 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4e9d2cae407980abba8c58b3a38979723ffbb95bd7b0cc832d33fbc6a60e1700
|
4
|
+
data.tar.gz: fce964dcf5e15a9f4de977a70d6f95c31cd02ad5674b5ee546328be9c606e8a4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 27da7756bb313e2499c1aebd25ba92691140763bc8a41402e3202be4d9d80feab95392dd6cb1c655dc104cd9ab98c09cea22a9e7bf19fa5a8266a017d935212b
|
7
|
+
data.tar.gz: 663348a23058f6e88f3e1bf28441692684fa6df9abd3579a5444e84609808a829c05d2b57742b3646094998c8725ec73fb35a733767117f811196ba191c0d05f
|
data/CHANGELOG.md
CHANGED
@@ -1,9 +1,14 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
+
## 1.0.3
|
4
|
+
|
5
|
+
- `Rectangle` and `Square` `#to_path_shapes` method, which decomposes them into `Point`s and `Line`s to be added to a `Path`
|
6
|
+
- `Path` can contain a `Rectangle` or `Square` (to get affected by the winding algorithm as opposed to `CompositeShape`, which has no winding algorithm)
|
7
|
+
|
3
8
|
## 1.0.2
|
4
9
|
|
5
|
-
- `Path` can contain an `Arc`, `Ellipse`, or `Circle` (to get affected by the winding algorithm as opposed to `CompositeShape` which has no winding algorithm)
|
6
10
|
- `Arc`, `Ellipse`, and `Circle` `#to_path_shapes` method, which decomposes them into `Point`s, `Line`s, and `CubicBezierCurve`s to be added to a `Path`
|
11
|
+
- `Path` can contain an `Arc`, `Ellipse`, or `Circle` (to get affected by the winding algorithm as opposed to `CompositeShape`, which has no winding algorithm)
|
7
12
|
|
8
13
|
## 1.0.1
|
9
14
|
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Perfect Shape 1.0.
|
1
|
+
# Perfect Shape 1.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
|
[![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 1.0.
|
17
|
+
gem install perfect-shape -v 1.0.3
|
18
18
|
```
|
19
19
|
|
20
20
|
Or include in Bundler `Gemfile`:
|
21
21
|
|
22
22
|
```ruby
|
23
|
-
gem 'perfect-shape', '~> 1.0.
|
23
|
+
gem 'perfect-shape', '~> 1.0.3'
|
24
24
|
```
|
25
25
|
|
26
26
|
And, run:
|
@@ -377,6 +377,7 @@ Includes `PerfectShape::RectangularShape`
|
|
377
377
|
- `#edges`: edges of rectangle as `PerfectShape::Line` objects
|
378
378
|
- `#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.
|
379
379
|
- `#empty?`: Returns `true` if width or height are 0 (or negative) and `false` otherwise
|
380
|
+
- `#to_path_shapes`: Converts `Rectangle` into basic `Path` shapes made up of `Point`s and `Line`s. Used by `Path` when adding a `Rectangle` to `Path` `shapes`
|
380
381
|
|
381
382
|
Example:
|
382
383
|
|
@@ -424,6 +425,7 @@ Extends `PerfectShape::Rectangle`
|
|
424
425
|
- `#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
|
425
426
|
- `#edges`: edges of square as `PerfectShape::Line` objects
|
426
427
|
- `#empty?`: Returns `true` if length is 0 (or negative) and `false` otherwise
|
428
|
+
- `#to_path_shapes`: Converts `Square` into basic `Path` shapes made up of `Point`s and `Line`s. Used by `Path` when adding a `Square` to `Path` `shapes`
|
427
429
|
|
428
430
|
Example:
|
429
431
|
|
@@ -760,9 +762,9 @@ Includes `PerfectShape::MultiPoint`
|
|
760
762
|
|
761
763
|
![path](https://raw.githubusercontent.com/AndyObtiva/perfect-shape/master/images/path.png)
|
762
764
|
|
763
|
-
- `::new(shapes: [], closed: false, winding_rule: :wind_even_odd, line_to_complex_shapes: false)`: constructs a path with `shapes` as `Array` of shape objects, which can be `PerfectShape::Point` (or `Array` of `[x, y]` coordinates), `PerfectShape::Line`, `PerfectShape::QuadraticBezierCurve`, `PerfectShape::CubicBezierCurve`, or complex shapes that decompose into the aforementioned basic path shapes, like `PerfectShape::Arc`, `PerfectShape::Ellipse`, and `PerfectShape::
|
765
|
+
- `::new(shapes: [], closed: false, winding_rule: :wind_even_odd, line_to_complex_shapes: false)`: constructs a path with `shapes` as `Array` of shape objects, which can be `PerfectShape::Point` (or `Array` of `[x, y]` coordinates), `PerfectShape::Line`, `PerfectShape::QuadraticBezierCurve`, `PerfectShape::CubicBezierCurve`, or complex shapes that decompose into the aforementioned basic path shapes, like `PerfectShape::Arc`, `PerfectShape::Ellipse`, `PerfectShape::Circle`, `PerfectShape::Rectangle`, and `PerfectShape::Square`. If a path is closed, its last point is automatically connected to its first point with a line segment. The winding rule can be `:wind_non_zero` (default) or `:wind_even_odd`. `line_to_complex_shapes` can be `true` or `false` (default), indicating whether to connect to complex shapes, meaning `Arc`, `Ellipse`, `Circle`, `Rectangle`, and `Square`, with a line, or otherwise move to their start point instead.
|
764
766
|
- `#shapes`: the shapes that the path is composed of (must always start with `PerfectShape::Point` or Array of `[x,y]` coordinates representing start point)
|
765
|
-
- `#basic_shapes`: the basic shapes that the path is composed of, meaning only `Point`, `Line`, `QuadraticBezierCurve`, and `CubicBezierCurve` shapes (decomposing complex shapes like `Arc`, `Ellipse`,
|
767
|
+
- `#basic_shapes`: the basic shapes that the path is composed of, meaning only `Point`, `Line`, `QuadraticBezierCurve`, and `CubicBezierCurve` shapes (decomposing complex shapes like `Arc`, `Ellipse`, `Circle`, `Rectangle`, and `Square`, using their `#to_path_shapes` method)
|
766
768
|
- `#closed?`: returns `true` if closed and `false` otherwise
|
767
769
|
- `#winding_rule`: returns winding rule (`:wind_non_zero` or `:wind_even_odd`)
|
768
770
|
- `#points`: path points calculated (derived) from shapes
|
@@ -813,7 +815,7 @@ Class
|
|
813
815
|
|
814
816
|
Extends `PerfectShape::Shape`
|
815
817
|
|
816
|
-
A composite shape is simply an aggregate of multiple shapes (e.g. square and polygon)
|
818
|
+
A composite shape is simply an aggregate of multiple shapes (e.g. square and triangle polygon)
|
817
819
|
|
818
820
|
![composite shape](https://raw.githubusercontent.com/AndyObtiva/perfect-shape/master/images/composite-shape.png)
|
819
821
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0.
|
1
|
+
1.0.3
|
data/lib/perfect_shape/arc.rb
CHANGED
@@ -348,7 +348,6 @@ module PerfectShape
|
|
348
348
|
arc_segs = line_segs = -1 if w < 0 || h < 0
|
349
349
|
|
350
350
|
first_point_x = first_point_y = nil
|
351
|
-
last_point_x = last_point_y = nil
|
352
351
|
(arc_segs + line_segs + 1).to_i.times.map do |index|
|
353
352
|
coords = []
|
354
353
|
angle = ang_st_rad
|
@@ -365,10 +364,6 @@ module PerfectShape
|
|
365
364
|
elsif index > arc_segs
|
366
365
|
coords[0] = x
|
367
366
|
coords[1] = y
|
368
|
-
if line_segs == 2
|
369
|
-
last_point_x = coords[0]
|
370
|
-
last_point_y = coords[1]
|
371
|
-
end
|
372
367
|
Line.new(points: coords)
|
373
368
|
else
|
374
369
|
angle += increment * (index - 1)
|
@@ -383,10 +378,6 @@ module PerfectShape
|
|
383
378
|
coords[3] = y + (rely - cv * relx) * h
|
384
379
|
coords[4] = x + relx * w
|
385
380
|
coords[5] = y + rely * h
|
386
|
-
if line_segs == 1
|
387
|
-
last_point_x = coords[4]
|
388
|
-
last_point_y = coords[5]
|
389
|
-
end
|
390
381
|
CubicBezierCurve.new(points: coords)
|
391
382
|
end
|
392
383
|
end.compact
|
@@ -116,5 +116,43 @@ module PerfectShape
|
|
116
116
|
x < (x0 + self.width) &&
|
117
117
|
y < (y0 + self.height)
|
118
118
|
end
|
119
|
+
|
120
|
+
# Converts Rectangle into basic Path shapes made up of Points and Lines
|
121
|
+
# Used by Path when adding a Rectangle to Path shapes
|
122
|
+
def to_path_shapes
|
123
|
+
path_shapes = []
|
124
|
+
x = self.x
|
125
|
+
y = self.y
|
126
|
+
w = self.width
|
127
|
+
h = self.height
|
128
|
+
index = 0
|
129
|
+
index = 5 if (w < 0 || h < 0)
|
130
|
+
max_index = 4
|
131
|
+
max_index = 2 if (w == 0 && h > 0) || (w > 0 && h == 0)
|
132
|
+
max_index = 1 if (w == 0 && h == 0)
|
133
|
+
first_point_x = first_point_y = nil
|
134
|
+
|
135
|
+
until index > max_index
|
136
|
+
if index == max_index
|
137
|
+
path_shapes << Line.new(points: [[first_point_x, first_point_y]])
|
138
|
+
else
|
139
|
+
coords = []
|
140
|
+
coords[0] = x
|
141
|
+
coords[1] = y
|
142
|
+
coords[0] += w if ([2, 4].include?(max_index) && index == 1) || (max_index == 4 && index == 2)
|
143
|
+
coords[1] += h if (max_index == 2 && index == 1) || (max_index == 4 && [2, 3].include?(index))
|
144
|
+
if index == 0
|
145
|
+
first_point_x = coords[0]
|
146
|
+
first_point_y = coords[1]
|
147
|
+
path_shapes << Point.new(coords)
|
148
|
+
else
|
149
|
+
path_shapes << Line.new(points: coords)
|
150
|
+
end
|
151
|
+
end
|
152
|
+
index += 1
|
153
|
+
end
|
154
|
+
|
155
|
+
path_shapes
|
156
|
+
end
|
119
157
|
end
|
120
158
|
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 1.0.
|
5
|
+
# stub: perfect-shape 1.0.3 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.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 = "2022-04-
|
14
|
+
s.date = "2022-04-26"
|
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 = [
|
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.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: 2022-04-
|
11
|
+
date: 2022-04-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: equalizer
|