ruby-geometry 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +5 -0
  3. data/.ruby-version +1 -0
  4. data/Gemfile +3 -0
  5. data/MIT-LICENSE +20 -0
  6. data/README.md +92 -0
  7. data/Rakefile +13 -0
  8. data/TODO +35 -0
  9. data/lib/line.rb +12 -0
  10. data/lib/point.rb +9 -1
  11. data/lib/polygon.rb +11 -0
  12. data/lib/segment.rb +23 -0
  13. data/ruby-geometry.gemspec +22 -0
  14. data/test/bounding_box/contains_test.rb +2 -2
  15. data/test/geometry/distance_test.rb +2 -2
  16. data/test/line/angle_to_test.rb +2 -2
  17. data/test/line/distance_to_test.rb +18 -0
  18. data/test/line/horizontal_test.rb +2 -2
  19. data/test/line/initialize_test.rb +2 -2
  20. data/test/line/intersect_x_test.rb +2 -2
  21. data/test/line/parallel_to_test.rb +2 -2
  22. data/test/line/slope_test.rb +2 -2
  23. data/test/line/vertical_test.rb +2 -2
  24. data/test/line/x_intercept_test.rb +2 -2
  25. data/test/line/y_intercept_test.rb +2 -2
  26. data/test/point/advance_by_test.rb +12 -0
  27. data/test/point/equals_test.rb +2 -2
  28. data/test/point/initialize_test.rb +2 -2
  29. data/test/polygon/bounding_box_test.rb +2 -2
  30. data/test/polygon/contains_point_test.rb +2 -2
  31. data/test/polygon/edges_test.rb +2 -2
  32. data/test/polygon/polygon_area_test.rb +35 -0
  33. data/test/segment/bounds_test.rb +2 -2
  34. data/test/segment/contains_point_test.rb +2 -2
  35. data/test/segment/distance_to_test.rb +31 -0
  36. data/test/segment/initialize_test.rb +2 -2
  37. data/test/segment/intersection_point_with_test.rb +9 -7
  38. data/test/segment/intersects_with_test.rb +2 -2
  39. data/test/segment/length_test.rb +2 -2
  40. data/test/segment/lie_on_one_line_with.rb +34 -0
  41. data/test/segment/overlaps_test.rb +8 -6
  42. data/test/segment/parallel_to_test.rb +2 -2
  43. data/test/segment/to_vector_test.rb +2 -2
  44. data/test/vector/arithmetics_test.rb +2 -2
  45. data/test/vector/collinear_with_test.rb +2 -2
  46. data/test/vector/cross_product_test.rb +2 -2
  47. data/test/vector/equals_test.rb +7 -7
  48. data/test/vector/modulus_test.rb +2 -2
  49. data/test/vector/scalar_product_test.rb +2 -2
  50. metadata +78 -23
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ceb19ba1fb790c21207f0d8b7543b64676e8c4d0
4
+ data.tar.gz: c69308a99ef8aee203bdad69478e0b2108f7fea1
5
+ SHA512:
6
+ metadata.gz: e4c5e0981ef218e99c704aefbf9410e2fe2c62dd1a650a790fd2fd6b4194869c46f77154242a444ff335960853cbc1a86f0225964bdaf884a23922f87966a9e7
7
+ data.tar.gz: 326038ae5819fa77e6986a78eb5b04b6eee0a4ff66e89d0b483fd426bb42965a5d700f201552299bcb6a0b96677168f06a0cac36487bcfb11d3ca31aca2c9a8e
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ nbproject
2
+ bin/*
3
+ pkg
4
+ .idea
5
+ Gemfile.lock
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.0.0
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008 Daniel Vartanov
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.
data/README.md ADDED
@@ -0,0 +1,92 @@
1
+ Geometry in Ruby
2
+ ================
3
+
4
+ Implementation of basic 2D geometry algorithms in Ruby.
5
+
6
+
7
+ Installation
8
+ ============
9
+ ```ruby
10
+ gem 'ruby-geometry', require: 'geometry'
11
+ ```
12
+
13
+
14
+ Defined geometry objects
15
+ ========================
16
+
17
+ * Point
18
+
19
+ * Segment
20
+
21
+ * Vector
22
+
23
+ * Polygon
24
+
25
+ * Line
26
+
27
+
28
+ Already implemented algorithms
29
+ ==============================
30
+
31
+ * Do segments overlap? { Segments#overlaps? }
32
+
33
+ * Do segments lie on one line? { Segment#lies_on_one_line_with? }
34
+
35
+ * Do segments intersect? { Segment#intersects_with? }
36
+
37
+ * Segments intersection point { Segment#intersection_point_with }
38
+
39
+ * Does segment contain given point? { Segment#contains_point? }
40
+
41
+ * Are segments parallel? { Segment#parallel_to? }
42
+
43
+ * Are vectors collinear? { Vector#collinear_with? }
44
+
45
+ * Vectors cross product (outer product, vector product) { Vector#cross_product }
46
+
47
+ * Vectors scalar product (inner product, dot product) { Vector#scalar_product }
48
+
49
+ * Segment length { Segment#length }
50
+
51
+ * Vector modulus { Vector#modulus }
52
+
53
+ * Trivial vector arithmetics: summation, subtraction, vector-number multiplication { Vector#+(vector); Vector#-(vector); Vector#*(numeric) }
54
+
55
+ * Euclid distance { Geometry#distance }
56
+
57
+ * Line slope { Line#slope }
58
+
59
+ * Y-intercept of a line { Line#y_intercept }
60
+
61
+ * X-intercept of a line { Line#x_intercept }
62
+
63
+ * Are lines parallel? { Line#parallel_to? }
64
+
65
+ * What x-value do lines intersect at? { Line#intersect_x }
66
+
67
+ * What is the angle between two lines? { Line#angle_to }
68
+
69
+ * Rectangular bounds of polygon { Polygon#bounding_box }
70
+
71
+ * Does polygon contain a given point? { Polygon#contains? }
72
+
73
+
74
+ Coming up
75
+ =========
76
+
77
+ * Is polygon self-intersecting?
78
+
79
+ * Area of polygon
80
+
81
+ * Is polygon convex?
82
+
83
+ * Do polygons intersect?
84
+
85
+ * Does circle contain given point?
86
+
87
+ * Do circles intersect?
88
+
89
+ * Area of circle
90
+
91
+
92
+ Copyright (c) 2008 Daniel Vartanov, released under the MIT license
data/Rakefile ADDED
@@ -0,0 +1,13 @@
1
+ require 'rake/dsl_definition'
2
+ require 'rake'
3
+ require 'rake/testtask'
4
+ require 'bundler/gem_tasks'
5
+
6
+ task default: :test
7
+
8
+ Rake::TestTask.new do |t|
9
+ t.libs << "lib"
10
+ t.libs << "test"
11
+ t.test_files = FileList['test/**/*_test.rb']
12
+ t.verbose = true
13
+ end
data/TODO ADDED
@@ -0,0 +1,35 @@
1
+ == Auxiliary features
2
+ * Methods requests tagging
3
+
4
+ If algorithm requires some state or property of object, it should be tagged.
5
+ Requirements should be checked before each method call (of course, info should
6
+ be cached due to computational complexity of algorithms).
7
+ Example:
8
+
9
+ class Polygon
10
+
11
+ def convex?
12
+ ...
13
+ end
14
+
15
+ def self_intersecting?
16
+ ...
17
+ end
18
+
19
+ must_be :convex
20
+ must_not_be :self_intersecting
21
+ def contains_point?(point)
22
+ ... # code, which assumes, that polygon is convex and not self_intersecting
23
+ end
24
+
25
+ == Algorithms
26
+
27
+ * Polygon convexity
28
+ * Polygons intersection
29
+ * Polygon contains given point?
30
+ * Rectangular bounds of polygon
31
+ * Area of polygon
32
+ * Does circle contain given point?
33
+ * Do circles intersect?
34
+ * Area of circle
35
+ * Making a ruby gem
data/lib/line.rb CHANGED
@@ -77,5 +77,17 @@ module Geometry
77
77
  oa = Math::atan(other.slope)
