crystalcell 0.0.6 → 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.
@@ -1,4 +1,4 @@
1
- module CrystalCell::Povray; end
1
+ class CrystalCell::Povray; end
2
2
 
3
3
  require 'crystalcell/povray/camera.rb'
4
4
  require 'crystalcell/povray/cell.rb'
@@ -6,3 +6,191 @@ require 'crystalcell/povray/cylinder.rb'
6
6
  require 'crystalcell/povray/element.rb'
7
7
  require 'crystalcell/povray/sphere.rb'
8
8
  require 'crystalcell/povray/triangle.rb'
9
+ require 'crystalcell/povray/tetrahedron.rb'
10
+ require 'crystalcell/povray/color.rb'
11
+
12
+
13
+ DEFAULT_ENVIRONMENTS = [
14
+ 'background {color rgb<1,1,1>}',
15
+ 'light_source{ < 4, 1, 4 > color <1,1,1> parallel point_at 0 }',
16
+ 'default{ texture{ finish{ ambient 0.4 phong 1.0 phong_size 10 } } }',
17
+ ]
18
+
19
+ class CrystalCell::Povray
20
+ attr_reader :camera, :environments, :cell, :axes
21
+
22
+ # camera_info indicates hash with the keys of camera info,
23
+ # e.g., :camera_type, :location, :direction, :right, :sky, :up, :look_at
24
+ def initialize(cell: , camera_info: {}, environments: DEFAULT_ENVIRONMENTS)
25
+ @camera = CrystalCell::Povray::Camera.new(camera_info)
26
+ @environments = environments
27
+ @cell = cell.to_povcell
28
+ @axes = nil
29
+ @objects = []
30
+
31
+ ## @camera.look_at
32
+ center = Mageo::Vector3D[0.0, 0.0, 0.0]
33
+ @cell.axes.each { |axis| center += axis.to_v3d * 0.5 }
34
+ @camera.look_at = center
35
+ end
36
+
37
+ # Reset camera location, using relative vector from center of cell
38
+ # with cartesian coordinate.
39
+ def camera_location(vector)
40
+ look_at = @camera.look_at || [0.0, 0.0, 0.0]
41
+ look_at = Mageo::Vector3D[*look_at]
42
+ @camera.location = look_at + Mageo::Vector3D[*vector]
43
+ end
44
+
45
+ # Reset camera location, using relative vector from center of cell
46
+ # with polar coordinates.
47
+ # theta and phi is set as degree. Not radian.
48
+ def camera_location_polar(r, theta, phi)
49
+ theta = (2.0 * Math::PI) * theta / 360.0
50
+ phi = (2.0 * Math::PI) * phi / 360.0
51
+
52
+ look_at = Mageo::Vector3D[*(@camera.look_at || [0.0, 0.0, 0.0])]
53
+ polar = Mageo::Polar3D.new(r, theta, phi)
54
+ @camera.location = look_at + polar.to_v3d
55
+ end
56
+
57
+ #
58
+ def shoot_snap(basename)
59
+ povfile = basename + '.pov'
60
+ File.open(povfile, 'w') do |io|
61
+ dump(io)
62
+ end
63
+ system "povray -D #{povfile}"
64
+ end
65
+
66
+ # shoot 4 angles and unite.
67
+ def shoot_4in1(basename, remain_intermediate = false)
68
+ name_x = basename + '-x'
69
+ name_y = basename + '-y'
70
+ name_z = basename + '-z'
71
+ name_w = basename + '-w'
72
+ name_zw = basename + '-zw'
73
+ name_xy = basename + '-xy'
74
+ #name_zwxy = basename + '-zwxy'
75
+ name_zwxy = basename
76
+
77
+ r = 10.0
78
+ povray = Marshal.load(Marshal.dump(self))
79
+ povray.camera_location_polar(r, 0, 0) ; povray.shoot_snap( name_z )
80
+ povray.camera_location_polar(r, 90, 0) ; povray.shoot_snap( name_x )
81
+ povray.camera_location_polar(r, 90, 90) ; povray.shoot_snap( name_y )
82
+ #povray.camera_location_polar(r, 80, 70) ; povray.shoot_snap( name_w )
83
+ povray.camera_location_polar(r, 120, 230) ; povray.shoot_snap( name_w )
84
+
85
+ system "convert +append #{name_z }.png #{name_w }.png #{name_zw }.png"
86
+ system "convert +append #{name_x }.png #{name_y }.png #{name_xy }.png"
87
+ system "convert -append #{name_zw}.png #{name_xy}.png #{name_zwxy}.png"
88
+
89
+ #中間ファイルを消す。
90
+ unless remain_intermediate
91
+ [
92
+ name_w + '.png',
93
+ name_w + '.pov',
94
+ name_x + '.png',
95
+ name_x + '.pov',
96
+ name_y + '.png',
97
+ name_y + '.pov',
98
+ name_z + '.png',
99
+ name_z + '.pov',
100
+ name_zw + '.png',
101
+ name_xy + '.png',
102
+ ].each do |file|
103
+ FileUtils.rm file if FileTest.exist? file
104
+ end
105
+ end
106
+ end
107
+
108
+ ##lattice を描くか
109
+ #def set_lattice(axes)
110
+ #end
111
+
112
+ #def set_atoms(cell)
113
+ #end
114
+
115
+ # 3つの棒で座標軸を配置
116
+ # x, y, z 軸をそれぞれ red, green, blue で表示。
117
+ def set_axes(position)
118
+ #o = Vector3D[-1.0, -1.0, 0.0]
119
+ o = Mageo::Vector3D[*position]
120
+ x = Mageo::Vector3D[1.0, 0.0, 0.0]
121
+ y = Mageo::Vector3D[0.0, 1.0, 0.0]
122
+ z = Mageo::Vector3D[0.0, 0.0, 1.0]
123
+ ox = o + x
124
+ oy = o + y
125
+ oz = o + z
126
+
127
+ @axes = [
128
+ CrystalCell::Povray::Cylinder.new(o, ox, 0.04, x),
129
+ CrystalCell::Povray::Cylinder.new(o, oy, 0.04, y),
130
+ CrystalCell::Povray::Cylinder.new(o, oz, 0.04, z)
131
+ ]
132
+ end
133
+
134
+ # object should have dump method
135
+ def add(object)
136
+ @objects << object
137
+ end
138
+
139
+ def dump(io)
140
+ @camera.dump(io)
141
+ @environments.each { |item| io.puts item }
142
+ @cell.dump(io)
143
+
144
+ if @axes
145
+ @axes.each {|axis| axis.dump(io)}
146
+ end
147
+
148
+ @objects.each { |obj| obj.dump(io) }
149
+ end
150
+
151
+ end
152
+
153
+ # def test_gen_image
154
+ # TODO
155
+ # end
156
+ #
157
+ # def test_gen_4in1_images
158
+ # TODO
159
+ # end
160
+ #
161
+ # def test_additional
162
+ # c10 = CrystalCell::Povray::Camera.new(
163
+ # camera_type: 'orthographic',
164
+ # location: [ 3.0, 3.0, 3.0 ],
165
+ # look_at: [ 0.0, 0.0, 0.0 ],
166
+ # sky: [ 0.0, 0.0, 1.0 ],
167
+ # right: [ -1.00, 0.0, 0.0 ],
168
+ # up: [ 0.0, 1.0, 0.0 ],
169
+ # angle: 68,
170
+ # additions:[ "background {color rgb<1,1,1>}",
171
+ # "light_source{ < 4, 1, 4 > color <1,1,1> parallel point_at 0 }",
172
+ # "default{ texture{ finish{ ambient 0.4 phong 1.0 phong_size 10 } } }",
173
+ # ]
174
+ # )
175
+ # correct = <<HERE
176
+ #camera {
177
+ # orthographic
178
+ # location <3.000000, 3.000000, 3.000000 >
179
+ # sky <0.000000, 0.000000, 1.000000 >
180
+ # right <-1.000000, 0.000000, 0.000000 >
181
+ # up <0.000000, 1.000000, 0.000000 >
182
+ # angle 68.000000
183
+ # look_at <0.000000, 0.000000, 0.000000 >
184
+ #}
185
+ #HERE
186
+ # io = StringIO.new
187
+ # c10.dump(io)
188
+ # io.rewind
189
+ # result = io.read
190
+ # assert_equal(correct, result)
191
+ # end
192
+
193
+ #bond を描くか
194
+ #def set_bond(cell)
195
+ #end
196
+
@@ -9,38 +9,149 @@ require "helper"
9
9
  class TC_Camera < Test::Unit::TestCase
