perfect-shape 0.0.1 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,65 @@
1
+ # Copyright (c) 2021 Andy Maleh
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining
4
+ # a copy of this software and associated documentation files (the
5
+ # "Software"), to deal in the Software without restriction, including
6
+ # without limitation the rights to use, copy, modify, merge, publish,
7
+ # distribute, sublicense, and/or sell copies of the Software, and to
8
+ # permit persons to whom the Software is furnished to do so, subject to
9
+ # the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be
12
+ # included in all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ module PerfectShape
23
+ # Mixin Module for Rectangular Shapes (having x, y, width, height)
24
+ # Can only be mixed into a class extending Shape or another module
25
+ module RectangularShape
26
+ attr_reader :x, :y, :width, :height
27
+
28
+ # Calls super before setting x, y, width, height
29
+ def initialize(x: 0, y: 0, width: 1, height: 1)
30
+ super()
31
+ self.x = x
32
+ self.y = y
33
+ self.width = width
34
+ self.height = height
35
+ end
36
+
37
+ # Sets x, normalizing to BigDecimal
38
+ def x=(value)
39
+ @x = BigDecimal(value.to_s)
40
+ end
41
+
42
+ # Sets y, normalizing to BigDecimal
43
+ def y=(value)
44
+ @y = BigDecimal(value.to_s)
45
+ end
46
+
47
+ # Sets width, normalizing to BigDecimal
48
+ def width=(value)
49
+ @width = BigDecimal(value.to_s)
50
+ end
51
+
52
+ # Sets height, normalizing to BigDecimal
53
+ def height=(value)
54
+ @height = BigDecimal(value.to_s)
55
+ end
56
+
57
+ def center_x
58
+ @x + (@width/BigDecimal('2.0')) if @x && @width
59
+ end
60
+
61
+ def center_y
62
+ @y + (@height/BigDecimal('2.0')) if @y && @height
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,39 @@
1
+ # Copyright (c) 2021 Andy Maleh
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining
4
+ # a copy of this software and associated documentation files (the
5
+ # "Software"), to deal in the Software without restriction, including
6
+ # without limitation the rights to use, copy, modify, merge, publish,
7
+ # distribute, sublicense, and/or sell copies of the Software, and to
8
+ # permit persons to whom the Software is furnished to do so, subject to
9
+ # the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be
12
+ # included in all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ module PerfectShape
23
+ class Shape
24
+ # Normalizes point args whether two-number Array or x, y args returning
25
+ # normalized point array of two BigDecimal's
26
+ #
27
+ # @param x_or_point The point or X coordinate of the point to test.
28
+ # @param y The Y coordinate of the point to test.
29
+ #
30
+ # @return Array of x and y BigDecimal's representing point
31
+ def normalize_point(x_or_point, y = nil)
32
+ x = x_or_point
33
+ x, y = x if y.nil? && x_or_point.is_a?(Array) && x_or_point.size == 2
34
+ x = BigDecimal(x.to_s)
35
+ y = BigDecimal(y.to_s)
36
+ [x, y]
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,56 @@
1
+ # Copyright (c) 2021 Andy Maleh
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining
4
+ # a copy of this software and associated documentation files (the
5
+ # "Software"), to deal in the Software without restriction, including
6
+ # without limitation the rights to use, copy, modify, merge, publish,
7
+ # distribute, sublicense, and/or sell copies of the Software, and to
8
+ # permit persons to whom the Software is furnished to do so, subject to
9
+ # the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be
12
+ # included in all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ require 'perfect_shape/rectangle'
23
+
24
+ module PerfectShape
25
+ class Square < Rectangle
26
+ MESSAGE_WIDTH_AND_HEIGHT_AND_LENGTH_NOT_EQUAL = 'Square width, height, and length must all be equal if more than one is specified; or otherwise keep only one of them in arguments!'
27
+
28
+ attr_reader :length
29
+
30
+ # Constructs with x, y, length (optionally width or height can be passed as alias for length)
31
+ def initialize(x: 0, y: 0, length: nil, width: nil, height: nil)
32
+ raise MESSAGE_WIDTH_AND_HEIGHT_AND_LENGTH_NOT_EQUAL if (length && width && length != width) || (length && height && length != height) || (width && height && width != height)
33
+ length ||= width || height || 1
34
+ super(x: x, y: y, width: length, height: length)
35
+ end
36
+
37
+ # Sets length, normalizing to BigDecimal
38
+ def length=(value)
39
+ @length = BigDecimal(value.to_s)
40
+ self.width = value unless width == value
41
+ self.height = value unless height == value
42
+ end
43
+
44
+ def width=(value)
45
+ super
46
+ self.length = value unless length == value
47
+ self.height = value unless height == value
48
+ end
49
+
50
+ def height=(value)
51
+ super
52
+ self.length = value unless length == value
53
+ self.width = value unless width == value
54
+ end
55
+ end
56
+ end
@@ -2,17 +2,17 @@
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.0.1 ruby lib
5
+ # stub: perfect-shape 0.0.5 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "perfect-shape".freeze
9
- s.version = "0.0.1"
9
+ s.version = "0.0.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]
13
13
  s.authors = ["Andy Maleh".freeze]