78
78
  (sa-oa).abs
79
79
  end
80
+
81
+ def distance_to(point)
82
+ x0 = point.x
83
+ y0 = point.y
84
+
85
+ x1 = point1.x
86
+ x2 = point2.x
87
+ y1 = point1.y
88
+ y2 = point2.y
89
+
90
+ (((x2-x1)*(y1-y0))-((x1-x0)*(y2-y1))).abs/Math.sqrt((x2-x1)**2+(y2-y1)**2)
91
+ end
80
92
  end
81
93
  end
data/lib/point.rb CHANGED
@@ -1,12 +1,20 @@
1
1
  module Geometry
2
2
  class Point < Struct.new(:x, :y)
3
- def self.new_by_array(array)
3
+ def self.new_by_array(array)
4
4
  self.new(array[0], array[1])
5
5
  end
6
6
 
7
7
  def ==(another_point)
8
8
  x === another_point.x && y === another_point.y
9
9
  end
10
+
11
+ def to_vector
12
+ Vector.new(x, y)
13
+ end
14
+
15
+ def advance_by(vector)
16
+ Point x + vector.x, y + vector.y
17
+ end
10
18
  end
11
19
  end
12
20
 
data/lib/polygon.rb CHANGED
@@ -21,6 +21,17 @@ module Geometry
21
21
  point_in_polygon = PointInPolygon.new(point, self)
22
22
  point_in_polygon.inside? || point_in_polygon.on_the_boundary?
23
23
  end