10
10
  def setup
11
11
  @c00 = CrystalCell::Povray::Camera.new(
12
- orthographic: true,
12
+ camera_type: 'orthographic',
13
13
  location: [ 3.0, 3.0, 3.0 ],
14
- look_at: [ 0.0, 0.0, 0.0 ],
15
14
  sky: [ 0.0, 0.0, 1.0 ],
16
15
  right: [ -1.00, 0.0, 0.0 ],
17
16
  up: [ 0.0, 1.0, 0.0 ],
18
- angle: 68
17
+ angle: 68,
18
+ look_at: [ 0.0, 0.0, 0.0 ],
19
19
  )
20
20
  end
21
21
 
22
22
  def test_initialize
23
23
  hash = {
24
- orthographic: true,
24
+ #camera_type: 'orthographic',
25
+ location: [ 3.0, 3.0, 3.0 ],
26
+ sky: [ 0.0, 0.0, 1.0 ],
27
+ right: [ -1.00, 0.0, 0.0 ],
28
+ up: [ 0.0, 1.0, 0.0 ],
29
+ angle: 68,
30
+ look_at: [ 0.0, 0.0, 0.0 ],
31
+ }
32
+ c01 = CrystalCell::Povray::Camera.new(hash)
33
+ assert_equal( nil , c01.camera_type)
34
+ assert_equal( [ 3.0, 3.0, 3.0 ], c01.location )
35
+ assert_equal( [ 0.0, 0.0, 0.0 ], c01.look_at )
36
+ assert_equal( [ 0.0, 0.0, 1.0 ], c01.sky )
37
+ assert_equal( [ -1.00, 0.0, 0.0 ], c01.right )
38
+ assert_equal( [ 0.0, 1.0, 0.0 ], c01.up )
39
+ assert_equal( 68 , c01.angle )
40
+
41
+ hash = {
42
+ camera_type: 'orthographic',
43
+ #location: [ 3.0, 3.0, 3.0 ],
44
+ sky: [ 0.0, 0.0, 1.0 ],
45
+ right: [ -1.00, 0.0, 0.0 ],
46
+ up: [ 0.0, 1.0, 0.0 ],
47
+ angle: 68,
48
+ look_at: [ 0.0, 0.0, 0.0 ],
49
+ }
50
+ c01 = CrystalCell::Povray::Camera.new(hash)
51
+ assert_equal( 'orthographic' , c01.camera_type)
52
+ assert_equal( nil, c01.location )
53
+ assert_equal( [ 0.0, 0.0, 0.0 ], c01.look_at )
54
+ assert_equal( [ 0.0, 0.0, 1.0 ], c01.sky )
55
+ assert_equal( [ -1.00, 0.0, 0.0 ], c01.right )
56
+ assert_equal( [ 0.0, 1.0, 0.0 ], c01.up )
57
+ assert_equal( 68 , c01.angle )
58
+
59
+ hash = {
60
+ camera_type: 'orthographic',
61
+ location: [ 3.0, 3.0, 3.0 ],
62
+ #sky: [ 0.0, 0.0, 1.0 ],
63
+ right: [ -1.00, 0.0, 0.0 ],
64
+ up: [ 0.0, 1.0, 0.0 ],
65
+ angle: 68,
66
+ look_at: [ 0.0, 0.0, 0.0 ],
67
+ }
68
+ c01 = CrystalCell::Povray::Camera.new(hash)
69
+ assert_equal( 'orthographic' , c01.camera_type)
70
+ assert_equal( [ 3.0, 3.0, 3.0 ], c01.location )
71
+ assert_equal( [ 0.0, 0.0, 0.0 ], c01.look_at )
72
+ assert_equal( [ 0.0, 0.0, 1.0], c01.sky )
73
+ assert_equal( [ -1.0, 0.0, 0.0 ], c01.right )
74
+ assert_equal( [ 0.0, 1.0, 0.0 ], c01.up )
75
+ assert_equal( 68 , c01.angle )
76
+
77
+ hash = {
78
+ camera_type: 'orthographic',
79
+ location: [ 3.0, 3.0, 3.0 ],
80
+ sky: [ 0.0, 0.0, 1.0 ],
81
+ #right: [ -1.00, 0.0, 0.0 ],
82
+ up: [ 0.0, 1.0, 0.0 ],
83
+ angle: 68,
84
+ look_at: [ 0.0, 0.0, 0.0 ],
85
+ }
86
+ c01 = CrystalCell::Povray::Camera.new(hash)
87
+ assert_equal( 'orthographic' , c01.camera_type)
88
+ assert_equal( [ 3.0, 3.0, 3.0 ], c01.location )
89
+ assert_equal( [ 0.0, 0.0, 0.0 ], c01.look_at )
90
+ assert_equal( [ 0.0, 0.0, 1.0 ], c01.sky )
91
+ assert_equal( [ -1.33,0.0, 0.0], c01.right )
92
+ assert_equal( [ 0.0, 1.0, 0.0 ], c01.up )
93
+ assert_equal( 68 , c01.angle )
94
+
95
+ hash = {
96
+ camera_type: 'orthographic',
97
+ location: [ 3.0, 3.0, 3.0 ],
98
+ sky: [ 0.0, 0.0, 1.0 ],
99
+ right: [ -1.00, 0.0, 0.0 ],
100
+ #up: [ 0.0, 1.0, 0.0 ],
101
+ angle: 68,
102
+ look_at: [ 0.0, 0.0, 0.0 ],
103
+ }
104
+ c01 = CrystalCell::Povray::Camera.new(hash)
105
+ assert_equal( 'orthographic' , c01.camera_type)
106
+ assert_equal( [ 3.0, 3.0, 3.0 ], c01.location )
107
+ assert_equal( [ 0.0, 0.0, 0.0 ], c01.look_at )
108
+ assert_equal( [ 0.0, 0.0, 1.0 ], c01.sky )
109
+ assert_equal( [ -1.00, 0.0, 0.0 ], c01.right )
110
+ assert_equal( nil , c01.up )
111
+ assert_equal( 68 , c01.angle )
112
+
113
+ hash = {
114
+ camera_type: 'orthographic',
25
115
  location: [ 3.0, 3.0, 3.0 ],
116
+ sky: [ 0.0, 0.0, 1.0 ],
117
+ right: [ -1.00, 0.0, 0.0 ],
118
+ up: [ 0.0, 1.0, 0.0 ],
119
+ #angle: 68,
26
120
  look_at: [ 0.0, 0.0, 0.0 ],
121
+ }
122
+ c01 = CrystalCell::Povray::Camera.new(hash)
123
+ assert_equal( 'orthographic' , c01.camera_type)
124
+ assert_equal( [ 3.0, 3.0, 3.0 ], c01.location )
125
+ assert_equal( [ 0.0, 0.0, 0.0 ], c01.look_at )
126
+ assert_equal( [ 0.0, 0.0, 1.0 ], c01.sky )
127
+ assert_equal( [ -1.00, 0.0, 0.0 ], c01.right )
128
+ assert_equal( [ 0.0, 1.0, 0.0 ], c01.up )
129
+ assert_equal( nil , c01.angle )
130
+
131
+ hash = {
132
+ camera_type: 'orthographic',
133
+ location: [ 3.0, 3.0, 3.0 ],
27
134
  sky: [ 0.0, 0.0, 1.0 ],
28
135
  right: [ -1.00, 0.0, 0.0 ],
29
136
  up: [ 0.0, 1.0, 0.0 ],
30
- angle: 68
137
+ angle: 68,
138
+ #look_at: [ 0.0, 0.0, 0.0 ],
31
139
  }
