geom2d 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CONTRIBUTERS +3 -0
- data/LICENSE +21 -0
- data/README.md +49 -0
- data/Rakefile +101 -0
- data/VERSION +1 -0
- data/lib/geom2d.rb +70 -0
- data/lib/geom2d/algorithms.rb +35 -0
- data/lib/geom2d/algorithms/polygon_operation.rb +435 -0
- data/lib/geom2d/bounding_box.rb +84 -0
- data/lib/geom2d/point.rb +145 -0
- data/lib/geom2d/polygon.rb +108 -0
- data/lib/geom2d/polygon_set.rb +67 -0
- data/lib/geom2d/segment.rb +202 -0
- data/lib/geom2d/utils.rb +38 -0
- data/lib/geom2d/utils/sorted_linked_list.rb +154 -0
- data/lib/geom2d/version.rb +16 -0
- data/test/geom2d/algorithms/test_polygon_operation.rb +229 -0
- data/test/geom2d/test_algorithms.rb +26 -0
- data/test/geom2d/test_bounding_box.rb +37 -0
- data/test/geom2d/test_point.rb +148 -0
- data/test/geom2d/test_polygon.rb +69 -0
- data/test/geom2d/test_polygon_set.rb +41 -0
- data/test/geom2d/test_segment.rb +253 -0
- data/test/geom2d/utils/test_sorted_linked_list.rb +72 -0
- data/test/test_helper.rb +15 -0
- metadata +68 -0
@@ -0,0 +1,72 @@
|
|
1
|
+
# -*- frozen_string_literal: true -*-
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
require 'geom2d/utils/sorted_linked_list'
|
5
|
+
|
6
|
+
describe Geom2D::Utils::SortedLinkedList do
|
7
|
+
before do
|
8
|
+
@list = Geom2D::Utils::SortedLinkedList.new {|a, b| a < b }
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "insert" do
|
12
|
+
it "inserts a value and returns its associated node" do
|
13
|
+
node = @list.insert(1)
|
14
|
+
assert_equal(1, node.value)
|
15
|
+
assert(node.prev_node.anchor?)
|
16
|
+
assert(node.next_node.anchor?)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "uses the comparator for choosing the place to insert the value" do
|
20
|
+
@list.insert(10)
|
21
|
+
@list.insert(5)
|
22
|
+
@list.insert(8)
|
23
|
+
assert_equal([5, 8, 10], @list.to_a)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
it "returns whether it is empty" do
|
28
|
+
assert(@list.empty?)
|
29
|
+
@list.insert(5)
|
30
|
+
refute(@list.empty?)
|
31
|
+
@list.delete(5)
|
32
|
+
assert(@list.empty?)
|
33
|
+
end
|
34
|
+
|
35
|
+
it "returns the last value in the list" do
|
36
|
+
@list.insert(5)
|
37
|
+
assert_equal(5, @list.last)
|
38
|
+
@list.insert(10)
|
39
|
+
assert_equal(10, @list.last)
|
40
|
+
@list.insert(6)
|
41
|
+
assert_equal(10, @list.last)
|
42
|
+
end
|
43
|
+
|
44
|
+
it "returns the first node found for a given value" do
|
45
|
+
@list.push(5).push(8)
|
46
|
+
node = @list.find_node(8)
|
47
|
+
assert_equal(8, node.value)
|
48
|
+
assert_equal(5, node.prev_node.value)
|
49
|
+
assert(node.next_node.anchor?)
|
50
|
+
end
|
51
|
+
|
52
|
+
it "pops the top value of the list" do
|
53
|
+
@list.push(8).push(5)
|
54
|
+
assert_equal(8, @list.pop)
|
55
|
+
end
|
56
|
+
|
57
|
+
it "clears the whole list" do
|
58
|
+
@list.push(8).push(5)
|
59
|
+
@list.clear
|
60
|
+
assert(@list.empty?)
|
61
|
+
end
|
62
|
+
|
63
|
+
it "deletes a value from the list" do
|
64
|
+
@list.push(8).push(5)
|
65
|
+
assert_equal(8, @list.delete(8))
|
66
|
+
end
|
67
|
+
|
68
|
+
it "can be inspected" do
|
69
|
+
@list.push(8).push(5)
|
70
|
+
assert_match(/[5, 8]/, @list.inspect)
|
71
|
+
end
|
72
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# -*- frozen_string_literal: true -*-
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'simplecov'
|
5
|
+
SimpleCov.start { add_filter '/test/' }
|
6
|
+
rescue LoadError
|
7
|
+
warn "Gem 'simplecov' not installed, not generating coverage report"
|
8
|
+
end
|
9
|
+
|
10
|
+
require 'minitest/autorun'
|
11
|
+
|
12
|
+
module TestHelper
|
13
|
+
end
|
14
|
+
|
15
|
+
Minitest::Spec.send(:include, TestHelper)
|
metadata
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: geom2d
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Thomas Leitner
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-03-28 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description:
|
14
|
+
email: t_leitner@gmx.at
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- CONTRIBUTERS
|
20
|
+
- LICENSE
|
21
|
+
- README.md
|
22
|
+
- Rakefile
|
23
|
+
- VERSION
|
24
|
+
- lib/geom2d.rb
|
25
|
+
- lib/geom2d/algorithms.rb
|
26
|
+
- lib/geom2d/algorithms/polygon_operation.rb
|
27
|
+
- lib/geom2d/bounding_box.rb
|
28
|
+
- lib/geom2d/point.rb
|
29
|
+
- lib/geom2d/polygon.rb
|
30
|
+
- lib/geom2d/polygon_set.rb
|
31
|
+
- lib/geom2d/segment.rb
|
32
|
+
- lib/geom2d/utils.rb
|
33
|
+
- lib/geom2d/utils/sorted_linked_list.rb
|
34
|
+
- lib/geom2d/version.rb
|
35
|
+
- test/geom2d/algorithms/test_polygon_operation.rb
|
36
|
+
- test/geom2d/test_algorithms.rb
|
37
|
+
- test/geom2d/test_bounding_box.rb
|
38
|
+
- test/geom2d/test_point.rb
|
39
|
+
- test/geom2d/test_polygon.rb
|
40
|
+
- test/geom2d/test_polygon_set.rb
|
41
|
+
- test/geom2d/test_segment.rb
|
42
|
+
- test/geom2d/utils/test_sorted_linked_list.rb
|
43
|
+
- test/test_helper.rb
|
44
|
+
homepage: https://geom2d.gettalong.org
|
45
|
+
licenses:
|
46
|
+
- MIT
|
47
|
+
metadata: {}
|
48
|
+
post_install_message:
|
49
|
+
rdoc_options: []
|
50
|
+
require_paths:
|
51
|
+
- lib
|
52
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '2.4'
|
57
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
requirements: []
|
63
|
+
rubyforge_project:
|
64
|
+
rubygems_version: 2.7.3
|
65
|
+
signing_key:
|
66
|
+
specification_version: 4
|
67
|
+
summary: Objects and Algorithms for 2D Geometry
|
68
|
+
test_files: []
|