24
+
25
+ def area
26
+ sum = 0.0
27
+ (0..vertices.length-1).each do |i|
28
+ a = vertices[i-1]
29
+ b = vertices[i]
30
+
31
+ sum = sum + ((a.x * b.y) - (a.y * b.x))
32
+ end
33
+ (sum/2).abs
34
+ end
24
35
  end
25
36
  end
26
37
 
data/lib/segment.rb CHANGED
@@ -66,6 +66,29 @@ module Geometry
66
66
  Point.new(x, y)
67
67
  end
68
68
 
69
+ def distance_to(point)
70
+ q = point.to_vector
71
+ p1 = point1.to_vector
72
+ p2 = point2.to_vector
73
+
74
+ u = p2 - p1
75
+ v = q - p1
76
+
77
+ a = u.scalar_product(v)
78
+ if a < 0
79
+ p = p1
80
+ else
81
+ b = u.scalar_product(u)
82
+ if a > b
83
+ p = p2
84
+ else
85
+ p = p1 + (a.to_f / b * u)
86
+ end
87
+ end
88
+
89
+ return Geometry.distance(q, p)
90
+ end
91
+
69
92
  def length
70
93
  Geometry.distance(point1, point2)
71
94
  end
@@ -0,0 +1,22 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "ruby-geometry"
3
+ s.version = "0.0.5"
4
+ s.author = ["Daniel Vartanov"]
5
+ s.email = ["dan@vartanov.net"]
6
+ s.homepage = "http://github.com/DanielVartanov/ruby-geometry"
7
+ s.summary = "Implementation of basic 2D geometry algorithms in Ruby"
8
+ s.has_rdoc = false
9
+ s.license = "MIT"
10
+
11
+ s.files = `git ls-files`.split($/)
12
+ s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
13
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
14
+ s.require_paths = ["lib"]
15
+
16
+ s.add_dependency 'activesupport'
17
+ s.add_dependency 'memoist'
18
+
19
+ s.add_development_dependency 'bundler'
20
+ s.add_development_dependency 'rake'
21
+ s.add_development_dependency 'minitest'
22
+ end
@@ -1,7 +1,7 @@
1
- require 'test/unit'
1
+ require 'minitest/autorun'
2
2
  require 'geometry'
3
3
 
4
- class ContainsTest < Test::Unit::TestCase
4
+ class ContainsTest < MiniTest::Unit::TestCase
5
5
  include Geometry
6
6
 
7
7
  def bounding_box
@@ -1,7 +1,7 @@
1
- require 'test/unit'
1
+ require 'minitest/autorun'
2
2
  require 'geometry'
3
3
 
4
- class DistanceTest < Test::Unit::TestCase
4
+ class DistanceTest < MiniTest::Unit::TestCase
5
5
  include Geometry
6
6
 
7
7
  def test_trivial_cases
@@ -1,7 +1,7 @@
1
- require 'test/unit'
1
+ require 'minitest/autorun'
2
2
  require 'geometry'
3
3
 
4
- class AngleToTest < Test::Unit::TestCase
4
+ class AngleToTest < MiniTest::Unit::TestCase
5
5
  include Geometry
6
6
 
7
7
  def test_angle_to_self
@@ -0,0 +1,18 @@
1
+ require 'minitest/autorun'
2
+ require 'geometry'
3
+
4
+ class DistanceToTest < MiniTest::Unit::TestCase
5
+ include Geometry
6
+
7
+ def test_distance_to_point_on_line
8
+ line = Line.new_by_arrays([0, 2], [2, 0])
9
+ point = Point.new(1,1)
10
+ assert_equal 0, line.distance_to(point)
11
+ end
12
+
13
+ def test_distance_to_flat_line
14
+ line = Line.new_by_arrays([0, 1], [2, 1])
15
+ point = Point.new(1, 2)
16
+ assert_equal 1, line.distance_to(point)
17
+ end
18
+ end
@@ -1,7 +1,7 @@
1
- require 'test/unit'
1
+ require 'minitest/autorun'
2
2
  require 'geometry'
3
3
 
4
- class HorizontalTest < Test::Unit::TestCase
4
+ class HorizontalTest < MiniTest::Unit::TestCase
5
5
  include Geometry
6
6
 
7
7
  def test_horizontal
@@ -1,7 +1,7 @@
1
- require 'test/unit'
1
+ require 'minitest/autorun'
2
2
  require 'geometry'
3
3
 
4
- class InitializeTest < Test::Unit::TestCase
4
+ class InitializeTest < MiniTest::Unit::TestCase
5
5
  include Geometry
6
6
 
7
7
  def test_initialize_by_points
@@ -1,7 +1,7 @@
1
- require 'test/unit'
1
+ require 'minitest/autorun'
2
2
  require 'geometry'
3
3
 
4
- class IntersectXTest < Test::Unit::TestCase
4
+ class IntersectXTest < MiniTest::Unit::TestCase
5
5
  include Geometry
6
6
 
7
7
  def test_vertical_non_overlapping