32
- @c01 = CrystalCell::Povray::Camera.new(hash)
33
- assert_equal( true , @c01.orthographic)
34
- assert_equal( [ 3.0, 3.0, 3.0 ], @c01.location )
35
- assert_equal( [ 0.0, 0.0, 0.0 ], @c01.look_at )
36
- assert_equal( [ 0.0, 0.0, 1.0 ], @c01.sky )
37
- assert_equal( [ -1.00, 0.0, 0.0 ], @c01.right )
38
- assert_equal( [ 0.0, 1.0, 0.0 ], @c01.up )
39
- assert_equal( 68 , @c01.angle )
140
+ c01 = CrystalCell::Povray::Camera.new(hash)
141
+ assert_equal( 'orthographic' , c01.camera_type)
142
+ assert_equal( [ 3.0, 3.0, 3.0 ], c01.location )
143
+ assert_equal( [ 0.0, 0.0, 1.0 ], c01.sky )
144
+ assert_equal( [ -1.00, 0.0, 0.0 ], c01.right )
145
+ assert_equal( [ 0.0, 1.0, 0.0 ], c01.up )
146
+ assert_equal( 68 , c01.angle )
147
+ assert_equal( nil , c01.look_at )
148
+
149
+ assert_nothing_raised(){ CrystalCell::Povray::Camera.new({})}
150
+ assert_nothing_raised(){ CrystalCell::Povray::Camera.new}
40
151
  end
