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 +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +29 -12
- data/VERSION +1 -1
- data/lib/perfect_shape/composite_shape.rb +3 -2
- data/lib/perfect_shape/rectangle.rb +1 -0
- 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: ab1f48d0551ed07a6a2b5f2d51abba6c6596eef82e156e68df57489319104e4c
|
4
|
+
data.tar.gz: bb67e137bbf23df2ed291a574ef45ae97113dd140d0a17269c9b60c27b7261e9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
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.
|
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.
|
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?(
|
704
|
-
shape.contain?([
|
705
|
-
shape.contain?(
|
706
|
-
shape.contain?([
|
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,
|
754
|
-
shape.contain?([170,
|
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.
|
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
|
-
|
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
|
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.3.
|
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.
|
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]
|