@@ -1,7 +1,7 @@
1
- require 'test/unit'
1
+ require 'minitest/autorun'
2
2
  require 'geometry'
3
3
 
4
- class ParallelToTest < Test::Unit::TestCase
4
+ class ParallelToTest < MiniTest::Unit::TestCase
5
5
  include Geometry
6
6
 
7
7
  def test_identical
@@ -1,7 +1,7 @@
1
- require 'test/unit'
1
+ require 'minitest/autorun'
2
2
  require 'geometry'
3
3
 
4
- class SlopeTest < Test::Unit::TestCase
4
+ class SlopeTest < MiniTest::Unit::TestCase
5
5
  include Geometry
6
6
 
7
7
  def setup
@@ -1,7 +1,7 @@
1
- require 'test/unit'
1
+ require 'minitest/autorun'
2
2
  require 'geometry'
3
3
 
4
- class VerticalTest < Test::Unit::TestCase
4
+ class VerticalTest < MiniTest::Unit::TestCase
5
5
  include Geometry
6
6
 
7
7
  def test_vertical
@@ -1,7 +1,7 @@
1
- require 'test/unit'
1
+ require 'minitest/autorun'
2
2
  require 'geometry'
3
3
 
4
- class XInterceptTest < Test::Unit::TestCase
4
+ class XInterceptTest < MiniTest::Unit::TestCase
5
5
  include Geometry
6
6
 
7
7
  def setup
@@ -1,7 +1,7 @@
1
- require 'test/unit'
1
+ require 'minitest/autorun'
2
2
  require 'geometry'
3
3
 
4
- class YInterceptTest < Test::Unit::TestCase
4
+ class YInterceptTest < MiniTest::Unit::TestCase
5
5
  include Geometry
6
6
 
7
7
  def setup
@@ -0,0 +1,12 @@
1
+ require 'minitest/autorun'
2
+ require 'geometry'
3
+
4
+ class AdvanceByTest < MiniTest::Unit::TestCase
5
+ include Geometry
6
+
7
+ def test_advance_by
8
+ point = Point.new(10, 15)
9
+ vector = Vector.new(-5, -10)
10
+ assert_equal Point.new(5, 5), point.advance_by(vector)
11
+ end
12
+ end
@@ -1,7 +1,7 @@
1
- require 'test/unit'
1
+ require 'minitest/autorun'
2
2
  require 'geometry'
3
3
 
4
- class EqualsTest < Test::Unit::TestCase
4
+ class EqualsTest < MiniTest::Unit::TestCase
5
5
  include Geometry
6
6
 
7
7
  def test_equal
@@ -1,7 +1,7 @@
1
- require 'test/unit'
1
+ require 'minitest/autorun'
2
2
  require 'geometry'
3
3
 
4
- class InitializeTest < Test::Unit::TestCase
4
+ class InitializeTest < MiniTest::Unit::TestCase
5
5
  include Geometry
6
6
 
7
7
  def test_initialize_by_numbers
@@ -1,7 +1,7 @@
1
- require 'test/unit'
1
+ require 'minitest/autorun'
2
2
  require 'geometry'
3
3
 
4
- class BoundingBoxTest < Test::Unit::TestCase
4
+ class BoundingBoxTest < MiniTest::Unit::TestCase
5
5
  include Geometry
6
6
 
7
7
  def test_rectangle
@@ -1,7 +1,7 @@
1
- require 'test/unit'
1
+ require 'minitest/autorun'
2
2
  require 'geometry'
3
3
 
4
- class ContainsPointTest < Test::Unit::TestCase
4
+ class ContainsPointTest < MiniTest::Unit::TestCase
5
5
  include Geometry
6
6
 
7
7
  def test_convex
@@ -1,7 +1,7 @@
1
- require 'test/unit'
1
+ require 'minitest/autorun'
2
2
  require 'geometry'
3
3
 
4
- class EdgesTest < Test::Unit::TestCase
4
+ class EdgesTest < MiniTest::Unit::TestCase
5
5
  include Geometry
6
6
 
7
7
  # +-----+
@@ -0,0 +1,35 @@
1
+ require 'minitest/autorun'
2
+ require 'geometry'
3
+
4
+ class PolygonAreaTest < MiniTest::Unit::TestCase
5
+ include Geometry
6
+ def test_area_of_empty_polygon
7
+ polygon = Polygon.new []
8
+
9
+ assert_equal 0, polygon.area
10
+ end
11
+
12
+ def test_area_of_two_points_polygon
13
+ polygon = Polygon.new [Point(0,0), Point(1,1)]
14
+
15
+ assert_equal 0, polygon.area
16
+ end
17
+
18
+ def test_area_of_triangle
19
+ polygon = Polygon.new [Point(0,0), Point(1,1), Point(0,1)]
20
+
21
+ assert_equal 0.5, polygon.area
22
+ end
23
+
24
+ def test_area_of_square
25
+ polygon = Polygon.new [Point(0,0), Point(0,2), Point(2,2), Point(2,0)]
26
+
27
+ assert_equal 4, polygon.area
28
+ end
29
+
30
+ def test_area_of_quadralateral
31
+ polygon = Polygon.new [Point(4,10), Point(9,7), Point(11,2), Point(2,2)]
32
+
33
+ assert_equal 45.5, polygon.area
34
+ end
35
+ end
@@ -1,7 +1,7 @@
1
- require 'test/unit'
1
+ require 'minitest/autorun'
2
2
  require 'geometry'