41
152
 
42
153
  def test_accessor
43
- assert_equal( true , @c00.orthographic)
154
+ assert_equal( 'orthographic' , @c00.camera_type)
44
155
  assert_equal( [ 3.0, 3.0, 3.0 ], @c00.location )
45
156
  assert_equal( [ 0.0, 0.0, 0.0 ], @c00.look_at )
46
157
  assert_equal( [ 0.0, 0.0, 1.0 ], @c00.sky )
@@ -48,62 +159,87 @@ class TC_Camera < Test::Unit::TestCase
48
159
  assert_equal( [ 0.0, 1.0, 0.0 ], @c00.up )
49
160
  assert_equal( 68 , @c00.angle )
50
161
 
51
- @c00.orthographic = false
52
- assert_equal( false , @c00.orthographic)
162
+ @c00.camera_type = 'orthographic'
163
+ assert_equal( 'orthographic' , @c00.camera_type)
53
164
  end
54
165
 
55
- def test_additional
166
+ def test_dump
167
+ ############################################################
56
168
  c10 = CrystalCell::Povray::Camera.new(
57
- orthographic: true,
169
+ camera_type: 'orthographic',
58
170
  location: [ 3.0, 3.0, 3.0 ],
59
- look_at: [ 0.0, 0.0, 0.0 ],
60
- sky: [ 0.0, 0.0, 1.0 ],
61
171
  right: [ -1.00, 0.0, 0.0 ],
62
172
  up: [ 0.0, 1.0, 0.0 ],
173
+ sky: [ 0.0, 0.0, 1.0 ],
63
174
  angle: 68,
64
- additions:[ "background {color rgb<1,1,1>}",
65
- "light_source{ < 4, 1, 4 > color <1,1,1> parallel point_at 0 }",
66
- "default{ texture{ finish{ ambient 0.4 phong 1.0 phong_size 10 } } }",
67
- ]
175
+ look_at: [ 0.0, 0.0, 0.0 ],
68
176
  )
69
177
  correct = <<HERE
