ruby-geometry 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -0
- data/README.md +27 -27
- data/lib/geometry.rb +8 -8
- data/lib/{algorithms → geometry/algorithms}/point_in_polygon.rb +1 -1
- data/lib/{bounding_box.rb → geometry/bounding_box.rb} +0 -0
- data/lib/{comparison_with_precision.rb → geometry/comparison_with_precision.rb} +0 -0
- data/lib/{line.rb → geometry/line.rb} +4 -0
- data/lib/{point.rb → geometry/point.rb} +4 -0
- data/lib/{polygon.rb → geometry/polygon.rb} +0 -0
- data/lib/{segment.rb → geometry/segment.rb} +2 -0
- data/lib/{vector.rb → geometry/vector.rb} +0 -0
- data/ruby-geometry.gemspec +1 -1
- data/test/line/length_test.rb +16 -0
- data/test/point/distance_to_test.rb +43 -0
- data/test/segment/distance_to_test.rb +7 -1
- metadata +30 -25
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f47c93644dd21704742df40e87355eb35ebb61a9
|
4
|
+
data.tar.gz: 6d9b2f81291fd61de1d3d5cdc110fde153681065
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a9eebbfbd51ceb989571d5506f43e0f50bc37a2fe1788e4d8af093eca4603cf40f255a86677b4b76c20a5949fda8aa958111b9b9a40c9d2ad5548e2362db0d6d
|
7
|
+
data.tar.gz: 1bb0cea637ba52b1dd40dbaea8484af7050684bc979d04c49285d5e5004cd341dc23d6613bfed00c88eb2b4c56cbe5c755fe8e174893d7a15efc95b002541cfc
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
Changelog
|
2
|
+
=========
|
3
|
+
|
4
|
+
### 0.5.0
|
5
|
+
|
6
|
+
* Added `Line#distance_to(point)`, `Segment#distance_to(point)`
|
7
|
+
* Added `Polygon#area`
|
8
|
+
* Added `Point.advance_by(vector)`
|
9
|
+
* Switched to Ruby 2.0 as a default Ruby version to support
|
10
|
+
* Switched from obsolete Test::Unit to Minitest
|
data/README.md
CHANGED
@@ -28,47 +28,51 @@ Defined geometry objects
|
|
28
28
|
Already implemented algorithms
|
29
29
|
==============================
|
30
30
|
|
31
|
-
*
|
31
|
+
* Area of convex polygon `Polygon#area`
|
32
32
|
|
33
|
-
*
|
33
|
+
* Distance from point to a line or segment `Line#distance_to(point)`, `Segment#distance_to(point)`
|
34
34
|
|
35
|
-
* Do segments
|
35
|
+
* Do segments overlap? `Segments#overlaps?`
|
36
36
|
|
37
|
-
*
|
37
|
+
* Do segments lie on one line? `Segment#lies_on_one_line_with?`
|
38
38
|
|
39
|
-
*
|
39
|
+
* Do segments intersect? `Segment#intersects_with?`
|
40
40
|
|
41
|
-
*
|
41
|
+
* Segments intersection point `Segment#intersection_point_with`
|
42
42
|
|
43
|
-
*
|
43
|
+
* Does segment contain given point? `Segment#contains_point?`
|
44
44
|
|
45
|
-
*
|
45
|
+
* Are segments parallel? `Segment#parallel_to?`
|
46
46
|
|
47
|
-
*
|
47
|
+
* Are vectors collinear? `Vector#collinear_with?`
|
48
48
|
|
49
|
-
*
|
49
|
+
* Vectors cross product (outer product, vector product) `Vector#cross_product`
|
50
50
|
|
51
|
-
*
|
51
|
+
* Vectors scalar product (inner product, dot product) `Vector#scalar_product`
|
52
52
|
|
53
|
-
*
|
53
|
+
* Segment length `Segment#length`
|
54
54
|
|
55
|
-
*
|
55
|
+
* Vector modulus `Vector#modulus`
|
56
56
|
|
57
|
-
*
|
57
|
+
* Trivial vector arithmetics: summation, subtraction, vector-number multiplication `Vector#+(vector); Vector#-(vector); Vector#*(numeric)`
|
58
58
|
|
59
|
-
*
|
59
|
+
* Euclid distance `Geometry#distance`
|
60
60
|
|
61
|
-
*
|
61
|
+
* Line slope `Line#slope`
|
62
62
|
|
63
|
-
*
|
63
|
+
* Y-intercept of a line `Line#y_intercept`
|
64
64
|
|
65
|
-
*
|
65
|
+
* X-intercept of a line `Line#x_intercept`
|
66
66
|
|
67
|
-
*
|
67
|
+
* Are lines parallel? `Line#parallel_to?`
|
68
68
|
|
69
|
-
*
|
70
|
-
|
71
|
-
*
|
69
|
+
* What x-value do lines intersect at? `Line#intersect_x`
|
70
|
+
|
71
|
+
* What is the angle between two lines? `Line#angle_to`
|
72
|
+
|
73
|
+
* Rectangular bounds of polygon `Polygon#bounding_box`
|
74
|
+
|
75
|
+
* Does polygon contain a given point? `Polygon#contains?`
|
72
76
|
|
73
77
|
|
74
78
|
Coming up
|
@@ -76,9 +80,7 @@ Coming up
|
|
76
80
|
|
77
81
|
* Is polygon self-intersecting?
|
78
82
|
|
79
|
-
*
|
80
|
-
|
81
|
-
* Is polygon convex?
|
83
|
+
* Is polygon convex?
|
82
84
|
|
83
85
|
* Do polygons intersect?
|
84
86
|
|
@@ -86,7 +88,5 @@ Coming up
|
|
86
88
|
|
87
89
|
* Do circles intersect?
|
88
90
|
|
89
|
-
* Area of circle
|
90
|
-
|
91
91
|
|
92
92
|
Copyright (c) 2008 Daniel Vartanov, released under the MIT license
|
data/lib/geometry.rb
CHANGED
@@ -1,18 +1,18 @@
|
|
1
1
|
require "active_support/core_ext/module/delegation"
|
2
2
|
require "memoist"
|
3
3
|
|
4
|
-
require 'point'
|
5
|
-
require 'segment'
|
6
|
-
require 'vector'
|
7
|
-
require 'polygon'
|
8
|
-
require 'line'
|
9
|
-
require 'bounding_box'
|
10
|
-
require 'algorithms/point_in_polygon'
|
4
|
+
require 'geometry/point'
|
5
|
+
require 'geometry/segment'
|
6
|
+
require 'geometry/vector'
|
7
|
+
require 'geometry/polygon'
|
8
|
+
require 'geometry/line'
|
9
|
+
require 'geometry/bounding_box'
|
10
|
+
require 'geometry/algorithms/point_in_polygon'
|
11
11
|
|
12
12
|
module Geometry
|
13
13
|
include Math
|
14
14
|
extend Math
|
15
|
-
|
15
|
+
|
16
16
|
def distance(point1, point2)
|
17
17
|
hypot point1.x - point2.x, point1.y - point2.y
|
18
18
|
end
|
@@ -43,7 +43,7 @@ module Geometry
|
|
43
43
|
end
|
44
44
|
|
45
45
|
def good_ray?(ray)
|
46
|
-
edges.none? { |edge| edge.parallel_to?(ray) } && vertices.none? { |vertex| ray.contains_point?(vertex) }
|
46
|
+
edges.none? { |edge| !edge.length.zero? && edge.parallel_to?(ray) } && vertices.none? { |vertex| ray.contains_point?(vertex) }
|
47
47
|
end
|
48
48
|
|
49
49
|
def intersection_count(ray)
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
data/ruby-geometry.gemspec
CHANGED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
require 'geometry'
|
3
|
+
|
4
|
+
class SlopeTest < MiniTest::Unit::TestCase
|
5
|
+
include Geometry
|
6
|
+
|
7
|
+
def test_length
|
8
|
+
point1 = Point.new(0, 0)
|
9
|
+
point2 = Point.new(3, 4)
|
10
|
+
line = Line.new(point1, point2)
|
11
|
+
assert_equal 5, point1.distance_to(point2)
|
12
|
+
assert_equal 5, line.length
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
require 'geometry'
|
3
|
+
|
4
|
+
class DistanceToTest < MiniTest::Unit::TestCase
|
5
|
+
include Geometry
|
6
|
+
|
7
|
+
# Distance in whole number
|
8
|
+
def test_distance_to_point2
|
9
|
+
point1 = Point.new(0, 0)
|
10
|
+
point2 = Point.new(3, 4)
|
11
|
+
assert_equal 5, point1.distance_to(point2)
|
12
|
+
end
|
13
|
+
|
14
|
+
# Distance in decimal
|
15
|
+
# point 2 is right up
|
16
|
+
def test_distance_to_point_right_up
|
17
|
+
point1 = Point.new(0, 0)
|
18
|
+
point2 = Point.new(1, 1)
|
19
|
+
assert_equal Math.sqrt(2), point1.distance_to(point2)
|
20
|
+
end
|
21
|
+
|
22
|
+
# Point 2 is left up
|
23
|
+
def test_distance_to_point_left_up
|
24
|
+
point1 = Point.new(3, 0)
|
25
|
+
point2 = Point.new(0, 4)
|
26
|
+
assert_equal 5, point1.distance_to(point2)
|
27
|
+
end
|
28
|
+
|
29
|
+
# Point 2 is right below
|
30
|
+
def test_distance_to_point_right_below
|
31
|
+
point1 = Point.new(0, 4)
|
32
|
+
point2 = Point.new(3, 0)
|
33
|
+
assert_equal 5, point1.distance_to(point2)
|
34
|
+
end
|
35
|
+
|
36
|
+
# Point 2 is left below
|
37
|
+
def test_distance_to_point_left_below
|
38
|
+
point1 = Point.new(3, 4)
|
39
|
+
point2 = Point.new(0, 0)
|
40
|
+
assert_equal 5, point1.distance_to(point2)
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
@@ -28,4 +28,10 @@ class DistanceToTest < MiniTest::Unit::TestCase
|
|
28
28
|
assert_equal 1, segment.distance_to(point)
|
29
29
|
end
|
30
30
|
|
31
|
-
|
31
|
+
def test_distance_to_point_segment
|
32
|
+
segment = Segment.new_by_arrays([0, 1], [0, 1])
|
33
|
+
point = Point.new(1, 1)
|
34
|
+
assert_equal 1, segment.distance_to(point)
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
metadata
CHANGED
@@ -1,83 +1,83 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-geometry
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Vartanov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-01-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: memoist
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: bundler
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rake
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: minitest
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- -
|
73
|
+
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '0'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- -
|
80
|
+
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
83
|
description:
|
@@ -87,22 +87,23 @@ executables: []
|
|
87
87
|
extensions: []
|
88
88
|
extra_rdoc_files: []
|
89
89
|
files:
|
90
|
-
- .gitignore
|
91
|
-
- .ruby-version
|
90
|
+
- ".gitignore"
|
91
|
+
- ".ruby-version"
|
92
|
+
- CHANGELOG.md
|
92
93
|
- Gemfile
|
93
94
|
- MIT-LICENSE
|
94
95
|
- README.md
|
95
96
|
- Rakefile
|
96
97
|
- TODO
|
97
|
-
- lib/algorithms/point_in_polygon.rb
|
98
|
-
- lib/bounding_box.rb
|
99
|
-
- lib/comparison_with_precision.rb
|
100
98
|
- lib/geometry.rb
|
101
|
-
- lib/
|
102
|
-
- lib/
|
103
|
-
- lib/
|
104
|
-
- lib/
|
105
|
-
- lib/
|
99
|
+
- lib/geometry/algorithms/point_in_polygon.rb
|
100
|
+
- lib/geometry/bounding_box.rb
|
101
|
+
- lib/geometry/comparison_with_precision.rb
|
102
|
+
- lib/geometry/line.rb
|
103
|
+
- lib/geometry/point.rb
|
104
|
+
- lib/geometry/polygon.rb
|
105
|
+
- lib/geometry/segment.rb
|
106
|
+
- lib/geometry/vector.rb
|
106
107
|
- ruby-geometry.gemspec
|
107
108
|
- test/bounding_box/contains_test.rb
|
108
109
|
- test/geometry/distance_test.rb
|
@@ -111,12 +112,14 @@ files:
|
|
111
112
|
- test/line/horizontal_test.rb
|
112
113
|
- test/line/initialize_test.rb
|
113
114
|
- test/line/intersect_x_test.rb
|
115
|
+
- test/line/length_test.rb
|
114
116
|
- test/line/parallel_to_test.rb
|
115
117
|
- test/line/slope_test.rb
|
116
118
|
- test/line/vertical_test.rb
|
117
119
|
- test/line/x_intercept_test.rb
|
118
120
|
- test/line/y_intercept_test.rb
|
119
121
|
- test/point/advance_by_test.rb
|
122
|
+
- test/point/distance_to_test.rb
|
120
123
|
- test/point/equals_test.rb
|
121
124
|
- test/point/initialize_test.rb
|
122
125
|
- test/polygon/bounding_box_test.rb
|
@@ -150,17 +153,17 @@ require_paths:
|
|
150
153
|
- lib
|
151
154
|
required_ruby_version: !ruby/object:Gem::Requirement
|
152
155
|
requirements:
|
153
|
-
- -
|
156
|
+
- - ">="
|
154
157
|
- !ruby/object:Gem::Version
|
155
158
|
version: '0'
|
156
159
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
157
160
|
requirements:
|
158
|
-
- -
|
161
|
+
- - ">="
|
159
162
|
- !ruby/object:Gem::Version
|
160
163
|
version: '0'
|
161
164
|
requirements: []
|
162
165
|
rubyforge_project:
|
163
|
-
rubygems_version: 2.
|
166
|
+
rubygems_version: 2.4.6
|
164
167
|
signing_key:
|
165
168
|
specification_version: 4
|
166
169
|
summary: Implementation of basic 2D geometry algorithms in Ruby
|
@@ -172,12 +175,14 @@ test_files:
|
|
172
175
|
- test/line/horizontal_test.rb
|
173
176
|
- test/line/initialize_test.rb
|
174
177
|
- test/line/intersect_x_test.rb
|
178
|
+
- test/line/length_test.rb
|
175
179
|
- test/line/parallel_to_test.rb
|
176
180
|
- test/line/slope_test.rb
|
177
181
|
- test/line/vertical_test.rb
|
178
182
|
- test/line/x_intercept_test.rb
|
179
183
|
- test/line/y_intercept_test.rb
|
180
184
|
- test/point/advance_by_test.rb
|
185
|
+
- test/point/distance_to_test.rb
|
181
186
|
- test/point/equals_test.rb
|
182
187
|
- test/point/initialize_test.rb
|
183
188
|
- test/polygon/bounding_box_test.rb
|