3
3
 
4
- class BoundsTest < Test::Unit::TestCase
4
+ class BoundsTest < MiniTest::Unit::TestCase
5
5
  include Geometry
6
6
 
7
7
  def setup
@@ -1,7 +1,7 @@
1
- require 'test/unit'
1
+ require 'minitest/autorun'
2
2
  require 'geometry'
3
3
 
4
- class ContainsPointTest < Test::Unit::TestCase
4
+ class ContainsPointTest < MiniTest::Unit::TestCase
5
5
  include Geometry
6
6
 
7
7
  # ----*----
@@ -0,0 +1,31 @@
1
+ require 'minitest/autorun'
2
+ require 'geometry'
3
+
4
+ class DistanceToTest < MiniTest::Unit::TestCase
5
+ include Geometry
6
+
7
+ def test_distance_to_point_on_segment
8
+ segment = Segment.new_by_arrays([0, 2], [2, 0])
9
+ point = Point.new(1,1)
10
+ assert_equal 0, segment.distance_to(point)
11
+ end
12
+
13
+ def test_distance_to_flat_segment
14
+ segment = Segment.new_by_arrays([0, 1], [2, 1])
15
+ point = Point.new(1, 2)
16
+ assert_equal 1, segment.distance_to(point)
17
+ end
18
+
19
+ def test_distance_to_segment_start
20
+ segment = Segment.new_by_arrays([1, 1], [2, 1])
21
+ point = Point.new(0, 1)
22
+ assert_equal 1, segment.distance_to(point)
23
+ end
24
+
25
+ def test_distance_to_segment_end
26
+ segment = Segment.new_by_arrays([0, 1], [0, 2])
27
+ point = Point.new(0, 3)
28
+ assert_equal 1, segment.distance_to(point)
29
+ end
30
+
31
+ end
@@ -1,7 +1,7 @@
1
- require 'test/unit'
1
+ require 'minitest/autorun'
2
2
  require 'geometry'
3
3
 
4
- class InitializeTest < Test::Unit::TestCase
4
+ class InitializeTest < MiniTest::Unit::TestCase
5
5
  include Geometry
6
6
 
7
7
  def test_initialize_by_points
@@ -1,16 +1,16 @@
1
- require 'test/unit'
1
+ require 'minitest/autorun'
2
2
  require 'geometry'
3
3
 
4
- class IntersectionPointWithTest < Test::Unit::TestCase
4
+ class IntersectionPointWithTest < MiniTest::Unit::TestCase
5
5
  include Geometry
6
-
6
+
7
7
  def test_regular_case
8
8
  segment1 = Segment.new_by_arrays([0, 0], [2, 2])
9
9
  segment2 = Segment.new_by_arrays([0, 2], [2, 0])
10
10
 
11
11
  assert_equal Point.new(1, 1), segment1.intersection_point_with(segment2)
12
12
  end
13
-
13
+
14
14
  def test_segments_intersect_at_the_endpoint
15
15
  segment1 = Segment.new_by_arrays([0, 0], [2, 2])
16
16
  segment2 = Segment.new_by_arrays([0, 2], [2, 2])
@@ -22,7 +22,7 @@ class IntersectionPointWithTest < Test::Unit::TestCase
22
22
  segment1 = Segment.new_by_arrays([0, 0], [0, 2])
23
23
  segment2 = Segment.new_by_arrays([1, 1], [2, 1])
24
24
 
25
- assert_raise SegmentsDoNotIntersect do
25
+ assert_raises SegmentsDoNotIntersect do
26
26
  segment1.intersection_point_with(segment2)
27
27
  end
28
28
  end
@@ -31,7 +31,7 @@ class IntersectionPointWithTest < Test::Unit::TestCase
31
31
  segment1 = Segment.new_by_arrays([0, 0], [2, 2])
32
32
  segment2 = Segment.new_by_arrays([1, 0], [3, 2])
33
33
 
34
- assert_raise SegmentsDoNotIntersect do
34
+ assert_raises SegmentsDoNotIntersect do
35
35
  segment1.intersection_point_with(segment2)
36
36
  end
37
37
  end
@@ -40,12 +40,14 @@ class IntersectionPointWithTest < Test::Unit::TestCase
40
40
  segment1 = Segment.new_by_arrays([0, 0], [2, 2])