70
178
  camera {
71
179
  orthographic
72
- location <3.000000, 3.000000, 3.000000 >
73
- look_at <0.000000, 0.000000, 0.000000 >
74
- sky <0.000000, 0.000000, 1.000000 >
75
- right <-1.000000, 0.000000, 0.000000 >
76
- up <0.000000, 1.000000, 0.000000 >
77
- angle 68.000000
180
+ location <3.000000, 3.000000, 3.000000 >
181
+ right <-1.000000, 0.000000, 0.000000 >
182
+ up <0.000000, 1.000000, 0.000000 >
183
+ sky <0.000000, 0.000000, 1.000000 >
184
+ angle 68.000000
185
+ look_at <0.000000, 0.000000, 0.000000 >
78
186
  }
79
- background {color rgb<1,1,1>}
80
- light_source{ < 4, 1, 4 > color <1,1,1> parallel point_at 0 }
81
- default{ texture{ finish{ ambient 0.4 phong 1.0 phong_size 10 } } }
82
187
  HERE
83
188
  io = StringIO.new
84
189
  c10.dump(io)
85
190
  io.rewind
86
191
  result = io.read
87
192
  assert_equal(correct, result)
88
- end
89
193
 
90
- def test_dump
194
+ ## no angle ##########################################################
195
+ c10 = CrystalCell::Povray::Camera.new(
196
+ camera_type: 'orthographic',
197
+ location: [ 3.0, 3.0, 3.0 ],
198
+ sky: [ 0.0, 0.0, 1.0 ],
199
+ right: [ -1.00, 0.0, 0.0 ],
200
+ up: [ 0.0, 1.0, 0.0 ],
201
+ look_at: [ 0.0, 0.0, 0.0 ],
202
+ )
91
203
  correct = <<HERE
92
204
  camera {
93
205
  orthographic
94
- location <3.000000, 3.000000, 3.000000 >
95
- look_at <0.000000, 0.000000, 0.000000 >
96
- sky <0.000000, 0.000000, 1.000000 >
97
- right <-1.000000, 0.000000, 0.000000 >
98
- up <0.000000, 1.000000, 0.000000 >
99
- angle 68.000000
206
+ location <3.000000, 3.000000, 3.000000 >
207
+ right <-1.000000, 0.000000, 0.000000 >
208
+ up <0.000000, 1.000000, 0.000000 >
209
+ sky <0.000000, 0.000000, 1.000000 >
210
+ look_at <0.000000, 0.000000, 0.000000 >
100
211
  }
101
212
  HERE
102
213
  io = StringIO.new
103
- @c00.dump(io)
214
+ c10.dump(io)
104
215
  io.rewind
105
216
  result = io.read
106
217
  assert_equal(correct, result)
218
+
219
+ ## no ortho ##########################################################
220
+ c10 = CrystalCell::Povray::Camera.new(
221
+ location: [ 3.0, 3.0, 3.0 ],
222
+ sky: [ 0.0, 0.0, 1.0 ],
223
+ right: [ -1.00, 0.0, 0.0 ],
224
+ up: [ 0.0, 1.0, 0.0 ],
225
+ look_at: [ 0.0, 0.0, 0.0 ],
226
+ )
227
+ correct = <<HERE
228
+ camera {
229
+ location <3.000000, 3.000000, 3.000000 >
230
+ right <-1.000000, 0.000000, 0.000000 >
231
+ up <0.000000, 1.000000, 0.000000 >
232
+ sky <0.000000, 0.000000, 1.000000 >
233
+ look_at <0.000000, 0.000000, 0.000000 >
234
+ }
235
+ HERE
236
+ io = StringIO.new
237
+ c10.dump(io)
238
+ io.rewind
239
+ result = io.read
240
+ assert_equal(correct, result)
241
+ ############################################################
107
242
  end
108
243
 
109
244
  end
245
+
@@ -15,32 +15,32 @@ class TC_Povray_Sphere < Test::Unit::TestCase
15
15
  end
16
16
  end
17
17
 