14
- s.date = "2021-12-06"
15
- s.description = "Perfect Shape is a collection of pure Ruby geometric algorithms that are mostly useful for GUI manipulation like checking containment of a point in popular geometric shapes such as rectangle, square, arc, circle, polygon, polyline, and paths containing lines, bezier curves, and quadratic curves. Additionally, it contains some purely mathematical algorithms like IEEEremainder (also known as IEEE-754 remainder).".freeze
14
+ s.date = "2021-12-15"
15
+ s.description = "Perfect Shape is a collection of pure Ruby geometric algorithms that are mostly useful for GUI manipulation like checking containment of a mouse click point in popular geometry shapes such as rectangle, square, arc (open, chord, and pie), ellipse, circle, polygon, polyline, polyquad, polycubic, and paths containing lines, bezier curves, and quadratic curves. 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 = [
18
18
  "CHANGELOG.md",
@@ -20,24 +20,20 @@ Gem::Specification.new do |s|
20
20
  "README.md"
21
21
  ]
22
22
  s.files = [
23
- ".document",
24
- ".ruby-gemset",
25
- ".ruby-version",
26
23
  "CHANGELOG.md",
27
- "Gemfile",
28
- "Gemfile.lock",
29
24
  "LICENSE.txt",
30
25
  "README.md",
31
- "Rakefile",
32
- "TODO.md",
33
26
  "VERSION",
34
27
  "lib/perfect-shape.rb",
35
28
  "lib/perfect_shape/arc.rb",
29
+ "lib/perfect_shape/ellipse.rb",
36
30
  "lib/perfect_shape/line.rb",
37
31
  "lib/perfect_shape/math.rb",
38
- "perfect-shape.gemspec",
39
- "test/lib/perfect_shape/test_arc.rb",
40
- "test/lib/perfect_shape/test_math.rb"
32
+ "lib/perfect_shape/rectangle.rb",
33
+ "lib/perfect_shape/rectangular_shape.rb",
34
+ "lib/perfect_shape/shape.rb",
35
+ "lib/perfect_shape/square.rb",
36
+ "perfect-shape.gemspec"
41
37
  ]
42
38
  s.homepage = "http://github.com/AndyObtiva/perfect-shape".freeze