41
41
  segment2 = Segment.new_by_arrays([1, 1], [3, 3])
42
42
 
43
- assert_raise SegmentsOverlap do
43
+ assert_raises SegmentsOverlap do
44
44
  segment1.intersection_point_with(segment2)
45
45
  end
46
46
  end
47
47
 
48
48
  def test_segments_parallel_and_have_common_endpoint
49
+ skip 'Not implemented yet'
50
+
49
51
  segment1 = Segment.new_by_arrays([0, 0], [1, 0])
50
52
  segment2 = Segment.new_by_arrays([1, 0], [2, 0])
51
53
 
@@ -1,7 +1,7 @@
1
- require 'test/unit'
1
+ require 'minitest/autorun'
2
2
  require 'geometry'
3
3
 
4
- class IntersectsTest < Test::Unit::TestCase
4
+ class IntersectsTest < MiniTest::Unit::TestCase
5
5
  include Geometry
6
6
 
7
7
  # |
@@ -1,7 +1,7 @@
1
- require 'test/unit'
1
+ require 'minitest/autorun'
2
2
  require 'geometry'
3
3
 
4
- class LengthTest < Test::Unit::TestCase
4
+ class LengthTest < MiniTest::Unit::TestCase
5
5
  include Geometry
6
6
 
7
7
  def test_parallel_to_axis
@@ -0,0 +1,34 @@
1
+ require 'minitest/autorun'
2
+ require 'geometry'
3
+
4
+ class IntersectsTest < MiniTest::Unit::TestCase
5
+ include Geometry
6
+
7
+ def test_segments_parralel_but_on_different_lines
8
+ segment1 = Segment.new_by_arrays([0, 1], [2, 1])
9
+ segment2 = Segment.new_by_arrays([0, 0], [2, 0])
10
+
11
+ assert ! segment1.lies_on_one_line_with?(segment2)
12
+ end
13
+
14
+ def test_segments_are_not_parallel
15
+ segment1 = Segment.new_by_arrays([0, 0], [2, 0])
16
+ segment2 = Segment.new_by_arrays([0, 1], [2, 2])
17
+
18
+ assert ! segment1.lies_on_one_line_with?(segment2)
19
+ end
20
+
21
+ def test_segments_lie_on_one_line
22
+ segment1 = Segment.new_by_arrays([0, 0], [1, 0])
23
+ segment2 = Segment.new_by_arrays([2, 0], [3, 0])
24
+
25
+ assert segment1.lies_on_one_line_with?(segment2)
26
+ end
27
+
28
+ def test_segments_lin_on_one_vertical_line
29
+ segment1 = Segment.new_by_arrays([0, 0], [0, 1])
30
+ segment2 = Segment.new_by_arrays([0, 2], [0, 3])
31
+
32
+ assert segment1.lies_on_one_line_with?(segment2)
33
+ end
34
+ end
@@ -1,7 +1,7 @@
1
- require 'test/unit'
1
+ require 'minitest/autorun'
2
2
  require 'geometry'
3
3
 
4
- class OverlapsTest < Test::Unit::TestCase
4
+ class OverlapsTest < MiniTest::Unit::TestCase
5
5
  include Geometry
6
6
 
7
7
  def test_overlaps
@@ -24,6 +24,8 @@ class OverlapsTest < Test::Unit::TestCase
24
24
  end
25
25
 
26
26
  def test_lies_on_one_line_and_have_common_endpoint
27
+ skip 'Not implemented yet'
28
+
27
29
  segment1 = Segment.new_by_arrays([0, 0], [1, 0])
28
30
  segment2 = Segment.new_by_arrays([1, 0], [2, 0])
29
31
 
@@ -33,14 +35,14 @@ class OverlapsTest < Test::Unit::TestCase
33
35
  def test_lies_on_one_line
34
36
  segment1 = Segment.new_by_arrays([0, 0], [2, 0])
35
37
  segment2 = Segment.new_by_arrays([4, 0], [6, 0])
36
-
38
+
37
39
  assert ! segment1.overlaps?(segment2)
38
40
  end
39
-
41
+
40
42
  def test_lies_on_one_vertical_line
41
43
  segment1 = Segment.new_by_arrays([0, 0], [0, 1])
42
44
  segment2 = Segment.new_by_arrays([0, 2], [0, 3])
43
-
45
+
44
46
  assert ! segment1.overlaps?(segment2)
45
47
  end
46
- end
48
+ end
@@ -1,7 +1,7 @@
1
- require 'test/unit'
1
+ require 'minitest/autorun'
2
2
  require 'geometry'
3
3
 
4
- class ParallelToTest < Test::Unit::TestCase
4
+ class ParallelToTest < MiniTest::Unit::TestCase
5
5
  include Geometry
6
6
 
7
7
  def test_segments_are_parallel
@@ -1,7 +1,7 @@
1
- require 'test/unit'
1
+ require 'minitest/autorun'
2
2
  require 'geometry'
