perfect-shape 0.3.4 → 0.3.5

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: 4dc25ad218f1860bfff0fccc88b81ea4b6ef71795c737b740b998385f4c7bf7d
4
- data.tar.gz: 31b52e8b765db80edde7ede8487f579a5de33b51fa1939bc1601dbad093741b1
3
+ metadata.gz: ab1f48d0551ed07a6a2b5f2d51abba6c6596eef82e156e68df57489319104e4c
4
+ data.tar.gz: bb67e137bbf23df2ed291a574ef45ae97113dd140d0a17269c9b60c27b7261e9
5
5
  SHA512:
6
- metadata.gz: 949d9a223e08cf4b9154f63f575908707c257620e18fdcd4a2820855c305400f418038b5ec53b56c4a4baea7c38065df8da71158dc29c76a5a19a809bf38da33
7
- data.tar.gz: '049d0fb36f1b633ebb20cf9fae4731688a19197a4bcbf29cbf55a7f837a5e4a9916b9b3a396a2f859387d3f80fcc7d8ebb9c6a23757dc3b389b0c70e79c7b845'
6
+ metadata.gz: 6d365e47635c7daa094f02849df24696784b667c55bffa479bdbaacc41abf1b9ad1114084a4ed7bd0145e6dd18ad233f9b09e6bad8792828417aca49db2076c4
7
+ data.tar.gz: d8440bb0d35e1539dcf5c8cad79e2930d74e10e32a408391085027d773c0ea7e4272a6011a7244677c035c8f6a7954606065611282ae8cd14aab71cbbe6b2bba
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Change Log
2
2
 
3
+ ## 0.3.5
4
+
5
+ - Check point containment in composite shape outline with distance tolerance (new method signature: `PerfectShape::CompositeShape#contain?(x_or_point, y = nil, outline: false, distance_tolerance: 0)`)
6
+
3
7
  ## 0.3.4
4
8
 
5
9
  - Check point containment in path outline with distance tolerance (new method signature: `PerfectShape::Path#contain?(x_or_point, y = nil, outline: false, distance_tolerance: 0)`)
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Perfect Shape 0.3.4
1
+ # Perfect Shape 0.3.5
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.3.4
17
+ gem install perfect-shape -v 0.3.5
18
18
  ```
19
19
 
20
20
  Or include in Bundler `Gemfile`:
21
21
 
22
22
  ```ruby
23
- gem 'perfect-shape', '~> 0.3.4'
23
+ gem 'perfect-shape', '~> 0.3.5'
24
24
  ```
25
25
 
26
26
  And, run:
@@ -700,10 +700,10 @@ path_shapes << PerfectShape::CubicBezierCurve.new(points: [[370, 50], [430, 220]
700
700
 
701
701
  shape = PerfectShape::Path.new(shapes: path_shapes, closed: false, winding_rule: :wind_even_odd)
702
702
 
703
- shape.contain?(225, 160) # => true
704
- shape.contain?([225, 160]) # => true
705
- shape.contain?(225, 160, outline: true) # => false
706
- shape.contain?([225, 160], outline: true) # => false
703
+ shape.contain?(275, 165) # => true
704
+ shape.contain?([275, 165]) # => true
705
+ shape.contain?(275, 165, outline: true) # => false
706
+ shape.contain?([275, 165], outline: true) # => false
707
707
  shape.contain?(shape.disconnected_shapes[1].curve_center_x, shape.disconnected_shapes[1].curve_center_y, outline: true) # => true
708
708
  shape.contain?([shape.disconnected_shapes[1].curve_center_x, shape.disconnected_shapes[1].curve_center_y], outline: true) # => true
709
709
  shape.contain?(shape.disconnected_shapes[1].curve_center_x + 1, shape.disconnected_shapes[1].curve_center_y, outline: true) # => false
@@ -735,7 +735,7 @@ A composite shape is simply an aggregate of multiple shapes (e.g. square and pol
735
735
  - `#center_y`: center y
736
736
  - `#bounding_box`: bounding box is a rectangle with x = min x, y = min y, and width/height of shape (bounding box only guarantees that the shape is within it, but it might be bigger than the shape)