43
39
  s.licenses = ["MIT".freeze]
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: 0.0.1
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Maleh
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-12-06 00:00:00.000000000 Z
11
+ date: 2021-12-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rdoc
@@ -81,10 +81,11 @@ dependencies:
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  description: Perfect Shape is a collection of pure Ruby geometric algorithms that
84
- are mostly useful for GUI manipulation like checking containment of a point in popular
85
- geometric shapes such as rectangle, square, arc, circle, polygon, polyline, and
86
- paths containing lines, bezier curves, and quadratic curves. Additionally, it contains
87
- some purely mathematical algorithms like IEEEremainder (also known as IEEE-754 remainder).
84
+ are mostly useful for GUI manipulation like checking containment of a mouse click
85
+ point in popular geometry shapes such as rectangle, square, arc (open, chord, and
86
+ pie), ellipse, circle, polygon, polyline, polyquad, polycubic, and paths containing
87
+ lines, bezier curves, and quadratic curves. Additionally, it contains some purely
88
+ mathematical algorithms like IEEEremainder (also known as IEEE-754 remainder).
88
89
  email: andy.am@gmail.com
89
90
  executables: []
90
91
  extensions: []
@@ -93,24 +94,20 @@ extra_rdoc_files:
93
94
  - LICENSE.txt
94
95
  - README.md
95
96
  files:
96
- - ".document"
97
- - ".ruby-gemset"
98
- - ".ruby-version"
99
97
  - CHANGELOG.md
100
- - Gemfile
101
- - Gemfile.lock
102
98
  - LICENSE.txt
103
99
  - README.md
104
- - Rakefile
105
- - TODO.md
106
100
  - VERSION
107
101
  - lib/perfect-shape.rb
108
102
  - lib/perfect_shape/arc.rb
103
+ - lib/perfect_shape/ellipse.rb
109
104
  - lib/perfect_shape/line.rb
110
105
  - lib/perfect_shape/math.rb
106
+ - lib/perfect_shape/rectangle.rb
107
+ - lib/perfect_shape/rectangular_shape.rb
108
+ - lib/perfect_shape/shape.rb
109
+ - lib/perfect_shape/square.rb
111
110
  - perfect-shape.gemspec
112
- - test/lib/perfect_shape/test_arc.rb
113
- - test/lib/perfect_shape/test_math.rb
114
111
  homepage: http://github.com/AndyObtiva/perfect-shape
115
112
  licenses:
116
113
  - MIT