3
3
 
4
- class ToVectorTest < Test::Unit::TestCase
4
+ class ToVectorTest < MiniTest::Unit::TestCase
5
5
  include Geometry
6
6
 
7
7
  def test_regular_case
@@ -1,7 +1,7 @@
1
- require 'test/unit'
1
+ require 'minitest/autorun'
2
2
  require 'geometry'
3
3
 
4
- class ArithmeticsTest < Test::Unit::TestCase
4
+ class ArithmeticsTest < MiniTest::Unit::TestCase
5
5
  include Geometry
6
6
 
7
7
  def test_summation
@@ -1,7 +1,7 @@
1
- require 'test/unit'
1
+ require 'minitest/autorun'
2
2
  require 'geometry'
3
3
 
4
- class CollinearWithTest < Test::Unit::TestCase
4
+ class CollinearWithTest < MiniTest::Unit::TestCase
5
5
  include Geometry
6
6
 
7
7
  def test_vectors_are_collinear
@@ -1,7 +1,7 @@
1
- require 'test/unit'
1
+ require 'minitest/autorun'
2
2
  require 'geometry'
3
3
 
4
- class CrossProductTest < Test::Unit::TestCase
4
+ class CrossProductTest < MiniTest::Unit::TestCase
5
5
  include Geometry
6
6
 
7
7
  def test_positive
@@ -1,15 +1,15 @@
1
- require 'test/unit'
1
+ require 'minitest/autorun'
2
2
  require 'geometry'
3
3
 
4
- class EqualsTest < Test::Unit::TestCase
4
+ class EqualsTest < MiniTest::Unit::TestCase
5
5
  include Geometry
6
6
 
7
- def test_equal
7
+ def test_equal
8
8
  assert_equal Vector.new(1, 3), Vector.new(1, 3)
9
9
  end
10
-
11
- def test_not_equal
12
- assert_not_equal Vector.new(1, 3), Vector.new(1, 2)
13
- assert_not_equal Vector.new(1, 2), Vector.new(0, 2)
10
+
11
+ def test_not_equal
12
+ refute_equal Vector.new(1, 3), Vector.new(1, 2)
13
+ refute_equal Vector.new(1, 2), Vector.new(0, 2)
14
14
  end
15
15
  end
@@ -1,7 +1,7 @@
1
- require 'test/unit'
1
+ require 'minitest/autorun'
2
2
  require 'geometry'
3
3
 
4
- class ModulusTest < Test::Unit::TestCase
4
+ class ModulusTest < MiniTest::Unit::TestCase
5
5
  include Geometry
6
6
 
7
7
  def test_parallel_to_axis
@@ -1,7 +1,7 @@
1
- require 'test/unit'
1
+ require 'minitest/autorun'
2
2
  require 'geometry'
3
3
 
4
- class ScalarProductTest < Test::Unit::TestCase
4
+ class ScalarProductTest < MiniTest::Unit::TestCase
5
5
  include Geometry
6
6
 
7
7
  def test_vectors_are_perpendicular
metadata CHANGED
@@ -1,55 +1,99 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-geometry
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
5
- prerelease:
4
+ version: 0.0.5
6
5
  platform: ruby
7
6
  authors:
8
7
  - Daniel Vartanov
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-06-30 00:00:00.000000000 Z
11
+ date: 2014-03-15 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: activesupport
16
- requirement: &2160900040 !ruby/object:Gem::Requirement
17
- none: false
15
+ requirement: !ruby/object:Gem::Requirement
18
16
  requirements:
19
- - - ! '>='
17
+ - - '>='
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :runtime
23
21
  prerelease: false
24
- version_requirements: *2160900040
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
25
27
  - !ruby/object:Gem::Dependency
26
28
  name: memoist
27
- requirement: &2160898360 !ruby/object:Gem::Requirement
28
- none: false
29
+ requirement: !ruby/object:Gem::Requirement
29
30
  requirements:
30
- - - ! '>='
31
+ - - '>='
31
32
  - !ruby/object:Gem::Version
32
33
  version: '0'
33
34
  type: :runtime
34
35
  prerelease: false
35
- version_requirements: *2160898360
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
36
55
  - !ruby/object:Gem::Dependency
37
56
  name: rake
38
- requirement: &2160896440 !ruby/object:Gem::Requirement
39
- none: false
57
+ requirement: !ruby/object:Gem::Requirement
40
58
  requirements:
41
- - - ! '>='
59
+ - - '>='
42
60
  - !ruby/object:Gem::Version
43
61
  version: '0'
44
62
  type: :development
45
63
  prerelease: false
46
- version_requirements: *2160896440
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: minitest
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
47
83
  description:
48
- email: daniel.vartanov@gmail.com
84
+ email:
85
+ - dan@vartanov.net
49
86
  executables: []
50
87
  extensions: []