737
737
  - `#==(other)`: Returns `true` if equal to `other` or `false` otherwise
738
- - `#contain?(x_or_point, y=nil)`: checks if point is inside any of the shapes owned by the composite shape
738
+ - `#contain?(x_or_point, y=nil)`: When `outline` is `false`, it checks if point is inside any of the shapes owned by the composite shape. Otherwise, when `outline` is `true`, it checks if point is on the outline of any of the shapes owned by the composite shape. `distance_tolerance` can be used as a fuzz factor when `outline` is `true`, for example, to help GUI users mouse-click-select a composite shape from its outline more successfully
739
739
 
740
740
  Example:
741
741
 
@@ -748,10 +748,27 @@ shapes << PerfectShape::Polygon.new(points: [[120, 215], [170, 165], [220, 215]]
748
748
 
749
749
  shape = PerfectShape::CompositeShape.new(shapes: shapes)
750
750
 
751
- shape.contain?(170, 265) # => true
752
- shape.contain?([170, 265]) # => true
753
- shape.contain?(170, 190) # => true
754
- shape.contain?([170, 190]) # => true
751
+ shape.contain?(170, 265) # => true inside square
752
+ shape.contain?([170, 265]) # => true inside square
753
+ shape.contain?(170, 265, outline: true) # => false
754
+ shape.contain?([170, 265], outline: true) # => false
755
+ shape.contain?(170, 315, outline: true) # => true
756
+ shape.contain?([170, 315], outline: true) # => true
757
+ shape.contain?(170, 316, outline: true) # => false
758
+ shape.contain?([170, 316], outline: true) # => false
759
+ shape.contain?(170, 316, outline: true, distance_tolerance: 1) # => true
760
+ shape.contain?([170, 316], outline: true, distance_tolerance: 1) # => true
761
+
762
+ shape.contain?(170, 190) # => true inside polygon
763
+ shape.contain?([170, 190]) # => true inside polygon
764
+ shape.contain?(170, 190, outline: true) # => false
765
+ shape.contain?([170, 190], outline: true) # => false
766
+ shape.contain?(145, 190, outline: true) # => true
767
+ shape.contain?([145, 190], outline: true) # => true
768
+ shape.contain?(145, 189, outline: true) # => false
769
+ shape.contain?([145, 189], outline: true) # => false
770
+ shape.contain?(145, 189, outline: true, distance_tolerance: 1) # => true
771
+ shape.contain?([145, 189], outline: true, distance_tolerance: 1) # => true
755
772
  ```
756
773
 
757
774
  ## Process
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.4
1
+ 0.3.5
@@ -63,10 +63,11 @@ module PerfectShape
63
63
  # @return true if the point lies within the bound of
64
64
  # the composite shape or false if the point lies outside of the
65
65
  # path's bounds.
66
- def contain?(x_or_point, y = nil)
66
+ def contain?(x_or_point, y = nil, outline: false, distance_tolerance: 0)
67
67
  x, y = normalize_point(x_or_point, y)
68
68
  return unless x && y
69
- shapes.any? {|shape| shape.contain?(x, y) }
69
+
70
+ shapes.any? { |shape| shape.contain?(x, y, outline: outline, distance_tolerance: distance_tolerance) }
70
71
  end
71
72
  end
72
73
  end
@@ -40,6 +40,7 @@ module PerfectShape
40
40
  def contain?(x_or_point, y = nil, outline: false, distance_tolerance: 0)
41
41
  x, y = normalize_point(x_or_point, y)
42
42
  return unless x && y
43
+
43
44
  if outline
44
45
  edges.any? { |edge| edge.contain?(x, y, distance_tolerance: distance_tolerance) }
45
46
  else
@@ -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.3.4 ruby lib
5
+ # stub: perfect-shape 0.3.5 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "perfect-shape".freeze
9
- s.version = "0.3.4"
9
+ s.version = "0.3.5"
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]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: perfect-shape
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4
4
+ version: 0.3.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Maleh