perfect-shape 1.0.6 → 1.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7cd9bf6e78e556604f5a9ff5b26e7b952ca8c61424aac789238c2d5d8961b1c8
4
- data.tar.gz: a76a11a91632b22a3b3b136d55ded17ba17b10b940de7186c912bf5cb0642cc7
3
+ metadata.gz: 8ccdbd2ecf2cb7dea672b46aa23831ade4b09acfd37242edfc7fb8bb030c574c
4
+ data.tar.gz: 485341606037a3ac14527338c657afcfad977646318358d56aca2b07e72e498a
5
5
  SHA512:
6
- metadata.gz: 54ca03287c4efe1f2a88ab8ad9a3372c29313460f433be17e7300428ea34264d6fcfbd3bc54dedb3953959295a97669e89553fa450f04ab62e99779638501826
7
- data.tar.gz: 4c254bfaa37c9d4254ec2df488a0989a580c5907594b992be1d024d3ddda1f790b5340e3f9205214454f167400b9af182d4ad71cf913336203af411a13d220e6
6
+ metadata.gz: 9912d75a61a947eea2d993764ed5802d986eb1775169444c798be0e2a51061998a81a7a36c2329c6da0581c38ccbe0dd8aa94f78a771f97e961dc5abcadaca71
7
+ data.tar.gz: 458e6674b93e4f4eabdba4769927b10ef7292f54bcb6795768e4419e8ded479de5183a3f8a273b82cd7fd4aa388d937a60f31e8577dcff159d88cc102bfa6cba
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
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
+
3
9
  ## 1.0.6
4
10
 
5
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`
data/README.md CHANGED
@@ -1,8 +1,10 @@
1
- # Perfect Shape 1.0.6
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.6
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.6'
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
 
@@ -96,6 +99,7 @@ Module
96
99
  - `#min_y`: min y of all points
97
100
  - `#max_x`: max x of all points
98
101
  - `#max_y`: max y of all points
102
+ - `#first_point`: first point for shape including this module
99
103
 
100
104
  ### `PerfectShape::AffineTransform`
101
105
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.6
1
+ 1.0.7
@@ -55,6 +55,10 @@ module PerfectShape
55
55
  @points
56
56
  end
57
57
 
58
+ def first_point
59
+ points.first.to_a
60
+ end
61
+
58
62
  def min_x
59
63
  points.map(&:first).min
60
64
  end
@@ -64,14 +64,20 @@ module PerfectShape
64
64
 
65
65
  def points
66
66
  the_points = []
67
- basic_shapes.each do |shape|
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
- the_points << shape.points.last.to_a
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.to_a if closed?
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.map do |shape|
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
@@ -245,7 +251,8 @@ module PerfectShape
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
248
- initial_point = start_point = basic_shapes.first.to_a.map {|n| BigDecimal(n.to_s)}
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)}
249
256
  final_point = nil
250
257
  the_disconnected_shapes = basic_shapes.drop(1).map do |shape|
251
258
  case shape
@@ -389,9 +396,10 @@ module PerfectShape
389
396
  # decomposed from complex shapes like Arc, Ellipse, and Circle by calling their `#to_path_shapes` method
390
397
  def basic_shapes
391
398
  the_shapes = []
392
- @shapes.each do |shape|
399
+ @shapes.each_with_index do |shape, i|
393
400
  if shape.respond_to?(:to_path_shapes)
394
401
  shape_basic_shapes = shape.to_path_shapes
402
+ the_shapes << shape.first_point if i == 0
395
403
  if @line_to_complex_shapes
396
404
  first_basic_shape = shape_basic_shapes.shift
397
405
  new_first_basic_shape = PerfectShape::Line.new(points: [first_basic_shape.to_a])
@@ -31,6 +31,10 @@ module PerfectShape
31
31
  self.y = y
32
32
  end
33
33
 
34
+ def first_point
35
+ [x, y]
36
+ end
37
+
34
38
  # Sets x, normalizing to BigDecimal
35
39
  def x=(value)
36
40
  @x = BigDecimal(value.to_s)
@@ -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.6 ruby lib
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.6"
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-11-05"
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 = [
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.6
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-05 00:00:00.000000000 Z
11
+ date: 2022-11-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: matrix