18
- class TC_Povray_Cylinder < Test::Unit::TestCase
19
- def setup
20
- @c00 = Mageo::Cylinder.new([[ 1.0, 2.0, 3.0 ], [4.0, 5.0, 6.0]], 2.0)
21
- end
22
-
23
- def test_to_pov
24
- assert_equal(
25
- "object { cylinder{ < 1.0000, 2.0000, 3.0000>, < 4.0000, 5.0000, 6.0000>, 2.0000 } pigment { color rgb <0.30, 0.60, 0.90> } }",
26
- @c00.to_pov([0.3, 0.6, 0.9]) )
27
- end
28
- end
29
-
30
- class TC_Povray_Triangle < Test::Unit::TestCase
31
- def setup
32
- @t00 = Mageo::Triangle.new(
33
- [[ 1.0, 2.0, 3.0 ], [4.0, 5.0, 6.0], [0.3, 0.6, 0.9 ]]
34
- )
35
- end
36
-
37
- def test_to_pov
38
- assert_equal(
39
- "polygon { 4, < 1.0000, 2.0000, 3.0000>, < 4.0000, 5.0000, 6.0000>, < 0.3000, 0.6000, 0.9000>, < 1.0000, 2.0000, 3.0000> pigment { color rgb <1, 0, 0> } }",
40
- @t00.to_pov([0.3, 0.6, 0.9])
41
- )
42
- end
43
- end
18
+ #class TC_Povray_Cylinder < Test::Unit::TestCase
19
+ # def setup
20
+ # @c00 = Mageo::Cylinder.new([[ 1.0, 2.0, 3.0 ], [4.0, 5.0, 6.0]], 2.0)
21
+ # end
22
+ #
23
+ # def test_to_pov
24
+ # assert_equal(
25
+ # "object { cylinder{ < 1.0000, 2.0000, 3.0000>, < 4.0000, 5.0000, 6.0000>, 2.0000 } pigment { color rgb <0.30, 0.60, 0.90> } }",
26
+ # @c00.to_pov([0.3, 0.6, 0.9]) )
27
+ # end
28
+ #end
29
+ #
30
+ #class TC_Povray_Triangle < Test::Unit::TestCase
31
+ # def setup
32
+ # @t00 = Mageo::Triangle.new(
33
+ # [[ 1.0, 2.0, 3.0 ], [4.0, 5.0, 6.0], [0.3, 0.6, 0.9 ]]
34
+ # )
35
+ # end
36
+ #
37
+ # def test_to_pov
38
+ # assert_equal(
39
+ # "polygon { 4, < 1.0000, 2.0000, 3.0000>, < 4.0000, 5.0000, 6.0000>, < 0.3000, 0.6000, 0.9000>, < 1.0000, 2.0000, 3.0000> pigment { color rgb <1, 0, 0> } }",
40
+ # @t00.to_pov([0.3, 0.6, 0.9])
41
+ # )
42
+ # end
43
+ #end
44
44
 
45
45
  class CrystalCell::Povray::Cell
46
46
  #public :atoms_to_povs, :bonds_to_povs, :lattice_to_povs
@@ -118,18 +118,18 @@ class TC_Povray_Cell < Test::Unit::TestCase
118
118
 
119
119
  def test_lattice_to_povs
120
120
  corrects = [
121
- "object { cylinder{ < 0.0000, 0.0000, 0.0000>, < 0.0000, 0.0000, 2.0000>, 0.1000 } pigment { color rgb <0.50, 0.50, 0.50> } }\n",
122
- "object { cylinder{ < 0.0000, 2.0000, 0.0000>, < 0.0000, 2.0000, 2.0000>, 0.1000 } pigment { color rgb <0.50, 0.50, 0.50> } }\n",
123
- "object { cylinder{ < 2.0000, 0.0000, 0.0000>, < 2.0000, 0.0000, 2.0000>, 0.1000 } pigment { color rgb <0.50, 0.50, 0.50> } }\n",
124
- "object { cylinder{ < 2.0000, 2.0000, 0.0000>, < 2.0000, 2.0000, 2.0000>, 0.1000 } pigment { color rgb <0.50, 0.50, 0.50> } }\n",
125
- "object { cylinder{ < 0.0000, 0.0000, 0.0000>, < 0.0000, 2.0000, 0.0000>, 0.1000 } pigment { color rgb <0.50, 0.50, 0.50> } }\n",
126
- "object { cylinder{ < 2.0000, 0.0000, 0.0000>, < 2.0000, 2.0000, 0.0000>, 0.1000 } pigment { color rgb <0.50, 0.50, 0.50> } }\n",
127
- "object { cylinder{ < 0.0000, 0.0000, 2.0000>, < 0.0000, 2.0000, 2.0000>, 0.1000 } pigment { color rgb <0.50, 0.50, 0.50> } }\n",
128
- "object { cylinder{ < 2.0000, 0.0000, 2.0000>, < 2.0000, 2.0000, 2.0000>, 0.1000 } pigment { color rgb <0.50, 0.50, 0.50> } }\n",
129
- "object { cylinder{ < 0.0000, 0.0000, 0.0000>, < 2.0000, 0.0000, 0.0000>, 0.1000 } pigment { color rgb <0.50, 0.50, 0.50> } }\n",
130
- "object { cylinder{ < 0.0000, 0.0000, 2.0000>, < 2.0000, 0.0000, 2.0000>, 0.1000 } pigment { color rgb <0.50, 0.50, 0.50> } }\n",
131
- "object { cylinder{ < 0.0000, 2.0000, 0.0000>, < 2.0000, 2.0000, 0.0000>, 0.1000 } pigment { color rgb <0.50, 0.50, 0.50> } }\n",
132
- "object { cylinder{ < 0.0000, 2.0000, 2.0000>, < 2.0000, 2.0000, 2.0000>, 0.1000 } pigment { color rgb <0.50, 0.50, 0.50> } }\n" ,
121
+ "object { cylinder{ < 0.0000, 0.0000, 0.0000>, < 0.0000, 0.0000, 2.0000>, 0.0200 } pigment { color rgb <0.50, 0.50, 0.50> } }\n",
122
+ "object { cylinder{ < 0.0000, 2.0000, 0.0000>, < 0.0000, 2.0000, 2.0000>, 0.0200 } pigment { color rgb <0.50, 0.50, 0.50> } }\n",
123
+ "object { cylinder{ < 2.0000, 0.0000, 0.0000>, < 2.0000, 0.0000, 2.0000>, 0.0200 } pigment { color rgb <0.50, 0.50, 0.50> } }\n",
124
+ "object { cylinder{ < 2.0000, 2.0000, 0.0000>, < 2.0000, 2.0000, 2.0000>, 0.0200 } pigment { color rgb <0.50, 0.50, 0.50> } }\n",
125
+ "object { cylinder{ < 0.0000, 0.0000, 0.0000>, < 0.0000, 2.0000, 0.0000>, 0.0200 } pigment { color rgb <0.50, 0.50, 0.50> } }\n",
126
+ "object { cylinder{ < 2.0000, 0.0000, 0.0000>, < 2.0000, 2.0000, 0.0000>, 0.0200 } pigment { color rgb <0.50, 0.50, 0.50> } }\n",
127
+ "object { cylinder{ < 0.0000, 0.0000, 2.0000>, < 0.0000, 2.0000, 2.0000>, 0.0200 } pigment { color rgb <0.50, 0.50, 0.50> } }\n",
128
+ "object { cylinder{ < 2.0000, 0.0000, 2.0000>, < 2.0000, 2.0000, 2.0000>, 0.0200 } pigment { color rgb <0.50, 0.50, 0.50> } }\n",
129
+ "object { cylinder{ < 0.0000, 0.0000, 0.0000>, < 2.0000, 0.0000, 0.0000>, 0.0200 } pigment { color rgb <0.50, 0.50, 0.50> } }\n",
130
+ "object { cylinder{ < 0.0000, 0.0000, 2.0000>, < 2.0000, 0.0000, 2.0000>, 0.0200 } pigment { color rgb <0.50, 0.50, 0.50> } }\n",
131
+ "object { cylinder{ < 0.0000, 2.0000, 0.0000>, < 2.0000, 2.0000, 0.0000>, 0.0200 } pigment { color rgb <0.50, 0.50, 0.50> } }\n",
132
+ "object { cylinder{ < 0.0000, 2.0000, 2.0000>, < 2.0000, 2.0000, 2.0000>, 0.0200 } pigment { color rgb <0.50, 0.50, 0.50> } }\n" ,
133
133
  ]
