mageo 0.0.5 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGES +13 -6
- data/Gemfile +1 -1
- data/VERSION +1 -1
- data/lib/mageo/cylinder.rb +3 -3
- data/lib/mageo/octahedron.rb +52 -52
- data/lib/mageo/polyhedron.rb +91 -100
- data/lib/mageo/tetrahedron.rb +112 -17
- data/lib/mageo/triangle.rb +13 -11
- data/mageo.gemspec +6 -6
- data/test/test_cylinder.rb +2 -1
- data/test/test_octahedron.rb +150 -154
- data/test/test_polar3d.rb +4 -1
- data/test/test_polyhedron.rb +15 -15
- data/test/test_tetrahedron.rb +29 -37
- data/test/test_triangle.rb +20 -29
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dc129222136be210ace8328833a4b272b80bab07
|
4
|
+
data.tar.gz: 386f5136658c132cf9c48320bcdf0495ab3b57be
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 230eb8e8e7a14edfaa68b5fc984c2e4fb8c791451c0db9fc844a8e09ba2afaa4414108f43c708e47356a0394c256e807174a0c87759001c9cf713d037e0f068f
|
7
|
+
data.tar.gz: 1a145a6ea3aa43da7e4aca3de2135315f31b33211d704185ff7d5beb25856b178e34e151aab5b887b121b6cc6d828479c81f0cefa0d1c47c5df0e1f408c382f6
|
data/CHANGES
CHANGED
@@ -1,15 +1,22 @@
|
|
1
1
|
= mageo changelog
|
2
2
|
|
3
|
-
|
3
|
+
<!-- master -->
|
4
4
|
|
5
|
-
== Version
|
5
|
+
== Version 0.1.0 [2016-07-12] released
|
6
|
+
|
7
|
+
* Cylinder#initialize, argument positions to position0 and position1
|
8
|
+
* Triangle#initialize, vertices to (v0, v1, v3)
|
9
|
+
* Mageo::Tetrahedron; @vertex_indices_of_triangles was changed to VERTEX_INDICES_OF_TRIANGLES
|
10
|
+
* Polyhedron and Octahedron class was obsoleted
|
11
|
+
|
12
|
+
== Version 0.0.5 [2016-05-09] released
|
6
13
|
* Bugfix of tests.
|
7
14
|
* Delete meaningless codes.
|
8
15
|
|
9
|
-
== Version
|
16
|
+
== Version 0.0.4 [2016-03-11] released
|
10
17
|
* Mageo::Vector3D#midpoint is added
|
11
18
|
|
12
|
-
== Version
|
19
|
+
== Version 0.0.3 [2014-08-30] released
|
13
20
|
* Mageo::Vector3D#to_v3di is changed not to need an argument.
|
14
21
|
* Mageo::Vector3D#internal_coordinates is added (old to_v3di(axes)).
|
15
22
|
* Mageo::Polyhedron#translate is added.
|
@@ -17,7 +24,7 @@
|
|
17
24
|
* Mageo::Polyhedron#shared_vertices is added.
|
18
25
|
* Update dependency on otehr gems.
|
19
26
|
|
20
|
-
== Version
|
27
|
+
== Version 0.0.2 [2013-04-18] released
|
21
28
|
* Make a namespace 'Mageo'.
|
22
29
|
* Most of classes are included into the namespace 'Mageo'.
|
23
30
|
* Adjust to malge-0.0.8
|
@@ -25,7 +32,7 @@
|
|
25
32
|
* Set default value of tolerance=0.0 in argument of Polyhedron#include?
|
26
33
|
* Adjust to builtinextension-0.1.0.
|
27
34
|
|
28
|
-
== Version
|
35
|
+
== Version 0.0.1
|
29
36
|
* Change indent style from tab char to two spaces.
|
30
37
|
* Adjust to malge 0.0.2.
|
31
38
|
|
data/Gemfile
CHANGED
@@ -6,7 +6,7 @@ source "http://rubygems.org"
|
|
6
6
|
# Add dependencies to develop your gem here.
|
7
7
|
# Include everything needed to run rake, tests, features, etc.
|
8
8
|
group :development do
|
9
|
-
gem "test-unit", "~> 3.
|
9
|
+
gem "test-unit", "~> 3.2"
|
10
10
|
gem "rdoc", "~> 4.2"
|
11
11
|
gem "bundler", "~> 1.11"
|
12
12
|
gem "jeweler", "~> 2.0"
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0
|
1
|
+
0.1.0
|
data/lib/mageo/cylinder.rb
CHANGED
@@ -9,10 +9,10 @@ class Mageo::Cylinder
|
|
9
9
|
|
10
10
|
# 座標と半径
|
11
11
|
# positions は 両底面の中心座標を入れた配列。
|
12
|
-
def initialize(
|
12
|
+
def initialize(position0, position1, radius)
|
13
13
|
@positions = [
|
14
|
-
Mageo::Vector3D[*
|
15
|
-
Mageo::Vector3D[*
|
14
|
+
Mageo::Vector3D[*position0],
|
15
|
+
Mageo::Vector3D[*position1]
|
16
16
|
]
|
17
17
|
@radius = radius
|
18
18
|
end
|
data/lib/mageo/octahedron.rb
CHANGED
@@ -1,55 +1,55 @@
|
|
1
1
|
#! /usr/bin/env ruby
|
2
2
|
# coding: utf-8
|
3
3
|
|
4
|
-
|
5
|
-
class Mageo::Octahedron < Mageo::Polyhedron
|
6
|
-
|
7
|
-
class InitializeError < Exception; end
|
8
|
-
|
9
|
-
#八面体は 6個の頂点で構成されるが、これを3組の対体角で指定する。
|
10
|
-
#e.g.,
|
11
|
-
# [
|
12
|
-
# [ [ -1, 0, 0 ], [ 1, 0, 0 ] ],
|
13
|
-
# [ [ 0, -1, 0 ], [ 0, 1, 0 ] ],
|
14
|
-
# [ [ 0, 0, -1 ], [ 0, 0, 1 ] ],
|
15
|
-
# ]
|
16
|
-
#
|
17
|
-
#凸包であることのチェックは難しいのでしない。
|
18
|
-
#TODO: 頂点が重複している、面上にあるなどのチェックも本来はすべきだが、入れていない。
|
19
|
-
def initialize( pairs )
|
20
|
-
raise InitializeError if pairs.class != Array
|
21
|
-
raise InitializeError if pairs.size != 3
|
22
|
-
pairs.each do |pair|
|
23
|
-
raise InitializeError unless pair.class == Array
|
24
|
-
raise InitializeError if pair.size != 2
|
25
|
-
pair.each do |pos|
|
26
|
-
raise InitializeError if pos.size != 3
|
27
|
-
raise InitializeError unless pos.methods.include?( :[] )
|
28
|
-
raise InitializeError unless pos.methods.include?( :map )
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
pairs.flatten.each do |vertex|
|
33
|
-
raise InitializeError if vertex.class == Mageo::Vector3DInternal
|
34
|
-
end
|
35
|
-
|
36
|
-
|
37
|
-
@vertices = []
|
38
|
-
pairs.each do |pair|
|
39
|
-
pair.each do |vertex|
|
40
|
-
@vertices << vertex.to_v3d
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
@vertex_indices_of_triangles = [
|
45
|
-
[ 0, 2, 4],
|
46
|
-
[ 0, 2, 5],
|
47
|
-
[ 0, 3, 4],
|
48
|
-
[ 0, 3, 5],
|
49
|
-
[ 1, 2, 4],
|
50
|
-
[ 1, 2, 5],
|
51
|
-
[ 1, 3, 4],
|
52
|
-
[ 1, 3, 5]
|
53
|
-
]
|
54
|
-
end
|
55
|
-
end
|
4
|
+
## 3次元空間中の八面体を表現するクラス
|
5
|
+
#class Mageo::Octahedron < Mageo::Polyhedron
|
6
|
+
#
|
7
|
+
# class InitializeError < Exception; end
|
8
|
+
#
|
9
|
+
# #八面体は 6個の頂点で構成されるが、これを3組の対体角で指定する。
|
10
|
+
# #e.g.,
|
11
|
+
# # [
|
12
|
+
# # [ [ -1, 0, 0 ], [ 1, 0, 0 ] ],
|
13
|
+
# # [ [ 0, -1, 0 ], [ 0, 1, 0 ] ],
|
14
|
+
# # [ [ 0, 0, -1 ], [ 0, 0, 1 ] ],
|
15
|
+
# # ]
|
16
|
+
# #
|
17
|
+
# #凸包であることのチェックは難しいのでしない。
|
18
|
+
# #TODO: 頂点が重複している、面上にあるなどのチェックも本来はすべきだが、入れていない。
|
19
|
+
# def initialize( pairs )
|
20
|
+
# raise InitializeError if pairs.class != Array
|
21
|
+
# raise InitializeError if pairs.size != 3
|
22
|
+
# pairs.each do |pair|
|
23
|
+
# raise InitializeError unless pair.class == Array
|
24
|
+
# raise InitializeError if pair.size != 2
|
25
|
+
# pair.each do |pos|
|
26
|
+
# raise InitializeError if pos.size != 3
|
27
|
+
# raise InitializeError unless pos.methods.include?( :[] )
|
28
|
+
# raise InitializeError unless pos.methods.include?( :map )
|
29
|
+
# end
|
30
|
+
# end
|
31
|
+
#
|
32
|
+
# pairs.flatten.each do |vertex|
|
33
|
+
# raise InitializeError if vertex.class == Mageo::Vector3DInternal
|
34
|
+
# end
|
35
|
+
#
|
36
|
+
#
|
37
|
+
# @vertices = []
|
38
|
+
# pairs.each do |pair|
|
39
|
+
# pair.each do |vertex|
|
40
|
+
# @vertices << vertex.to_v3d
|
41
|
+
# end
|
42
|
+
# end
|
43
|
+
#
|
44
|
+
# @vertex_indices_of_triangles = [
|
45
|
+
# [ 0, 2, 4],
|
46
|
+
# [ 0, 2, 5],
|
47
|
+
# [ 0, 3, 4],
|
48
|
+
# [ 0, 3, 5],
|
49
|
+
# [ 1, 2, 4],
|
50
|
+
# [ 1, 2, 5],
|
51
|
+
# [ 1, 3, 4],
|
52
|
+
# [ 1, 3, 5]
|
53
|
+
# ]
|
54
|
+
# end
|
55
|
+
#end
|
data/lib/mageo/polyhedron.rb
CHANGED
@@ -5,6 +5,8 @@ require "rubygems"
|
|
5
5
|
gem "builtinextension"
|
6
6
|
require "array/includeeql.rb"
|
7
7
|
|
8
|
+
# This class is obsoleted.
|
9
|
+
#
|
8
10
|
# 多面体を表現する抽象クラス。
|
9
11
|
# 面は必ず三角形で、たとえば四角形も2つの三角形であると考える。
|
10
12
|
# initialize メソッドは subclass で再定義する。
|
@@ -20,105 +22,94 @@ require "array/includeeql.rb"
|
|
20
22
|
# see Mageo::Tetrahedron.rb
|
21
23
|
# - メインのテストは 四面体 Mageo::Tetrahedron クラスで行っている。
|
22
24
|
class Mageo::Polyhedron
|
23
|
-
attr_reader :vertices
|
24
|
-
|
25
|
-
class TypeError <
|
26
|
-
|
27
|
-
|
28
|
-
#
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
#pp
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
end
|
113
|
-
results << sv if flag
|
114
|
-
end
|
115
|
-
results
|
116
|
-
end
|
117
|
-
|
118
|
-
#private
|
119
|
-
|
120
|
-
#def vertices_include?(vertex, vertices, tolerance)
|
121
|
-
#end
|
122
|
-
|
25
|
+
# attr_reader :vertices
|
26
|
+
#
|
27
|
+
# class TypeError < StandardError; end
|
28
|
+
# class NotImplementError < StandardError; end
|
29
|
+
#
|
30
|
+
# # initialize で例外を返すことでインスタンスを生成できない抽象クラスを表現。
|
31
|
+
# # subclass で再定義する。
|
32
|
+
# def initialize()
|
33
|
+
# raise NotImplementedError, "need to define `initialize'"
|
34
|
+
# end
|
35
|
+
#
|
36
|
+
# def edges
|
37
|
+
# results = []
|
38
|
+
# triangles.each do |triangle|
|
39
|
+
# triangle.edges.each do |edge|
|
40
|
+
# results << edge unless results.include_eql?(edge)
|
41
|
+
# end
|
42
|
+
# end
|
43
|
+
# return results
|
44
|
+
# end
|
45
|
+
#
|
46
|
+
# def triangles
|
47
|
+
# results = Mageo::Tetrahedron::VERTEX_INDICES_OF_TRIANGLES.map do |indices|
|
48
|
+
# Mageo::Triangle.new( *(indices.map{|i| @vertices[i] }) )
|
49
|
+
# end
|
50
|
+
# return results
|
51
|
+
# end
|
52
|
+
#
|
53
|
+
# #面で囲まれた空間の中にあれば true を返す。
|
54
|
+
# def inside?( pos )
|
55
|
+
# raise TypeError if pos.class == Mageo::Vector3DInternal
|
56
|
+
#
|
57
|
+
# result = true
|
58
|
+
# triangles.each do |triangle|
|
59
|
+
# result = false unless triangle.same_side?( center, pos.to_v3d )
|
60
|
+
# end
|
61
|
+
# return result
|
62
|
+
# end
|
63
|
+
#
|
64
|
+
# def include?(pos, tolerance = 0.0)
|
65
|
+
# raise TypeError if pos.class == Mageo::Vector3DInternal
|
66
|
+
#
|
67
|
+
# return true if inside?( pos )
|
68
|
+
# triangles.each do |triangle|
|
69
|
+
# #pp pos
|
70
|
+
# #pp triangle
|
71
|
+
# return true if triangle.include?(pos.to_v3d, tolerance)
|
72
|
+
# end
|
73
|
+
# return false
|
74
|
+
# end
|
75
|
+
#
|
76
|
+
# #各頂点の座標の平均値を返す。
|
77
|
+
# def center
|
78
|
+
# tmp = Mageo::Vector3D[ 0.0, 0.0, 0.0 ]
|
79
|
+
# @vertices.each do |vertex|
|
80
|
+
# tmp += vertex
|
81
|
+
# end
|
82
|
+
# return tmp * ( 1.0 / @vertices.size.to_f ) # 座標の平均の算出
|
83
|
+
# end
|
84
|
+
#
|
85
|
+
# def translate!(vector)
|
86
|
+
# @vertices.map! do |pos|
|
87
|
+
# pos + vector
|
88
|
+
# end
|
89
|
+
# end
|
90
|
+
#
|
91
|
+
# def translate(vector)
|
92
|
+
# result = Marshal.load(Marshal.dump(self))
|
93
|
+
# result.translate! vector
|
94
|
+
# result
|
95
|
+
# end
|
96
|
+
#
|
97
|
+
# def shared_vertices(other, tolerance = 0.0)
|
98
|
+
# results = []
|
99
|
+
# @vertices.each do |sv|
|
100
|
+
# flag = false
|
101
|
+
# other.vertices.each do |ov|
|
102
|
+
# flag = true if (ov - sv).r <= tolerance
|
103
|
+
# end
|
104
|
+
# results << sv if flag
|
105
|
+
# end
|
106
|
+
# results
|
107
|
+
# end
|
108
|
+
#
|
109
|
+
# #private
|
110
|
+
#
|
111
|
+
# #def vertices_include?(vertex, vertices, tolerance)
|
112
|
+
# #end
|
113
|
+
#
|
123
114
|
end
|
124
115
|
|
data/lib/mageo/tetrahedron.rb
CHANGED
@@ -4,33 +4,128 @@
|
|
4
4
|
#
|
5
5
|
# 直交座標系 3次元空間内の四面体を表現するクラス。
|
6
6
|
#
|
7
|
-
class Mageo::Tetrahedron < Mageo::Polyhedron
|
7
|
+
#class Mageo::Tetrahedron < Mageo::Polyhedron
|
8
|
+
class Mageo::Tetrahedron
|
8
9
|
|
9
10
|
class InitializeError < Exception; end
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
12
|
+
VERTEX_INDICES_OF_TRIANGLES = [ [ 0, 1, 2 ], [ 1, 2, 3 ], [ 2, 3, 0 ], [ 3, 0, 1 ] ]
|
13
|
+
|
14
|
+
attr_reader :vertices
|
15
|
+
|
16
|
+
class TypeError < StandardError; end
|
17
|
+
class NotImplementError < StandardError; end
|
18
|
+
|
19
|
+
def edges
|
20
|
+
results = []
|
21
|
+
triangles.each do |triangle|
|
22
|
+
triangle.edges.each do |edge|
|
23
|
+
results << edge unless results.include_eql?(edge)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
return results
|
27
|
+
end
|
28
|
+
|
29
|
+
def triangles
|
30
|
+
results = VERTEX_INDICES_OF_TRIANGLES.map do |indices|
|
31
|
+
Mageo::Triangle.new( *(indices.map{|i| @vertices[i] }) )
|
32
|
+
end
|
33
|
+
return results
|
34
|
+
end
|
35
|
+
|
36
|
+
#面で囲まれた空間の中にあれば true を返す。
|
37
|
+
def inside?( pos )
|
38
|
+
raise TypeError if pos.class == Mageo::Vector3DInternal
|
39
|
+
|
40
|
+
result = true
|
41
|
+
triangles.each do |triangle|
|
42
|
+
result = false unless triangle.same_side?( center, pos.to_v3d )
|
43
|
+
end
|
44
|
+
return result
|
45
|
+
end
|
46
|
+
|
47
|
+
def include?(pos, tolerance = 0.0)
|
48
|
+
raise TypeError if pos.class == Mageo::Vector3DInternal
|
49
|
+
|
50
|
+
return true if inside?( pos )
|
51
|
+
triangles.each do |triangle|
|
52
|
+
#pp pos
|
53
|
+
#pp triangle
|
54
|
+
return true if triangle.include?(pos.to_v3d, tolerance)
|
55
|
+
end
|
56
|
+
return false
|
57
|
+
end
|
58
|
+
|
59
|
+
#各頂点の座標の平均値を返す。
|
60
|
+
def center
|
61
|
+
tmp = Mageo::Vector3D[ 0.0, 0.0, 0.0 ]
|
62
|
+
@vertices.each do |vertex|
|
63
|
+
tmp += vertex
|
19
64
|
end
|
65
|
+
return tmp * ( 1.0 / @vertices.size.to_f ) # 座標の平均の算出
|
66
|
+
end
|
67
|
+
|
68
|
+
def translate!(vector)
|
69
|
+
@vertices.map! do |pos|
|
70
|
+
pos + vector
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def translate(vector)
|
75
|
+
result = Marshal.load(Marshal.dump(self))
|
76
|
+
result.translate! vector
|
77
|
+
result
|
78
|
+
end
|
79
|
+
|
80
|
+
def shared_vertices(other, tolerance = 0.0)
|
81
|
+
results = []
|
82
|
+
@vertices.each do |sv|
|
83
|
+
flag = false
|
84
|
+
other.vertices.each do |ov|
|
85
|
+
flag = true if (ov - sv).r <= tolerance
|
86
|
+
end
|
87
|
+
results << sv if flag
|
88
|
+
end
|
89
|
+
results
|
90
|
+
end
|
91
|
+
|
92
|
+
#private
|
93
|
+
|
94
|
+
#def vertices_include?(vertex, vertices, tolerance)
|
95
|
+
#end
|
96
|
+
|
97
|
+
|
98
|
+
## v0, v1, v2, v3 are 四面体の頂点
|
99
|
+
def initialize( v0, v1, v2, v3 )
|
100
|
+
#raise InitializeError if vertices.class != Array
|
101
|
+
#raise InitializeError if vertices.size != 4
|
102
|
+
#vertices.each do |vertex|
|
103
|
+
# raise InitializeError if vertex.size != 3
|
104
|
+
# raise InitializeError unless vertex.methods.include?( :[] )
|
105
|
+
# raise InitializeError unless vertex.methods.include?( :map )
|
106
|
+
#end
|
107
|
+
#@vertices = vertices.map { |vertex| vertex.to_v3d }
|
108
|
+
vertices = [v0, v1, v2, v3]
|
20
109
|
vertices.each do |vertex|
|
21
110
|
raise InitializeError if vertex.class == Mageo::Vector3DInternal
|
22
111
|
end
|
23
112
|
|
24
|
-
@vertices = vertices.map {
|
25
|
-
|
26
|
-
@vertex_indices_of_triangles = [
|
27
|
-
[ 0, 1, 2 ],
|
28
|
-
[ 1, 2, 3 ],
|
29
|
-
[ 2, 3, 0 ],
|
30
|
-
[ 3, 0, 1 ],
|
31
|
-
]
|
113
|
+
@vertices = vertices.map {|v| v.to_v3d}
|
32
114
|
|
33
115
|
raise InitializeError, "volume is zero." if volume == 0.0
|
34
116
|
end
|
117
|
+
|
118
|
+
# 体積を返す
|
119
|
+
def volume
|
120
|
+
result = 0.0
|
121
|
+
[ [ 0, 1, 2 ], [ 1, 2, 3 ], [ 2, 3, 0 ], [ 3, 0, 1 ] ].each do |tri_vertices|
|
122
|
+
vectors = tri_vertices.map { |i| @vertices[i] - center }
|
123
|
+
volume = Mageo::Vector3D.scalar_triple_product( *vectors ).abs
|
124
|
+
volume /= 6.0
|
125
|
+
result += volume
|
126
|
+
end
|
127
|
+
return result
|
128
|
+
end
|
129
|
+
|
35
130
|
end
|
36
131
|
|
data/lib/mageo/triangle.rb
CHANGED
@@ -22,17 +22,19 @@ class Mageo::Triangle
|
|
22
22
|
#座標が整数で入っていたとしても内部的には Float に変換して使用する。
|
23
23
|
#3点が1直線上に並んでいて三角形を囲まない場合は
|
24
24
|
#例外 Mageo::Triangle::LinearException を投げる。
|
25
|
-
def initialize( vertices )
|
26
|
-
|
27
|
-
raise InitializeError
|
28
|
-
vertices.
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
25
|
+
#def initialize( vertices )
|
26
|
+
def initialize( v0, v1, v2 )
|
27
|
+
#raise InitializeError unless vertices.methods.include?( :size )
|
28
|
+
#raise InitializeError if vertices.size != 3
|
29
|
+
#vertices.each do |pos|
|
30
|
+
# raise InitializeError if pos.size != 3
|
31
|
+
# raise InitializeError unless pos.methods.include?( :[] )
|
32
|
+
# raise InitializeError unless pos.methods.include?( :map )
|
33
|
+
#end
|
34
|
+
#@vertices = vertices.map do |pos|
|
35
|
+
# ( pos.map { |i| i.to_f }) . to_v3d
|
36
|
+
#end
|
37
|
+
@vertices = [v0.to_v3d, v1.to_v3d, v2.to_v3d]
|
36
38
|
|
37
39
|
#Checking on linear.
|
38
40
|
edge1 = @vertices[1] - @vertices[0]
|
data/mageo.gemspec
CHANGED
@@ -2,16 +2,16 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: mageo 0.0
|
5
|
+
# stub: mageo 0.1.0 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "mageo"
|
9
|
-
s.version = "0.0
|
9
|
+
s.version = "0.1.0"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib"]
|
13
13
|
s.authors = ["ippei94da"]
|
14
|
-
s.date = "2016-
|
14
|
+
s.date = "2016-07-12"
|
15
15
|
s.description = "MAth GEOmetry library to deal with 2 and 3 dimensional spaces.\n Cartesian and internal coordinate systems can be used.\n This includes besic objects in 3 dimensional space.\n "
|
16
16
|
s.email = "ippei94da@gmail.com"
|
17
17
|
s.extra_rdoc_files = [
|
@@ -65,7 +65,7 @@ Gem::Specification.new do |s|
|
|
65
65
|
s.specification_version = 4
|
66
66
|
|
67
67
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
68
|
-
s.add_development_dependency(%q<test-unit>, ["~> 3.
|
68
|
+
s.add_development_dependency(%q<test-unit>, ["~> 3.2"])
|
69
69
|
s.add_development_dependency(%q<rdoc>, ["~> 4.2"])
|
70
70
|
s.add_development_dependency(%q<bundler>, ["~> 1.11"])
|
71
71
|
s.add_development_dependency(%q<jeweler>, ["~> 2.0"])
|
@@ -73,7 +73,7 @@ Gem::Specification.new do |s|
|
|
73
73
|
s.add_development_dependency(%q<builtinextension>, ["~> 0.1"])
|
74
74
|
s.add_development_dependency(%q<malge>, ["~> 0.0"])
|
75
75
|
else
|
76
|
-
s.add_dependency(%q<test-unit>, ["~> 3.
|
76
|
+
s.add_dependency(%q<test-unit>, ["~> 3.2"])
|
77
77
|
s.add_dependency(%q<rdoc>, ["~> 4.2"])
|
78
78
|
s.add_dependency(%q<bundler>, ["~> 1.11"])
|
79
79
|
s.add_dependency(%q<jeweler>, ["~> 2.0"])
|
@@ -82,7 +82,7 @@ Gem::Specification.new do |s|
|
|
82
82
|
s.add_dependency(%q<malge>, ["~> 0.0"])
|
83
83
|
end
|
84
84
|
else
|
85
|
-
s.add_dependency(%q<test-unit>, ["~> 3.
|
85
|
+
s.add_dependency(%q<test-unit>, ["~> 3.2"])
|
86
86
|
s.add_dependency(%q<rdoc>, ["~> 4.2"])
|
87
87
|
s.add_dependency(%q<bundler>, ["~> 1.11"])
|
88
88
|
s.add_dependency(%q<jeweler>, ["~> 2.0"])
|
data/test/test_cylinder.rb
CHANGED
@@ -9,7 +9,8 @@ require "helper"
|
|
9
9
|
|
10
10
|
class TC_Cylinder < Test::Unit::TestCase
|
11
11
|
def setup
|
12
|
-
|
12
|
+
#@c00 = Mageo::Cylinder.new([[0.0, 1.0, 2.0], [1.0, 2.0, 3.0]], 3.0)
|
13
|
+
@c00 = Mageo::Cylinder.new([0.0, 1.0, 2.0], [1.0, 2.0, 3.0], 3.0)
|
13
14
|
end
|
14
15
|
|
15
16
|
def test_initialize
|
data/test/test_octahedron.rb
CHANGED
@@ -1,154 +1,150 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
require "helper"
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
class Mageo::Octahedron
|
9
|
-
public :center
|
10
|
-
end
|
11
|
-
|
12
|
-
class TC_Octahedron < Test::Unit::TestCase
|
13
|
-
$tolerance = 10**(-10)
|
14
|
-
|
15
|
-
V_X_PLUS = Mageo::Vector3D[ 1, 0, 0 ]
|
16
|
-
V_Y_PLUS = Mageo::Vector3D[ 0, 1, 0 ]
|
17
|
-
V_Z_PLUS = Mageo::Vector3D[ 0, 0, 1 ]
|
18
|
-
|
19
|
-
V_X_MINUS = Mageo::Vector3D[ -1, 0, 0 ]
|
20
|
-
V_Y_MINUS = Mageo::Vector3D[ 0, -1, 0 ]
|
21
|
-
V_Z_MINUS = Mageo::Vector3D[ 0, 0, -1 ]
|
22
|
-
|
23
|
-
def setup
|
24
|
-
@o00 = Mageo::Octahedron.new(
|
25
|
-
[ [V_X_MINUS, V_X_PLUS ],
|
26
|
-
[V_Y_MINUS, V_Y_PLUS ],
|
27
|
-
[V_Z_MINUS, V_Z_PLUS ] ]
|
28
|
-
)
|
29
|
-
@o01 = Mageo::Octahedron.new(
|
30
|
-
[ [ [ -0.5, 0.5, 0.5 ], [ 1.5, 0.5, 0.5 ] ],
|
31
|
-
[ [ 0.5, -0.5, 0.5 ], [ 0.5, 1.5, 0.5 ] ],
|
32
|
-
[ [ 0.5, 0.5, -0.5 ], [ 0.5, 0.5, 1.5 ] ] ]
|
33
|
-
)
|
34
|
-
end
|
35
|
-
|
36
|
-
def test_initialize
|
37
|
-
assert_raise( ArgumentError ){ Mageo::Octahedron.new }
|
38
|
-
assert_raise( ArgumentError ){ Mageo::Octahedron.new() }
|
39
|
-
assert_raise( Mageo::Octahedron::InitializeError ){ Mageo::Octahedron.new( nil ) }
|
40
|
-
assert_raise( Mageo::Octahedron::InitializeError ){ Mageo::Octahedron.new( [] ) }
|
41
|
-
assert_raise( Mageo::Octahedron::InitializeError ){ Mageo::Octahedron.new( [ 0, 1, 2 ] ) }
|
42
|
-
assert_raise( Mageo::Octahedron::InitializeError ){ Mageo::Octahedron.new( [ [], [], [] ] ) }
|
43
|
-
assert_raise( Mageo::Octahedron::InitializeError ){
|
44
|
-
Mageo::Octahedron.new(
|
45
|
-
[ [ V_X_MINUS, V_X_PLUS ],
|
46
|
-
[ V_Y_MINUS, V_Y_PLUS ],
|
47
|
-
[ V_Z_MINUS, [ 0, 0 ] ]
|
48
|
-
]
|
49
|
-
)
|
50
|
-
}
|
51
|
-
assert_raise( Mageo::Octahedron::InitializeError ){
|
52
|
-
Mageo::Octahedron.new(
|
53
|
-
[ [ V_X_MINUS, V_X_PLUS],
|
54
|
-
[ V_Y_MINUS, [ 0, 1, 0, 2 ] ],
|
55
|
-
[ V_Z_MINUS, V_Z_PLUS ]
|
56
|
-
]
|
57
|
-
)
|
58
|
-
}
|
59
|
-
assert_raise( Mageo::Octahedron::InitializeError ){
|
60
|
-
Mageo::Octahedron.new(
|
61
|
-
[ [ V_X_MINUS, V_X_PLUS ],
|
62
|
-
[ V_Y_MINUS, V_Y_PLUS ],
|
63
|
-
[ V_Z_MINUS, V_Z_PLUS ],
|
64
|
-
[ [ -5, -5, -5 ], [ 5, 5, 5 ] ]
|
65
|
-
]
|
66
|
-
)
|
67
|
-
}
|
68
|
-
|
69
|
-
assert_raise( Mageo::Octahedron::InitializeError ){
|
70
|
-
Mageo::Octahedron.new(
|
71
|
-
[ [ Mageo::Vector3DInternal[ -0.5, 0.5, 0.5 ], Mageo::Vector3DInternal[ 1.5, 0.5, 0.5 ] ],
|
72
|
-
[ Mageo::Vector3DInternal[ 0.5, -0.5, 0.5 ], Mageo::Vector3DInternal[ 0.5, 1.5, 0.5 ] ],
|
73
|
-
[ Mageo::Vector3DInternal[ 0.5, 0.5, -0.5 ], Mageo::Vector3DInternal[ 0.5, 0.5, 1.5 ] ] ]
|
74
|
-
)
|
75
|
-
}
|
76
|
-
|
77
|
-
assert_nothing_raised{
|
78
|
-
Mageo::Octahedron.new(
|
79
|
-
[ [ Mageo::Vector3D[ -0.5, 0.5, 0.5 ], Mageo::Vector3D[ 1.5, 0.5, 0.5 ] ],
|
80
|
-
[ Mageo::Vector3D[ 0.5, -0.5, 0.5 ], Mageo::Vector3D[ 0.5, 1.5, 0.5 ] ],
|
81
|
-
[ Mageo::Vector3D[ 0.5, 0.5, -0.5 ], Mageo::Vector3D[ 0.5, 0.5, 1.5 ] ] ]
|
82
|
-
)
|
83
|
-
}
|
84
|
-
end
|
85
|
-
|
86
|
-
def test_inside?
|
87
|
-
assert_equal( true , @o00.inside?( [0.0, 0.2, 0.4] ) )
|
88
|
-
assert_equal( false, @o00.inside?( [1.0, 0.0, 0.0] ) ) #境界上
|
89
|
-
assert_equal( false, @o00.inside?( [2.0, 0.2, 0.4] ) )
|
90
|
-
end
|
91
|
-
|
92
|
-
def test_include?
|
93
|
-
assert_equal( true , @o00.include?( [0.0, 0.2, 0.4], $tolerance ) )
|
94
|
-
assert_equal( true , @o00.include?( [1.0, 0.0, 0.0], $tolerance ) ) #境界上
|
95
|
-
assert_equal( true , @o00.include?( [1.0, 0.0, 0.0] ) ) #境界上, no tolerance
|
96
|
-
assert_equal( false, @o00.include?( [2.0, 0.2, 0.4], $tolerance ) )
|
97
|
-
end
|
98
|
-
|
99
|
-
def
|
100
|
-
assert_in_delta(
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
assert_in_delta( 0.
|
105
|
-
assert_in_delta( 0.
|
106
|
-
assert_in_delta( 0.
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
t
|
115
|
-
assert_equal(
|
116
|
-
assert_equal(
|
117
|
-
assert_equal(
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
t
|
126
|
-
assert_equal(
|
127
|
-
assert_equal(true, t.include_eql?(Mageo::Triangle.new([
|
128
|
-
assert_equal(true, t.include_eql?(Mageo::Triangle.new([
|
129
|
-
assert_equal(true, t.include_eql?(Mageo::Triangle.new([
|
130
|
-
assert_equal(true, t.include_eql?(Mageo::Triangle.new([
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
t
|
139
|
-
assert_equal(
|
140
|
-
assert_equal(true, (t.include_eql?(Mageo::Segment.new(
|
141
|
-
assert_equal(true, (t.include_eql?(Mageo::Segment.new(
|
142
|
-
assert_equal(true, (t.include_eql?(Mageo::Segment.new(
|
143
|
-
assert_equal(true, (t.include_eql?(Mageo::Segment.new(
|
144
|
-
assert_equal(true, (t.include_eql?(Mageo::Segment.new(
|
145
|
-
assert_equal(true, (t.include_eql?(Mageo::Segment.new(
|
146
|
-
assert_equal(true, (t.include_eql?(Mageo::Segment.new(
|
147
|
-
assert_equal(true, (t.include_eql?(Mageo::Segment.new(
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
assert_equal(true, (t.include_eql?(Mageo::Segment.new(V_Y_MINUS, V_Z_MINUS))))
|
152
|
-
end
|
153
|
-
end
|
154
|
-
|
1
|
+
##! /usr/bin/env ruby
|
2
|
+
## coding: utf-8
|
3
|
+
#
|
4
|
+
#require "helper"
|
5
|
+
##gem "builtinextension"
|
6
|
+
##require "array/includeeql.rb"
|
7
|
+
#
|
8
|
+
#class Mageo::Octahedron
|
9
|
+
# public :center
|
10
|
+
#end
|
11
|
+
#
|
12
|
+
#class TC_Octahedron < Test::Unit::TestCase
|
13
|
+
# $tolerance = 10**(-10)
|
14
|
+
#
|
15
|
+
# V_X_PLUS = Mageo::Vector3D[ 1, 0, 0 ]
|
16
|
+
# V_Y_PLUS = Mageo::Vector3D[ 0, 1, 0 ]
|
17
|
+
# V_Z_PLUS = Mageo::Vector3D[ 0, 0, 1 ]
|
18
|
+
#
|
19
|
+
# V_X_MINUS = Mageo::Vector3D[ -1, 0, 0 ]
|
20
|
+
# V_Y_MINUS = Mageo::Vector3D[ 0, -1, 0 ]
|
21
|
+
# V_Z_MINUS = Mageo::Vector3D[ 0, 0, -1 ]
|
22
|
+
#
|
23
|
+
# def setup
|
24
|
+
# @o00 = Mageo::Octahedron.new(
|
25
|
+
# [ [V_X_MINUS, V_X_PLUS ],
|
26
|
+
# [V_Y_MINUS, V_Y_PLUS ],
|
27
|
+
# [V_Z_MINUS, V_Z_PLUS ] ]
|
28
|
+
# )
|
29
|
+
# @o01 = Mageo::Octahedron.new(
|
30
|
+
# [ [ [ -0.5, 0.5, 0.5 ], [ 1.5, 0.5, 0.5 ] ],
|
31
|
+
# [ [ 0.5, -0.5, 0.5 ], [ 0.5, 1.5, 0.5 ] ],
|
32
|
+
# [ [ 0.5, 0.5, -0.5 ], [ 0.5, 0.5, 1.5 ] ] ]
|
33
|
+
# )
|
34
|
+
# end
|
35
|
+
#
|
36
|
+
# def test_initialize
|
37
|
+
# assert_raise( ArgumentError ){ Mageo::Octahedron.new }
|
38
|
+
# assert_raise( ArgumentError ){ Mageo::Octahedron.new() }
|
39
|
+
# assert_raise( Mageo::Octahedron::InitializeError ){ Mageo::Octahedron.new( nil ) }
|
40
|
+
# assert_raise( Mageo::Octahedron::InitializeError ){ Mageo::Octahedron.new( [] ) }
|
41
|
+
# assert_raise( Mageo::Octahedron::InitializeError ){ Mageo::Octahedron.new( [ 0, 1, 2 ] ) }
|
42
|
+
# assert_raise( Mageo::Octahedron::InitializeError ){ Mageo::Octahedron.new( [ [], [], [] ] ) }
|
43
|
+
# assert_raise( Mageo::Octahedron::InitializeError ){
|
44
|
+
# Mageo::Octahedron.new(
|
45
|
+
# [ [ V_X_MINUS, V_X_PLUS ],
|
46
|
+
# [ V_Y_MINUS, V_Y_PLUS ],
|
47
|
+
# [ V_Z_MINUS, [ 0, 0 ] ]
|
48
|
+
# ]
|
49
|
+
# )
|
50
|
+
# }
|
51
|
+
# assert_raise( Mageo::Octahedron::InitializeError ){
|
52
|
+
# Mageo::Octahedron.new(
|
53
|
+
# [ [ V_X_MINUS, V_X_PLUS],
|
54
|
+
# [ V_Y_MINUS, [ 0, 1, 0, 2 ] ],
|
55
|
+
# [ V_Z_MINUS, V_Z_PLUS ]
|
56
|
+
# ]
|
57
|
+
# )
|
58
|
+
# }
|
59
|
+
# assert_raise( Mageo::Octahedron::InitializeError ){
|
60
|
+
# Mageo::Octahedron.new(
|
61
|
+
# [ [ V_X_MINUS, V_X_PLUS ],
|
62
|
+
# [ V_Y_MINUS, V_Y_PLUS ],
|
63
|
+
# [ V_Z_MINUS, V_Z_PLUS ],
|
64
|
+
# [ [ -5, -5, -5 ], [ 5, 5, 5 ] ]
|
65
|
+
# ]
|
66
|
+
# )
|
67
|
+
# }
|
68
|
+
#
|
69
|
+
# assert_raise( Mageo::Octahedron::InitializeError ){
|
70
|
+
# Mageo::Octahedron.new(
|
71
|
+
# [ [ Mageo::Vector3DInternal[ -0.5, 0.5, 0.5 ], Mageo::Vector3DInternal[ 1.5, 0.5, 0.5 ] ],
|
72
|
+
# [ Mageo::Vector3DInternal[ 0.5, -0.5, 0.5 ], Mageo::Vector3DInternal[ 0.5, 1.5, 0.5 ] ],
|
73
|
+
# [ Mageo::Vector3DInternal[ 0.5, 0.5, -0.5 ], Mageo::Vector3DInternal[ 0.5, 0.5, 1.5 ] ] ]
|
74
|
+
# )
|
75
|
+
# }
|
76
|
+
#
|
77
|
+
# assert_nothing_raised{
|
78
|
+
# Mageo::Octahedron.new(
|
79
|
+
# [ [ Mageo::Vector3D[ -0.5, 0.5, 0.5 ], Mageo::Vector3D[ 1.5, 0.5, 0.5 ] ],
|
80
|
+
# [ Mageo::Vector3D[ 0.5, -0.5, 0.5 ], Mageo::Vector3D[ 0.5, 1.5, 0.5 ] ],
|
81
|
+
# [ Mageo::Vector3D[ 0.5, 0.5, -0.5 ], Mageo::Vector3D[ 0.5, 0.5, 1.5 ] ] ]
|
82
|
+
# )
|
83
|
+
# }
|
84
|
+
# end
|
85
|
+
#
|
86
|
+
# def test_inside?
|
87
|
+
# assert_equal( true , @o00.inside?( [0.0, 0.2, 0.4] ) )
|
88
|
+
# assert_equal( false, @o00.inside?( [1.0, 0.0, 0.0] ) ) #境界上
|
89
|
+
# assert_equal( false, @o00.inside?( [2.0, 0.2, 0.4] ) )
|
90
|
+
# end
|
91
|
+
#
|
92
|
+
# def test_include?
|
93
|
+
# assert_equal( true , @o00.include?( [0.0, 0.2, 0.4], $tolerance ) )
|
94
|
+
# assert_equal( true , @o00.include?( [1.0, 0.0, 0.0], $tolerance ) ) #境界上
|
95
|
+
# assert_equal( true , @o00.include?( [1.0, 0.0, 0.0] ) ) #境界上, no tolerance
|
96
|
+
# assert_equal( false, @o00.include?( [2.0, 0.2, 0.4], $tolerance ) )
|
97
|
+
# end
|
98
|
+
#
|
99
|
+
# def test_center
|
100
|
+
# assert_in_delta( 0.0, @o00.center[0], $tolerance)
|
101
|
+
# assert_in_delta( 0.0, @o00.center[1], $tolerance)
|
102
|
+
# assert_in_delta( 0.0, @o00.center[2], $tolerance)
|
103
|
+
#
|
104
|
+
# assert_in_delta( 0.5, @o01.center[0], $tolerance)
|
105
|
+
# assert_in_delta( 0.5, @o01.center[1], $tolerance)
|
106
|
+
# assert_in_delta( 0.5, @o01.center[2], $tolerance)
|
107
|
+
# end
|
108
|
+
#
|
109
|
+
# def test_vertices
|
110
|
+
# t = @o00.vertices
|
111
|
+
# assert_equal(6, t.size)
|
112
|
+
# assert_equal(V_X_MINUS, t[0])
|
113
|
+
# assert_equal(V_X_PLUS , t[1])
|
114
|
+
# assert_equal(V_Y_MINUS, t[2])
|
115
|
+
# assert_equal(V_Y_PLUS , t[3])
|
116
|
+
# assert_equal(V_Z_MINUS, t[4])
|
117
|
+
# assert_equal(V_Z_PLUS , t[5])
|
118
|
+
# end
|
119
|
+
#
|
120
|
+
# def test_triangles
|
121
|
+
# t = @o00.triangles
|
122
|
+
# assert_equal(8, t.size)
|
123
|
+
# assert_equal(true, t.include_eql?(Mageo::Triangle.new([V_X_PLUS, V_Y_PLUS, V_Z_PLUS])))
|
124
|
+
# assert_equal(true, t.include_eql?(Mageo::Triangle.new([V_X_PLUS, V_Y_PLUS, V_Z_MINUS])))
|
125
|
+
# assert_equal(true, t.include_eql?(Mageo::Triangle.new([V_X_PLUS, V_Y_MINUS, V_Z_PLUS])))
|
126
|
+
# assert_equal(true, t.include_eql?(Mageo::Triangle.new([V_X_PLUS, V_Y_MINUS, V_Z_MINUS])))
|
127
|
+
# assert_equal(true, t.include_eql?(Mageo::Triangle.new([V_X_MINUS, V_Y_PLUS, V_Z_PLUS])))
|
128
|
+
# assert_equal(true, t.include_eql?(Mageo::Triangle.new([V_X_MINUS, V_Y_PLUS, V_Z_MINUS])))
|
129
|
+
# assert_equal(true, t.include_eql?(Mageo::Triangle.new([V_X_MINUS, V_Y_MINUS, V_Z_PLUS])))
|
130
|
+
# assert_equal(true, t.include_eql?(Mageo::Triangle.new([V_X_MINUS, V_Y_MINUS, V_Z_MINUS])))
|
131
|
+
# end
|
132
|
+
#
|
133
|
+
# def test_edges
|
134
|
+
# t = @o00.edges
|
135
|
+
# assert_equal(12, t.size)
|
136
|
+
# assert_equal(true, (t.include_eql?(Mageo::Segment.new(V_X_PLUS , V_Y_PLUS))))
|
137
|
+
# assert_equal(true, (t.include_eql?(Mageo::Segment.new(V_X_PLUS , V_Y_MINUS))))
|
138
|
+
# assert_equal(true, (t.include_eql?(Mageo::Segment.new(V_X_PLUS , V_Z_PLUS))))
|
139
|
+
# assert_equal(true, (t.include_eql?(Mageo::Segment.new(V_X_PLUS , V_Z_MINUS))))
|
140
|
+
# assert_equal(true, (t.include_eql?(Mageo::Segment.new(V_X_MINUS, V_Y_PLUS))))
|
141
|
+
# assert_equal(true, (t.include_eql?(Mageo::Segment.new(V_X_MINUS, V_Y_MINUS))))
|
142
|
+
# assert_equal(true, (t.include_eql?(Mageo::Segment.new(V_X_MINUS, V_Z_PLUS))))
|
143
|
+
# assert_equal(true, (t.include_eql?(Mageo::Segment.new(V_X_MINUS, V_Z_MINUS))))
|
144
|
+
# assert_equal(true, (t.include_eql?(Mageo::Segment.new(V_Y_PLUS , V_Z_PLUS))))
|
145
|
+
# assert_equal(true, (t.include_eql?(Mageo::Segment.new(V_Y_PLUS , V_Z_MINUS))))
|
146
|
+
# assert_equal(true, (t.include_eql?(Mageo::Segment.new(V_Y_MINUS, V_Z_PLUS))))
|
147
|
+
# assert_equal(true, (t.include_eql?(Mageo::Segment.new(V_Y_MINUS, V_Z_MINUS))))
|
148
|
+
# end
|
149
|
+
#end
|
150
|
+
#
|
data/test/test_polar3d.rb
CHANGED
@@ -19,6 +19,10 @@ class TC_Polar3D < Test::Unit::TestCase
|
|
19
19
|
@p3d03 = Mageo::Polar3D.new( 2.0, 0.25*PI, 0.25*PI)
|
20
20
|
end
|
21
21
|
|
22
|
+
#def test_self_polar2cartesian
|
23
|
+
#
|
24
|
+
#end
|
25
|
+
|
22
26
|
def test_to_v3d
|
23
27
|
assert_equal( Mageo::Vector3D, @p3d00.to_v3d.class )
|
24
28
|
assert_in_delta( 0.0, @p3d00.to_v3d[0], $tolerance )
|
@@ -40,7 +44,6 @@ class TC_Polar3D < Test::Unit::TestCase
|
|
40
44
|
assert_in_delta( 1.0 , @p3d03.to_v3d[0], $tolerance)
|
41
45
|
assert_in_delta( 1.0 , @p3d03.to_v3d[1], $tolerance)
|
42
46
|
assert_in_delta( Math::sqrt(2.0), @p3d03.to_v3d[2], $tolerance )
|
43
|
-
|
44
47
|
end
|
45
48
|
|
46
49
|
def test_minimize_phi!
|
data/test/test_polyhedron.rb
CHANGED
@@ -1,15 +1,15 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
require "helper"
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
class TC_Polyhedron < Test::Unit::TestCase
|
12
|
-
def test_initialize
|
13
|
-
assert_raise( NotImplementedError ) { Mageo::Polyhedron.new }
|
14
|
-
end
|
15
|
-
end
|
1
|
+
##! /usr/bin/env ruby
|
2
|
+
## coding: utf-8
|
3
|
+
#
|
4
|
+
##require "test/unit"
|
5
|
+
#require "helper"
|
6
|
+
##require 'mageo.rb'
|
7
|
+
##require "mageo/polyhedron.rb"
|
8
|
+
#
|
9
|
+
## initialize でインスタンスを生成できないことのみテストする。
|
10
|
+
## その他の機能はサブクラスでテスト。
|
11
|
+
#class TC_Polyhedron < Test::Unit::TestCase
|
12
|
+
# def test_initialize
|
13
|
+
# assert_raise( NotImplementedError ) { Mageo::Polyhedron.new }
|
14
|
+
# end
|
15
|
+
#end
|
data/test/test_tetrahedron.rb
CHANGED
@@ -27,48 +27,42 @@ class TC_Tetrahedron < Test::Unit::TestCase
|
|
27
27
|
V_13 = Mageo::Vector3D[10.0,20.0, 0.0]
|
28
28
|
|
29
29
|
def setup
|
30
|
-
@t00 = Mageo::Tetrahedron.new(
|
31
|
-
@t01 = Mageo::Tetrahedron.new(
|
30
|
+
@t00 = Mageo::Tetrahedron.new(V_00, V_01, V_02, V_03)
|
31
|
+
@t01 = Mageo::Tetrahedron.new(V_10, V_11, V_12, V_13)
|
32
32
|
end
|
33
33
|
|
34
34
|
def test_initialize
|
35
35
|
assert_raise( ArgumentError ){ Mageo::Tetrahedron.new }
|
36
36
|
assert_raise( ArgumentError ){ Mageo::Tetrahedron.new() }
|
37
|
-
assert_raise( Mageo::Tetrahedron::InitializeError ){ Mageo::Tetrahedron.new( nil ) }
|
38
|
-
assert_raise( Mageo::Tetrahedron::InitializeError ){ Mageo::Tetrahedron.new( [] ) }
|
39
|
-
assert_raise( Mageo::Tetrahedron::InitializeError ){ Mageo::Tetrahedron.new(
|
40
|
-
assert_raise( Mageo::Tetrahedron::InitializeError ){ Mageo::Tetrahedron.new( [ [], [], [], [] ] ) }
|
41
|
-
assert_raise( Mageo::Tetrahedron::InitializeError ){
|
42
|
-
|
43
|
-
}
|
44
|
-
assert_raise( Mageo::Tetrahedron::InitializeError ){
|
45
|
-
|
46
|
-
}
|
37
|
+
#assert_raise( Mageo::Tetrahedron::InitializeError ){ Mageo::Tetrahedron.new( nil ) }
|
38
|
+
#assert_raise( Mageo::Tetrahedron::InitializeError ){ Mageo::Tetrahedron.new( [] ) }
|
39
|
+
#assert_raise( Mageo::Tetrahedron::InitializeError ){ Mageo::Tetrahedron.new( 0, 1, 2, 3 ) }
|
40
|
+
#assert_raise( Mageo::Tetrahedron::InitializeError ){ Mageo::Tetrahedron.new( [ [], [], [], [] ] ) }
|
41
|
+
#assert_raise( Mageo::Tetrahedron::InitializeError ){
|
42
|
+
# Mageo::Tetrahedron.new(V_00, V_01, V_02, [ 0.0, 0.0 ])
|
43
|
+
#}
|
44
|
+
#assert_raise( Mageo::Tetrahedron::InitializeError ){
|
45
|
+
# Mageo::Tetrahedron.new(V_00, V_01, V_02, [ 0.0, 0.0, 1.0, 0.0 ])
|
46
|
+
#}
|
47
47
|
|
48
|
-
# 5点ある
|
49
|
-
assert_raise( Mageo::Tetrahedron::InitializeError ){
|
50
|
-
Mageo::Tetrahedron.new( [ V_00, V_01, V_02, V_03, [ 1.0, 1.0, 1.0] ])
|
51
|
-
}
|
52
|
-
|
53
48
|
# 体積が 0.0 になるのはエラー
|
54
49
|
assert_raise( Mageo::Tetrahedron::InitializeError ){
|
55
|
-
Mageo::Tetrahedron.new(
|
50
|
+
Mageo::Tetrahedron.new(V_00, V_01, V_02, [ 2.0, 2.0, 0.0])
|
56
51
|
}
|
57
52
|
|
58
53
|
# Mageo::Vector3DInternal なら 例外
|
59
54
|
assert_raise( Mageo::Tetrahedron::InitializeError ){
|
60
|
-
Mageo::Tetrahedron.new(
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
]
|
55
|
+
Mageo::Tetrahedron.new(
|
56
|
+
Mageo::Vector3DInternal[ 0.0, 0.0, 0.0],
|
57
|
+
Mageo::Vector3DInternal[ 1.0, 0.0, 0.0],
|
58
|
+
Mageo::Vector3DInternal[ 0.0, 1.0, 0.0],
|
59
|
+
Mageo::Vector3DInternal[ 0.0, 0.0, 1.0]
|
66
60
|
)
|
67
61
|
}
|
68
62
|
|
69
63
|
# Mageo::Vector3D なら OK
|
70
64
|
assert_nothing_raised{
|
71
|
-
Mageo::Tetrahedron.new(
|
65
|
+
Mageo::Tetrahedron.new( V_00, V_01, V_02, V_03)
|
72
66
|
}
|
73
67
|
end
|
74
68
|
|
@@ -78,7 +72,6 @@ class TC_Tetrahedron < Test::Unit::TestCase
|
|
78
72
|
assert_equal( false, @t00.inside?( [-5.0,-5.0,-5.0] ) )
|
79
73
|
assert_equal( false, @t00.inside?( [ 0.0, 0.0, 0.0] ) ) #頂点上
|
80
74
|
|
81
|
-
assert_raise(Mageo::Polyhedron::TypeError){@t00.inside?(Mageo::Vector3DInternal[1.0, 1.0, 1.0])}
|
82
75
|
assert_raise(Mageo::Tetrahedron::TypeError){@t00.inside?(Mageo::Vector3DInternal[1.0, 1.0, 1.0])}
|
83
76
|
#pp Mageo::Polyhedron::TypeError.ancestors
|
84
77
|
#pp Mageo::Tetrahedron::TypeError.ancestors
|
@@ -92,7 +85,6 @@ class TC_Tetrahedron < Test::Unit::TestCase
|
|
92
85
|
|
93
86
|
assert_equal( false, @t01.include?(Mageo::Vector3D[ 3.0, 6.0, 30.0], $tolerance))
|
94
87
|
|
95
|
-
assert_raise(Mageo::Polyhedron::TypeError){@t00.include?(Mageo::Vector3DInternal[1.0, 1.0, 1.0], $tolerance)}
|
96
88
|
end
|
97
89
|
|
98
90
|
def test_volume
|
@@ -112,10 +104,10 @@ class TC_Tetrahedron < Test::Unit::TestCase
|
|
112
104
|
def test_triangles
|
113
105
|
t = @t00.triangles
|
114
106
|
assert_equal(4, t.size)
|
115
|
-
assert_equal(Mageo::Triangle.new(
|
116
|
-
assert_equal(Mageo::Triangle.new(
|
117
|
-
assert_equal(Mageo::Triangle.new(
|
118
|
-
assert_equal(Mageo::Triangle.new(
|
107
|
+
assert_equal(Mageo::Triangle.new(V_00, V_01, V_02) ,t[0])
|
108
|
+
assert_equal(Mageo::Triangle.new(V_01, V_02, V_03) ,t[1])
|
109
|
+
assert_equal(Mageo::Triangle.new(V_02, V_03, V_00) ,t[2])
|
110
|
+
assert_equal(Mageo::Triangle.new(V_03, V_00, V_01) ,t[3])
|
119
111
|
end
|
120
112
|
|
121
113
|
def test_edges
|
@@ -182,23 +174,23 @@ class TC_Tetrahedron < Test::Unit::TestCase
|
|
182
174
|
v859 = Mageo::Vector3D[ 8.0, 5.0, 9.0]
|
183
175
|
|
184
176
|
# Mismatch is only the order of vertices.
|
185
|
-
t11 = Mageo::Tetrahedron.new(
|
177
|
+
t11 = Mageo::Tetrahedron.new( V_01, V_02, V_03, V_00)
|
186
178
|
results = @t00.shared_vertices(t11)
|
187
179
|
assert_equal([ V_00, V_01, V_02, V_03 ], results)
|
188
180
|
|
189
|
-
t11 = Mageo::Tetrahedron.new(
|
181
|
+
t11 = Mageo::Tetrahedron.new(V_01, V_02, v123, V_00)
|
190
182
|
results = @t00.shared_vertices(t11)
|
191
183
|
assert_equal([V_00, V_01, V_02], results)
|
192
184
|
|
193
|
-
t11 = Mageo::Tetrahedron.new(
|
185
|
+
t11 = Mageo::Tetrahedron.new(V_01, v234, v123, V_00)
|
194
186
|
results = @t00.shared_vertices(t11)
|
195
187
|
assert_equal([V_00, V_01], results)
|
196
188
|
|
197
|
-
t11 = Mageo::Tetrahedron.new(
|
189
|
+
t11 = Mageo::Tetrahedron.new(v346, v234, v123, V_00)
|
198
190
|
results = @t00.shared_vertices(t11)
|
199
191
|
assert_equal([V_00], results)
|
200
192
|
|
201
|
-
t11 = Mageo::Tetrahedron.new(
|
193
|
+
t11 = Mageo::Tetrahedron.new(v346, v234, v123, v859)
|
202
194
|
results = @t00.shared_vertices(t11)
|
203
195
|
assert_equal([], results)
|
204
196
|
|
@@ -206,7 +198,7 @@ class TC_Tetrahedron < Test::Unit::TestCase
|
|
206
198
|
v01a = Mageo::Vector3D[10.0+1.0E-13, 0.0+1.0E-13, 0.0+1.0E-13]
|
207
199
|
v02a = Mageo::Vector3D[ 0.0+1.0E-13,10.0+1.0E-13, 0.0+1.0E-13]
|
208
200
|
v03a = Mageo::Vector3D[ 0.0+1.0E-13, 0.0+1.0E-13,10.0+1.0E-13]
|
209
|
-
t11 = Mageo::Tetrahedron.new(
|
201
|
+
t11 = Mageo::Tetrahedron.new( v01a, v02a, v03a, v00a)
|
210
202
|
results = @t00.shared_vertices(t11)
|
211
203
|
assert_equal([], results)
|
212
204
|
results = @t00.shared_vertices(t11, 1.0E-10)
|
data/test/test_triangle.rb
CHANGED
@@ -20,26 +20,17 @@ class TC_Triangle < Test::Unit::TestCase
|
|
20
20
|
VEC_Z = Mageo::Vector3D[0.0, 0.0, 1.0]
|
21
21
|
|
22
22
|
def setup
|
23
|
-
@t00 = Mageo::Triangle.new(
|
24
|
-
@t01 = Mageo::Triangle.new(
|
25
|
-
@t02 = Mageo::Triangle.new([
|
26
|
-
@t03 = Mageo::Triangle.new([
|
23
|
+
@t00 = Mageo::Triangle.new(VEC_O, VEC_X, VEC_Y)
|
24
|
+
@t01 = Mageo::Triangle.new(VEC_X, VEC_Y, VEC_Z)
|
25
|
+
@t02 = Mageo::Triangle.new([10.0,10.0,10.0], [20.0,10.0,10.0], [10.0,20.0,10.0])
|
26
|
+
@t03 = Mageo::Triangle.new([10.0,20.0,30.0], [ 0.0,20.0,30.0], [10.0, 0.0,30.0])
|
27
27
|
end
|
28
28
|
|
29
29
|
def test_initialize
|
30
|
-
assert_raise(
|
31
|
-
assert_raise(
|
32
|
-
|
33
|
-
|
34
|
-
assert_raise( Mageo::Triangle::InitializeError ){ Mageo::Triangle.new( [ 0, 1 ] ) }
|
35
|
-
assert_raise( Mageo::Triangle::InitializeError ){ Mageo::Triangle.new( [ 0, 1, 2 ] ) }
|
36
|
-
assert_raise( Mageo::Triangle::InitializeError ){ Mageo::Triangle.new( [ 0, 1, 2, 3 ] ) }
|
37
|
-
assert_raise( Mageo::Triangle::InitializeError ){ Mageo::Triangle.new( [ [ 0, 0, 0 ], [ 1, 1, 1 ], [ 2, 3 ] ] ) } #3次元座標になっていないものがある。
|
38
|
-
|
39
|
-
assert_raise( Mageo::Triangle::LinearException ){ Mageo::Triangle.new( [ [ 0, 0, 0 ], [ 0, 0, 0 ], [ 2, 2, 2 ] ] ) } #同一の点を含む。
|
40
|
-
assert_raise( Mageo::Triangle::LinearException ){ Mageo::Triangle.new( [ [ 0, 0, 0 ], [ 1, 1, 1 ], [ 2, 2, 2 ] ] ) } #直線上に並ぶ
|
41
|
-
|
42
|
-
assert_equal( Mageo::Triangle, Mageo::Triangle.new( [ Mageo::Vector3D[ 0, 0, 0 ], Mageo::Vector3D[ 1, 0, 0 ], Mageo::Vector3D[ 0, 1, 0 ] ] ).class )
|
30
|
+
assert_raise( Mageo::Triangle::LinearException ){ Mageo::Triangle.new( [ 0, 0, 0 ], [ 0, 0, 0 ], [ 2, 2, 2 ] ) } #同一の点を含む。
|
31
|
+
assert_raise( Mageo::Triangle::LinearException ){ Mageo::Triangle.new( [ 0, 0, 0 ], [ 1, 1, 1 ], [ 2, 2, 2 ] ) } #直線上に並ぶ
|
32
|
+
|
33
|
+
assert_equal( Mageo::Triangle, Mageo::Triangle.new( Mageo::Vector3D[ 0, 0, 0 ], Mageo::Vector3D[ 1, 0, 0 ], Mageo::Vector3D[ 0, 1, 0 ] ).class )
|
43
34
|
end
|
44
35
|
|
45
36
|
def test_vertices
|
@@ -190,44 +181,44 @@ class TC_Triangle < Test::Unit::TestCase
|
|
190
181
|
@t00.equivalent?([[ 0.0, 0.0, 0.0], [ 1.0, 0.0, 0.0], [ 0.0, 1.0, 0.0]])
|
191
182
|
}
|
192
183
|
|
193
|
-
t = Mageo::Triangle.new([
|
184
|
+
t = Mageo::Triangle.new([ 0.0, 0.0, 0.0], [ 1.0, 0.0, 0.0], [ 0.0, 1.0, 0.0])
|
194
185
|
assert_equal(true , @t00.eql?(t))
|
195
186
|
|
196
|
-
t = Mageo::Triangle.new([
|
187
|
+
t = Mageo::Triangle.new([ 1.0, 0.0, 0.0], [ 0.0, 0.0, 0.0], [ 0.0, 1.0, 0.0])
|
197
188
|
assert_equal(true , @t00.eql?(t))
|
198
189
|
|
199
|
-
t = Mageo::Triangle.new([
|
190
|
+
t = Mageo::Triangle.new([ 1.0, 0.0, 0.0], [ 0.0, 1.0, 0.0], [ 0.0, 0.0, 0.0])
|
200
191
|
assert_equal(true , @t00.eql?(t))
|
201
192
|
|
202
|
-
t = Mageo::Triangle.new([
|
193
|
+
t = Mageo::Triangle.new([ 0.0, 0.0, 1.0], [ 1.0, 0.0, 0.0], [ 0.0, 1.0, 0.0])
|
203
194
|
assert_equal(false, @t00.eql?(t))
|
204
195
|
|
205
196
|
# tolerance を設定の上 0.0
|
206
|
-
t = Mageo::Triangle.new([
|
197
|
+
t = Mageo::Triangle.new([ 0.0, 0.0, 1.0], [ 1.0, 0.0, 0.0], [ 0.0, 1.0, 0.0])
|
207
198
|
assert_equal(false, @t00.eql?(t, 0.0))
|
208
199
|
|
209
200
|
# tolerance を 1.0 に設定
|
210
|
-
t = Mageo::Triangle.new([
|
201
|
+
t = Mageo::Triangle.new([ 0.0, 0.0, 1.0], [ 1.0, 0.0, 0.0], [ 0.0, 1.0, 0.0])
|
211
202
|
assert_equal(true, @t00.eql?(t, 1.0))
|
212
203
|
end
|
213
204
|
|
214
205
|
def test_equal2
|
215
|
-
t = Mageo::Triangle.new([
|
206
|
+
t = Mageo::Triangle.new([ 0.0, 0.0, 0.0], [ 1.0, 0.0, 0.0], [ 0.0, 1.0, 0.0])
|
216
207
|
assert_equal(true , @t00 == t)
|
217
208
|
|
218
|
-
t = Mageo::Triangle.new([
|
209
|
+
t = Mageo::Triangle.new([ 1.0, 0.0, 0.0], [ 0.0, 0.0, 0.0], [ 0.0, 1.0, 0.0])
|
219
210
|
assert_equal(false, @t00 == t)
|
220
211
|
|
221
|
-
t = Mageo::Triangle.new([
|
212
|
+
t = Mageo::Triangle.new([ 1.0, 0.0, 0.0], [ 0.0, 1.0, 0.0], [ 0.0, 0.0, 0.0])
|
222
213
|
assert_equal(false, @t00 == t)
|
223
214
|
|
224
|
-
t = Mageo::Triangle.new([
|
215
|
+
t = Mageo::Triangle.new([ 0.0, 0.0, 1.0], [ 1.0, 0.0, 0.0], [ 0.0, 1.0, 0.0])
|
225
216
|
assert_equal(false, @t00 == t)
|
226
217
|
end
|
227
218
|
|
228
219
|
def test_internal_axes
|
229
|
-
@t01 = Mageo::Triangle.new([
|
230
|
-
@t02 = Mageo::Triangle.new([
|
220
|
+
@t01 = Mageo::Triangle.new([ 1.0, 0.0, 0.0], [ 0.0, 1.0, 0.0], [ 0.0, 0.0, 1.0])
|
221
|
+
@t02 = Mageo::Triangle.new([10.0,10.0,10.0], [20.0,10.0,10.0], [10.0,20.0,10.0])
|
231
222
|
|
232
223
|
t = Mageo::Axes.new([[ 1.0, 0.0, 0.0], [ 0.0, 1.0, 0.0], [ 0.0, 0.0, 1.0]])
|
233
224
|
assert_equal(t, @t00.internal_axes)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mageo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ippei94da
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-07-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: test-unit
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '3.
|
19
|
+
version: '3.2'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '3.
|
26
|
+
version: '3.2'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rdoc
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|