51
88
  extra_rdoc_files: []
52
89
  files:
90
+ - .gitignore
91
+ - .ruby-version
92
+ - Gemfile
93
+ - MIT-LICENSE
94
+ - README.md
95
+ - Rakefile
96
+ - TODO
53
97
  - lib/algorithms/point_in_polygon.rb
54
98
  - lib/bounding_box.rb
55
99
  - lib/comparison_with_precision.rb
@@ -59,9 +103,11 @@ files:
59
103
  - lib/polygon.rb
60
104
  - lib/segment.rb
61
105
  - lib/vector.rb
106
+ - ruby-geometry.gemspec
62
107
  - test/bounding_box/contains_test.rb
63
108
  - test/geometry/distance_test.rb
64
109
  - test/line/angle_to_test.rb
110
+ - test/line/distance_to_test.rb
65
111
  - test/line/horizontal_test.rb
66
112
  - test/line/initialize_test.rb
67
113
  - test/line/intersect_x_test.rb
@@ -70,17 +116,21 @@ files:
70
116
  - test/line/vertical_test.rb
71
117
  - test/line/x_intercept_test.rb
72
118
  - test/line/y_intercept_test.rb
119
+ - test/point/advance_by_test.rb
73
120
  - test/point/equals_test.rb
74
121
  - test/point/initialize_test.rb
75
122
  - test/polygon/bounding_box_test.rb
76
123
  - test/polygon/contains_point_test.rb
77
124
  - test/polygon/edges_test.rb
125
+ - test/polygon/polygon_area_test.rb
78
126
  - test/segment/bounds_test.rb
79
127
  - test/segment/contains_point_test.rb
128
+ - test/segment/distance_to_test.rb
80
129
  - test/segment/initialize_test.rb
81
130
  - test/segment/intersection_point_with_test.rb
82
131
  - test/segment/intersects_with_test.rb
83
132
  - test/segment/length_test.rb
133
+ - test/segment/lie_on_one_line_with.rb
84
134
  - test/segment/overlaps_test.rb
85
135
  - test/segment/parallel_to_test.rb
86
136
  - test/segment/to_vector_test.rb
@@ -91,33 +141,34 @@ files:
91
141
  - test/vector/modulus_test.rb
92
142
  - test/vector/scalar_product_test.rb
93
143
  homepage: http://github.com/DanielVartanov/ruby-geometry
94
- licenses: []
144
+ licenses:
145
+ - MIT
146
+ metadata: {}
95
147
  post_install_message:
96
148
  rdoc_options: []
97
149
  require_paths:
98
150
  - lib
99
151
  required_ruby_version: !ruby/object:Gem::Requirement
100
- none: false
101
152
  requirements:
102
- - - ! '>='
153
+ - - '>='
103
154
  - !ruby/object:Gem::Version
104
155
  version: '0'
105
156
  required_rubygems_version: !ruby/object:Gem::Requirement
106
- none: false
107
157
  requirements:
108
- - - ! '>='
158
+ - - '>='
109
159
  - !ruby/object:Gem::Version
110
160
  version: '0'
111
161
  requirements: []
112
162
  rubyforge_project:
113
- rubygems_version: 1.8.15
163
+ rubygems_version: 2.2.1
114
164
  signing_key:
115
- specification_version: 3
165
+ specification_version: 4
116
166
  summary: Implementation of basic 2D geometry algorithms in Ruby
117
167
  test_files:
118
168
  - test/bounding_box/contains_test.rb
119
169
  - test/geometry/distance_test.rb
120
170
  - test/line/angle_to_test.rb
171
+ - test/line/distance_to_test.rb
121
172
  - test/line/horizontal_test.rb
122
173
  - test/line/initialize_test.rb
123
174
  - test/line/intersect_x_test.rb
@@ -126,17 +177,21 @@ test_files:
126
177
  - test/line/vertical_test.rb
127
178
  - test/line/x_intercept_test.rb
128
179
  - test/line/y_intercept_test.rb
180
+ - test/point/advance_by_test.rb
129
181
  - test/point/equals_test.rb
130
182
  - test/point/initialize_test.rb
131
183
  - test/polygon/bounding_box_test.rb
132
184
  - test/polygon/contains_point_test.rb
133
185
  - test/polygon/edges_test.rb
186
+ - test/polygon/polygon_area_test.rb
134
187
  - test/segment/bounds_test.rb
135
188
  - test/segment/contains_point_test.rb
189
+ - test/segment/distance_to_test.rb
136
190
  - test/segment/initialize_test.rb
137
191
  - test/segment/intersection_point_with_test.rb
138
192
  - test/segment/intersects_with_test.rb
139
193
  - test/segment/length_test.rb
194
+ - test/segment/lie_on_one_line_with.rb
140
195
  - test/segment/overlaps_test.rb
141
196
  - test/segment/parallel_to_test.rb
142
197
  - test/segment/to_vector_test.rb