134
134
  t = @c00.lattice_to_povs
135
135
  corrects.each_with_index do |correct, index|
@@ -0,0 +1,106 @@
1
+ #! /usr/bin/env ruby
2
+ # coding: utf-8
3
+
4
+ require "pp"
5
+ require "helper"
6
+ #require "test/unit"
7
+ #require "pkg/klass.rb"
8
+
9
+ $tolerance = 1.0E-10
10
+
11
+ class TC_Color < Test::Unit::TestCase
12
+ #def setup
13
+ # @k = Color.new
14
+ #end
15
+ #
16
+ COLOR = CrystalCell::Povray::Color
17
+ PI = Math::PI
18
+
19
+ def test_self_circle_color
20
+ results = COLOR.circle_color((2.0 * PI) * 0.0)
21
+ assert_in_delta(1.0, results[0], $tolerance)
22
+ assert_in_delta(0.0, results[1], $tolerance)
23
+ assert_in_delta(0.0, results[2], $tolerance)
24
+
25
+ results = COLOR.circle_color((2.0 * PI) * (1.0/6.0))
26
+ assert_in_delta(1.0, results[0], $tolerance)
27
+ assert_in_delta(1.0, results[1], $tolerance)
28
+ assert_in_delta(0.0, results[2], $tolerance)
29
+
30
+ results = COLOR.circle_color((2.0 * PI) * (2.0/6.0))
31
+ assert_in_delta(0.0, results[0], $tolerance)
32
+ assert_in_delta(1.0, results[1], $tolerance)
33
+ assert_in_delta(0.0, results[2], $tolerance)
34
+
35
+ results = COLOR.circle_color((2.0 * PI) * (3.0/6.0))
36
+ assert_in_delta(0.0, results[0], $tolerance)
37
+ assert_in_delta(1.0, results[1], $tolerance)
38
+ assert_in_delta(1.0, results[2], $tolerance)
39
+
40
+ results = COLOR.circle_color((2.0 * PI) * (4.0/6.0))
41
+ assert_in_delta(0.0, results[0], $tolerance)
42
+ assert_in_delta(0.0, results[1], $tolerance)
43
+ assert_in_delta(1.0, results[2], $tolerance)
44
+
45
+ results = COLOR.circle_color((2.0 * PI) * (5.0/6.0))
46
+ assert_in_delta(1.0, results[0], $tolerance)
47
+ assert_in_delta(0.0, results[1], $tolerance)
48
+ assert_in_delta(1.0, results[2], $tolerance)
49
+
50
+ results = COLOR.circle_color(2.0 * PI)
51
+ assert_in_delta(1.0, results[0], $tolerance)
52
+ assert_in_delta(0.0, results[1], $tolerance)
53
+ assert_in_delta(0.0, results[2], $tolerance)
54
+
55
+
56
+ results = COLOR.circle_color((2.0 * PI) * (1.0/12.0))
57
+ assert_in_delta(1.0, results[0], $tolerance)
58
+ assert_in_delta(0.5, results[1], $tolerance)
59
+ assert_in_delta(0.0, results[2], $tolerance)
60
+
61
+ # out of range , 0 <= theta < pi
62
+ results = COLOR.circle_color((2.0 * PI) * (9.0/6.0))
63
+ assert_in_delta(0.0, results[0], $tolerance)
64
+ assert_in_delta(1.0, results[1], $tolerance)
65
+ assert_in_delta(1.0, results[2], $tolerance)
66
+
67
+ results = COLOR.circle_color((2.0 * PI) * (-3.0/6.0))
68
+ assert_in_delta(0.0, results[0], $tolerance)
69
+ assert_in_delta(1.0, results[1], $tolerance)
70
+ assert_in_delta(1.0, results[2], $tolerance)
71
+ end
72
+
73
+ def test_trapezoidal_wave
74
+ assert_in_delta(0.0, COLOR.trapezoidal_wave(( 0.0/12.0)*2.0*PI, 0.0), $tolerance)
75
+ assert_in_delta(0.5, COLOR.trapezoidal_wave(( 1.0/12.0)*2.0*PI, 0.0), $tolerance)
76
+ assert_in_delta(1.0, COLOR.trapezoidal_wave(( 2.0/12.0)*2.0*PI, 0.0), $tolerance)
77
+ assert_in_delta(1.0, COLOR.trapezoidal_wave(( 3.0/12.0)*2.0*PI, 0.0), $tolerance)
78
+ assert_in_delta(1.0, COLOR.trapezoidal_wave(( 4.0/12.0)*2.0*PI, 0.0), $tolerance)
79
+ assert_in_delta(1.0, COLOR.trapezoidal_wave(( 5.0/12.0)*2.0*PI, 0.0), $tolerance)
80
+ assert_in_delta(1.0, COLOR.trapezoidal_wave(( 6.0/12.0)*2.0*PI, 0.0), $tolerance)
81
+ assert_in_delta(0.5, COLOR.trapezoidal_wave(( 7.0/12.0)*2.0*PI, 0.0), $tolerance)
82
+ assert_in_delta(0.0, COLOR.trapezoidal_wave(( 8.0/12.0)*2.0*PI, 0.0), $tolerance)
83
+ assert_in_delta(0.0, COLOR.trapezoidal_wave(( 9.0/12.0)*2.0*PI, 0.0), $tolerance)
84
+ assert_in_delta(0.0, COLOR.trapezoidal_wave((10.0/12.0)*2.0*PI, 0.0), $tolerance)
85
+ assert_in_delta(0.0, COLOR.trapezoidal_wave((11.0/12.0)*2.0*PI, 0.0), $tolerance)
86
+
87
+ assert_in_delta(1.0, COLOR.trapezoidal_wave(( 0.0/12.0)*2.0*PI, PI), $tolerance)
88
+ assert_in_delta(0.5, COLOR.trapezoidal_wave(( 1.0/12.0)*2.0*PI, PI), $tolerance)
89
+ assert_in_delta(0.0, COLOR.trapezoidal_wave(( 2.0/12.0)*2.0*PI, PI), $tolerance)
90
+ assert_in_delta(0.0, COLOR.trapezoidal_wave(( 3.0/12.0)*2.0*PI, PI), $tolerance)
91
+ assert_in_delta(0.0, COLOR.trapezoidal_wave(( 4.0/12.0)*2.0*PI, PI), $tolerance)
92
+ assert_in_delta(0.0, COLOR.trapezoidal_wave(( 5.0/12.0)*2.0*PI, PI), $tolerance)
93
+ assert_in_delta(0.0, COLOR.trapezoidal_wave(( 6.0/12.0)*2.0*PI, PI), $tolerance)
94
+ assert_in_delta(0.5, COLOR.trapezoidal_wave(( 7.0/12.0)*2.0*PI, PI), $tolerance)
95
+ assert_in_delta(1.0, COLOR.trapezoidal_wave(( 8.0/12.0)*2.0*PI, PI), $tolerance)
96
+ assert_in_delta(1.0, COLOR.trapezoidal_wave(( 9.0/12.0)*2.0*PI, PI), $tolerance)
97
+ assert_in_delta(1.0, COLOR.trapezoidal_wave((10.0/12.0)*2.0*PI, PI), $tolerance)
98
+ assert_in_delta(1.0, COLOR.trapezoidal_wave((11.0/12.0)*2.0*PI, PI), $tolerance)
99
+
100
+ assert_in_delta(1.0, COLOR.trapezoidal_wave((-6.0/12.0)*2.0*PI, 0.0), $tolerance)
101
+ assert_in_delta(1.0, COLOR.trapezoidal_wave((18.0/12.0)*2.0*PI, 0.0), $tolerance)
102
+ end
103
+ end
104
+
105
+ #! /usr/bin/env ruby # coding: utf-8
106
+