data/.document DELETED
@@ -1,5 +0,0 @@
1
- lib/**/*.rb
2
- bin/*
3
- -
4
- features/**/*.feature
5
- LICENSE.txt
data/.ruby-gemset DELETED
@@ -1 +0,0 @@
1
- perfect-shape
data/.ruby-version DELETED
@@ -1 +0,0 @@
1
- ruby-3.0.2
data/Gemfile DELETED
@@ -1,14 +0,0 @@
1
- source "https://rubygems.org"
2
- # Add dependencies required to use your gem here.
3
- # Example:
4
- # gem "activesupport", ">= 2.3.5"
5
-
6
- # Add dependencies to develop your gem here.
7
- # Include everything needed to run rake, tests, features, etc.
8
- group :development do
9
- gem "rdoc", "~> 3.12"
10
- gem "juwelier", "~> 2.1.0"
11
- gem 'minitest', '~> 5.14.4'
12
- gem 'puts_debuggerer', '~> 0.13.1'
13
- gem 'rake-tui', '> 0'
14
- end
data/Gemfile.lock DELETED
@@ -1,102 +0,0 @@
1
- GEM
2
- remote: https://rubygems.org/
3
- specs:
4
- addressable (2.8.0)
5
- public_suffix (>= 2.0.2, < 5.0)
6
- awesome_print (1.9.2)
7
- builder (3.2.4)
8
- descendants_tracker (0.0.4)
9
- thread_safe (~> 0.3, >= 0.3.1)
10
- faraday (1.8.0)
11
- faraday-em_http (~> 1.0)
12
- faraday-em_synchrony (~> 1.0)
13
- faraday-excon (~> 1.1)
14
- faraday-httpclient (~> 1.0.1)
15
- faraday-net_http (~> 1.0)
16
- faraday-net_http_persistent (~> 1.1)
17
- faraday-patron (~> 1.0)
18
- faraday-rack (~> 1.0)
19
- multipart-post (>= 1.2, < 3)
20
- ruby2_keywords (>= 0.0.4)
21
- faraday-em_http (1.0.0)
22
- faraday-em_synchrony (1.0.0)
23
- faraday-excon (1.1.0)
24
- faraday-httpclient (1.0.1)
25
- faraday-net_http (1.0.1)
26
- faraday-net_http_persistent (1.2.0)
27
- faraday-patron (1.0.0)
28
- faraday-rack (1.0.0)
29
- git (1.9.1)
30
- rchardet (~> 1.8)
31
- github_api (0.19.0)
32
- addressable (~> 2.4)
33
- descendants_tracker (~> 0.0.4)
34
- faraday (>= 0.8, < 2)
35
- hashie (~> 3.5, >= 3.5.2)
36
- oauth2 (~> 1.0)
37
- hashie (3.6.0)
38
- highline (2.0.3)
39
- json (1.8.6)
40
- juwelier (2.1.3)
41
- builder
42
- bundler (>= 1.13)
43
- git (>= 1.2.5)
44
- github_api
45
- highline (>= 1.6.15)
46
- nokogiri (>= 1.5.10)
47
- rake
48
- rdoc
49
- semver
50
- jwt (2.3.0)
51
- minitest (5.14.4)
52
- multi_json (1.15.0)
53
- multi_xml (0.6.0)
54
- multipart-post (2.1.1)
55
- nokogiri (1.12.5-x86_64-darwin)
56
- racc (~> 1.4)
57
- oauth2 (1.4.7)
58
- faraday (>= 0.8, < 2.0)
59
- jwt (>= 1.0, < 3.0)
60
- multi_json (~> 1.3)
61
- multi_xml (~> 0.5)
62
- rack (>= 1.2, < 3)
63
- pastel (0.8.0)
64
- tty-color (~> 0.5)
65
- public_suffix (4.0.6)
66
- puts_debuggerer (0.13.1)
67
- awesome_print (~> 1.9.2)
68
- racc (1.6.0)
69
- rack (2.2.3)
70
- rake (13.0.6)
71
- rake-tui (0.2.3)
72
- tty-prompt
73
- rchardet (1.8.0)
74
- rdoc (3.12.2)
75
- json (~> 1.4)
76
- ruby2_keywords (0.0.5)
77
- semver (1.0.1)
78
- thread_safe (0.3.6)
79
- tty-color (0.6.0)
80
- tty-cursor (0.7.1)
81
- tty-prompt (0.23.1)
82
- pastel (~> 0.8)
83
- tty-reader (~> 0.8)
84
- tty-reader (0.9.0)
85
- tty-cursor (~> 0.7)
86
- tty-screen (~> 0.8)
87
- wisper (~> 2.0)
88
- tty-screen (0.8.1)
89
- wisper (2.0.1)
90
-
91
- PLATFORMS
92
- x86_64-darwin-19
93
-
94
- DEPENDENCIES
95
- juwelier (~> 2.1.0)
96
- minitest (~> 5.14.4)
97
- puts_debuggerer (~> 0.13.1)
98
- rake-tui (> 0)
99
- rdoc (~> 3.12)
100
-
101
- BUNDLED WITH
102
- 2.2.31
data/Rakefile DELETED
@@ -1,46 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'rubygems'
4
- require 'bundler'
5
- begin
6
- Bundler.setup(:default, :development)
7
- rescue Bundler::BundlerError => e
8
- $stderr.puts e.message
9
- $stderr.puts "Run `bundle install` to install missing gems"
10
- exit e.status_code
11
- end
12
- require 'rake'
13
- require 'juwelier'
14
- Juwelier::Tasks.new do |gem|
15
- # gem is a Gem::Specification... see http://guides.rubygems.org/specification-reference/ for more options
16
- gem.name = "perfect-shape"
17
- gem.homepage = "http://github.com/AndyObtiva/perfect-shape"
18
- gem.license = "MIT"
19
- gem.summary = %Q{Perfect Shape - Geometric Algorithms}
20
- gem.description = %Q{Perfect Shape is a collection of pure Ruby geometric algorithms that are mostly useful for GUI manipulation like checking containment of a point in popular geometric shapes such as rectangle, square, arc, circle, polygon, polyline, and paths containing lines, bezier curves, and quadratic curves. Additionally, it contains some purely mathematical algorithms like IEEEremainder (also known as IEEE-754 remainder).}
21
- gem.email = "andy.am@gmail.com"
22
- gem.authors = ["Andy Maleh"]
23
-
24
- # dependencies defined in Gemfile
25
- end
26
- Juwelier::RubygemsDotOrgTasks.new
27
-
28
- require "rake/testtask"
29
-
30
- Rake::TestTask.new(:test) do |t|
31
- t.libs << "test"
32
- t.libs << "lib"
33
- t.test_files = FileList["test/**/test_*.rb"]
34
- end
35
-
36
- task :default => :test
37
-
38
- require 'rdoc/task'
39
- Rake::RDocTask.new do |rdoc|
40
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
41
-
42
- rdoc.rdoc_dir = 'rdoc'
43
- rdoc.title = "perfect-shape #{version}"
44
- rdoc.rdoc_files.include('README*')
45
- rdoc.rdoc_files.include('lib/**/*.rb')
46
- end
data/TODO.md DELETED
@@ -1,31 +0,0 @@
1
- # TODO
2
-
3
- ## Geometry
4
-
5
- Mostly inspired by java.awt.geom: https://docs.oracle.com/javase/8/docs/api/java/awt/geom/package-summary.html
6
-
7
- - Polygon
8
- - CubicCurve
9
- - QuadCurve
10
- - Line
11
- - Path: flexible shape which represents an arbitrary geometric path
12
- - GeneralPath: represents a geometric path constructed from straight lines, and quadratic and cubic (Bézier) curves. It can contain multiple subpaths.
13
- - Rectangle
14
- - RoundRectangle
15
- - Point
16
- - Ellipse
17
- - Polybezier
18
- - Polyline
19
- - Area: aggregate of multiple shapes
20
- - AffineTransform: represents a 2D affine transform that performs a linear mapping from 2D coordinates to other 2D coordinates that preserves the "straightness" and "parallelness" of lines.
21
-
22
- ## Miscellaneous
23
-
24
- - Include screenshots of the supported shapes in README
25
-
26
- ## Maybe
27
-
28
- - Consider the idea of having tests run in JRuby and check against java.awt.geom and compare result with perfect-shape
29
- - Consider contributing IEEEremainder to Ruby
30
- - Contribute this type of expectation: _(arc).must_be :contain?, *point to Minitest Expectations
31
- - Maybe contribute xit to minitest expectations
@@ -1,184 +0,0 @@
1
- require 'puts_debuggerer'
2
- require 'minitest/autorun'
3
-
4
- require_relative '../../../lib/perfect-shape'
5
-
6
- describe PerfectShape do
7
- describe PerfectShape::Arc do
8
- it 'constructs with chord type and dimensions' do
9
- arc = PerfectShape::Arc.new(type: :chord, x: 2, y: 3, width: 50, height: 60, start: 30, extent: 90)
10
-
11
- _(arc.type).must_equal :chord
12
- _(arc.y).must_equal 3
13
- _(arc.y).must_equal 3
14
- _(arc.width).must_equal 50
15
- _(arc.height).must_equal 60
16
- _(arc.start).must_equal 30
17
- _(arc.extent).must_equal 90
18
- end
19
-
20
- it 'constructs with open type defaults' do
21
- arc = PerfectShape::Arc.new
22
-
23
- _(arc.type).must_equal :open
24
- _(arc.x).must_equal 0
25
- _(arc.y).must_equal 0
26
- _(arc.width).must_equal 1
27
- _(arc.height).must_equal 1
28
- _(arc.start).must_equal 0
29
- _(arc.extent).must_equal 360
30
- end
31
-
32
- it 'updates attributes' do
33
- arc = PerfectShape::Arc.new
34
- arc.type = :chord
35
- arc.x = 2
36
- arc.y = 3
37
- arc.width = 50
38
- arc.height = 60
39
- arc.start = 30
40
- arc.extent = 90
41
-
42
- _(arc.type).must_equal :chord
43
- _(arc.y).must_equal 3
44
- _(arc.y).must_equal 3
45
- _(arc.width).must_equal 50
46
- _(arc.height).must_equal 60
47
- _(arc.start).must_equal 30
48
- _(arc.extent).must_equal 90
49
- end
50
-
51
- it 'contains point with chord type circle' do
52
- arc = PerfectShape::Arc.new(type: :chord, x: 2, y: 3, width: 50.5, height: 60.75, start: 0, extent: 360)
53
- point = [arc.x + arc.width / 2.0, arc.y + arc.height / 2.0]
54
-
55
- _(arc).must_be :contain?, point
56
- _(arc.contain?(point)).must_equal arc.contain?(*point)
57
- end
58
-
59
- it 'contains point with chord type arc' do
60
- arc = PerfectShape::Arc.new(type: :chord, x: 2, y: 3, width: 50.5, height: 60.75, start: 45, extent: 270)
61
- point = [arc.x + arc.width*3/4.0, arc.y + (arc.height / 2.0)]
62
-
63
- _(arc).must_be :contain?, point
64
- _(arc.contain?(point)).must_equal arc.contain?(*point)
65
- end
66
-
67
- it 'does not contain point within bounding box with chord type arc' do
68
- arc = PerfectShape::Arc.new(type: :chord, x: 2, y: 3, width: 67, height: 46, start: 45, extent: 270)
69
- point = [arc.x + arc.width*(3.9/4.0), arc.y + (arc.height / 2.0)]
70
-
71
- _(arc.contain?(point)).must_equal false
72
- end
73
-
74
- it 'does not contain point in center of chord type arc' do
75
- arc = PerfectShape::Arc.new(type: :chord, x: 2, y: 3, width: 50.5, height: 60.75, start: 0, extent: 145)
76
- point = [arc.x + arc.width / 2.0, arc.y + arc.height / 2.0]
77
-
78
- _(arc.contain?(point)).must_equal false
79
- end
80
-
81
- it 'does not contain point within bounding box with chord type circle' do
82
- arc = PerfectShape::Arc.new(type: :chord, x: 2, y: 3, width: 50.5, height: 60.75, start: 0, extent: 360)
83
- point = [3.0, 4.0]
84
-
85
- _(arc.contain?(point)).must_equal false
86
- end
87
-
88
- it 'does not contain point outside bounding box with chord type circle' do
89
- arc = PerfectShape::Arc.new(type: :chord, x: 2, y: 3, width: 50.5, height: 60.75, start: 0, extent: 360)
90
- point = [1.0, 2.0]
91
-
92
- _(arc.contain?(point)).must_equal false
93
- end
94
-
95
- it 'contains point with open type circle' do
96
- arc = PerfectShape::Arc.new(type: :open, x: 2, y: 3, width: 50.5, height: 60.75, start: 0, extent: 360)
97
- point = [arc.x + arc.width / 2.0, arc.y + arc.height / 2.0]
98
-
99
- _(arc).must_be :contain?, point
100
- _(arc.contain?(point)).must_equal arc.contain?(*point)
101
- end
102
-
103
- it 'contains point with open type arc' do
104
- arc = PerfectShape::Arc.new(type: :open, x: 2, y: 3, width: 50.5, height: 60.75, start: 45, extent: 270)
105
- point = [arc.x + arc.width*3/4.0, arc.y + (arc.height / 2.0)]
106
-
107
- _(arc).must_be :contain?, point
108
- _(arc.contain?(point)).must_equal arc.contain?(*point)
109
- end
110
-
111
- it 'does not contain point within bounding box with open type arc' do
112
- arc = PerfectShape::Arc.new(type: :open, x: 2, y: 3, width: 67, height: 46, start: 45, extent: 270)
113
- point = [arc.x + arc.width*(3.9/4.0), arc.y + (arc.height / 2.0)]
114
-
115
- _(arc.contain?(point)).must_equal false
116
- end
117
-
118
- it 'does not contain point in center of open type arc' do
119
- arc = PerfectShape::Arc.new(type: :open, x: 2, y: 3, width: 50.5, height: 60.75, start: 0, extent: 145)
120
- point = [arc.x + arc.width / 2.0, arc.y + arc.height / 2.0]
121
-
122
- _(arc.contain?(point)).must_equal false
123
- end
124
-
125
- it 'does not contain point within bounding box with open type circle' do
126
- arc = PerfectShape::Arc.new(type: :open, x: 2, y: 3, width: 50.5, height: 60.75, start: 0, extent: 360)
127
- point = [3.0, 4.0]
128
-
129
- _(arc.contain?(point)).must_equal false
130
- end
131
-
132
- it 'does not contain point outside bounding box with open type circle' do
133
- arc = PerfectShape::Arc.new(type: :open, x: 2, y: 3, width: 50.5, height: 60.75, start: 0, extent: 360)
134
- point = [1.0, 2.0]
135
-
136
- _(arc.contain?(point)).must_equal false
137
- end
138
-
139
- it 'contains point with pie type circle' do
140
- arc = PerfectShape::Arc.new(type: :pie, x: 2, y: 3, width: 50.5, height: 60.75, start: 0, extent: 360)
141
- point = [arc.x + arc.width / 2.0, arc.y + arc.height / 2.0]
142
-
143
- _(arc).must_be :contain?, point
144
- _(arc.contain?(point)).must_equal arc.contain?(*point)
145
- end
146
-
147
- it 'contains point in center of pie type arc' do
148
- arc = PerfectShape::Arc.new(type: :pie, x: 2, y: 3, width: 50.5, height: 60.75, start: 0, extent: 145)
149
- point = [arc.x + arc.width / 2.0, arc.y + arc.height / 2.0]
150
-
151
- _(arc).must_be :contain?, point
152
- _(arc.contain?(point)).must_equal arc.contain?(*point)
153
- end
154
-
155
- it 'contains point with pie type arc' do
156
- arc = PerfectShape::Arc.new(type: :pie, x: 2, y: 3, width: 50.5, height: 60.75, start: 0, extent: 145)
157
- point = [arc.x + arc.width / 2.0 + (arc.width / 4.0), arc.y + (arc.height / 2.0) - (arc.height / 4.0)]
158
-
159
- _(arc).must_be :contain?, point
160
- _(arc.contain?(point)).must_equal arc.contain?(*point)
161
- end
162
-
163
- it 'does not contain point within bounding box with pie type arc' do
164
- arc = PerfectShape::Arc.new(type: :pie, x: 2, y: 3, width: 50.5, height: 60.75, start: 0, extent: 145)
165
- point = [arc.x + (arc.width / 2.0) - (arc.width / 4.0), arc.y + arc.height / 2.0]
166
-
167
- _(arc.contain?(point)).must_equal false
168
- end
169
-
170
- it 'does not contain point within bounding box with pie type circle' do
171
- arc = PerfectShape::Arc.new(type: :pie, x: 2, y: 3, width: 50.5, height: 60.75, start: 0, extent: 360)
172
- point = [3.0, 4.0]
173
-
174
- _(arc.contain?(point)).must_equal false
175
- end
176
-
177
- it 'does not contain point outside bounding box with pie type circle' do
178
- arc = PerfectShape::Arc.new(type: :pie, x: 2, y: 3, width: 50.5, height: 60.75, start: 0, extent: 360)
179
- point = [1.0, 2.0]
180
-
181
- _(arc.contain?(point)).must_equal false
182
- end
183
- end
184
- end