rays 0.1.8 → 0.1.9
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/.doc/ext/rays/painter.cpp +29 -22
- data/.doc/ext/rays/point.cpp +25 -0
- data/VERSION +1 -1
- data/ext/rays/painter.cpp +29 -22
- data/ext/rays/point.cpp +28 -0
- data/include/rays/color.h +1 -0
- data/include/rays/painter.h +22 -3
- data/include/rays/point.h +6 -0
- data/lib/rays/color.rb +30 -4
- data/lib/rays/painter.rb +3 -23
- data/src/painter.cpp +28 -12
- data/src/point.cpp +25 -0
- data/test/test_color.rb +18 -18
- data/test/test_point.rb +19 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7ebe243b01fc7a01ec4ff0a6cec05648f8cca592
|
4
|
+
data.tar.gz: 0865209e13e9aaaf678d215df4afe9b3262d094d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ef1548261bc1ef3d7710f47422ea7a8f6dda287fe452f619545b4bd7cda47837ada92b090eae6dedec51d758b70628d38f1e65adc381230cfa1d463c53fa648e
|
7
|
+
data.tar.gz: bae292886978f083b34fd2506960865591787ccebc3fb0c2f9bb0d6b6ef17cacdfe2219dbf84dcce5cbc585014775f06377c70009ad7930c31043f5f4f97d42b
|
data/.doc/ext/rays/painter.cpp
CHANGED
@@ -132,17 +132,24 @@ static
|
|
132
132
|
VALUE rect(VALUE self)
|
133
133
|
{
|
134
134
|
CHECK;
|
135
|
-
check_arg_count(__FILE__, __LINE__, "Painter#rect", argc, 1, 4);
|
135
|
+
check_arg_count(__FILE__, __LINE__, "Painter#rect", argc, 1, 2, 3, 4, 5, 6);
|
136
136
|
|
137
|
-
if (argc
|
138
|
-
|
137
|
+
if (argc <= 3)
|
138
|
+
{
|
139
|
+
Rays::Bounds& b = to<Rays::Bounds&>(argv[0]);
|
140
|
+
coord rw = argc >= 2 ? to<coord>(argv[1]) : 0;
|
141
|
+
coord rh = argc >= 3 ? to<coord>(argv[2]) : rw;
|
142
|
+
THIS->rect(b, rw, rh);
|
143
|
+
}
|
139
144
|
else
|
140
145
|
{
|
141
|
-
coord x
|
142
|
-
coord y
|
143
|
-
coord w
|
144
|
-
coord h
|
145
|
-
|
146
|
+
coord x = to<coord>(argv[0]);
|
147
|
+
coord y = to<coord>(argv[1]);
|
148
|
+
coord w = to<coord>(argv[2]);
|
149
|
+
coord h = to<coord>(argv[3]);
|
150
|
+
coord rw = argc >= 5 ? to<coord>(argv[4]) : 0;
|
151
|
+
coord rh = argc >= 6 ? to<coord>(argv[5]) : rw;
|
152
|
+
THIS->rect(x, y, w, h, rw, rh);
|
146
153
|
}
|
147
154
|
|
148
155
|
return self;
|
@@ -184,23 +191,23 @@ VALUE arc(VALUE self)
|
|
184
191
|
if (argv[0].is_kind_of(Rays::bounds_class()))
|
185
192
|
{
|
186
193
|
const Rays::Bounds& b = to<Rays::Bounds&>(argv[0]);
|
187
|
-
float
|
188
|
-
float
|
189
|
-
coord min_
|
190
|
-
uint nseg
|
191
|
-
THIS->arc(b,
|
194
|
+
float begin = (argc >= 2) ? to<float>(argv[1]) : 0;
|
195
|
+
float end = (argc >= 3) ? to<float>(argv[2]) : 360;
|
196
|
+
coord min_ = (argc >= 4) ? to<coord>(argv[3]) : 0;
|
197
|
+
uint nseg = (argc >= 5) ? to<uint> (argv[4]) : 0;
|
198
|
+
THIS->arc(b, begin, end, min_, nseg);
|
192
199
|
}
|
193
200
|
else
|
194
201
|
{
|
195
|
-
coord x
|
196
|
-
coord y
|
197
|
-
coord w
|
198
|
-
coord h
|
199
|
-
float
|
200
|
-
float
|
201
|
-
coord min_
|
202
|
-
uint nseg
|
203
|
-
THIS->arc(x, y, w, h,
|
202
|
+
coord x = to<coord>(argv[0]);
|
203
|
+
coord y = to<coord>(argv[1]);
|
204
|
+
coord w = to<coord>(argv[2]);
|
205
|
+
coord h = (argc >= 4) ? to<coord>(argv[3]) : 0;
|
206
|
+
float begin = (argc >= 5) ? to<float>(argv[4]) : 0;
|
207
|
+
float end = (argc >= 6) ? to<float>(argv[5]) : 360;
|
208
|
+
coord min_ = (argc >= 7) ? to<coord>(argv[6]) : 0;
|
209
|
+
uint nseg = (argc >= 8) ? to<uint> (argv[7]) : 0;
|
210
|
+
THIS->arc(x, y, w, h, begin, end, min_, nseg);
|
204
211
|
}
|
205
212
|
|
206
213
|
return self;
|
data/.doc/ext/rays/point.cpp
CHANGED
@@ -95,6 +95,28 @@ VALUE move_by(VALUE self)
|
|
95
95
|
return self;
|
96
96
|
}
|
97
97
|
|
98
|
+
static
|
99
|
+
VALUE length(VALUE self)
|
100
|
+
{
|
101
|
+
CHECK;
|
102
|
+
return value(THIS->length());
|
103
|
+
}
|
104
|
+
|
105
|
+
static
|
106
|
+
VALUE normalize(VALUE self)
|
107
|
+
{
|
108
|
+
CHECK;
|
109
|
+
THIS->normalize();
|
110
|
+
return self;
|
111
|
+
}
|
112
|
+
|
113
|
+
static
|
114
|
+
VALUE normal(VALUE self)
|
115
|
+
{
|
116
|
+
CHECK;
|
117
|
+
return value(THIS->normal());
|
118
|
+
}
|
119
|
+
|
98
120
|
static
|
99
121
|
VALUE set_x(VALUE self, VALUE x)
|
100
122
|
{
|
@@ -223,6 +245,9 @@ Init_point ()
|
|
223
245
|
rb_define_private_method(cPoint, "initialize_copy", RUBY_METHOD_FUNC(initialize_copy), 1);
|
224
246
|
cPoint.define_method("move_to!", move_to);
|
225
247
|
cPoint.define_method("move_by!", move_by);
|
248
|
+
rb_define_method(cPoint, "length", RUBY_METHOD_FUNC(length), 0);
|
249
|
+
rb_define_method(cPoint, "normalize", RUBY_METHOD_FUNC(normalize), 0);
|
250
|
+
rb_define_method(cPoint, "normal", RUBY_METHOD_FUNC(normal), 0);
|
226
251
|
rb_define_method(cPoint, "x=", RUBY_METHOD_FUNC(set_x), 1);
|
227
252
|
rb_define_method(cPoint, "x", RUBY_METHOD_FUNC(get_x), 0);
|
228
253
|
rb_define_method(cPoint, "y=", RUBY_METHOD_FUNC(set_y), 1);
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.9
|
data/ext/rays/painter.cpp
CHANGED
@@ -141,17 +141,24 @@ static
|
|
141
141
|
RUCY_DEFN(rect)
|
142
142
|
{
|
143
143
|
CHECK;
|
144
|
-
check_arg_count(__FILE__, __LINE__, "Painter#rect", argc, 1, 4);
|
144
|
+
check_arg_count(__FILE__, __LINE__, "Painter#rect", argc, 1, 2, 3, 4, 5, 6);
|
145
145
|
|
146
|
-
if (argc
|
147
|
-
|
146
|
+
if (argc <= 3)
|
147
|
+
{
|
148
|
+
Rays::Bounds& b = to<Rays::Bounds&>(argv[0]);
|
149
|
+
coord rw = argc >= 2 ? to<coord>(argv[1]) : 0;
|
150
|
+
coord rh = argc >= 3 ? to<coord>(argv[2]) : rw;
|
151
|
+
THIS->rect(b, rw, rh);
|
152
|
+
}
|
148
153
|
else
|
149
154
|
{
|
150
|
-
coord x
|
151
|
-
coord y
|
152
|
-
coord w
|
153
|
-
coord h
|
154
|
-
|
155
|
+
coord x = to<coord>(argv[0]);
|
156
|
+
coord y = to<coord>(argv[1]);
|
157
|
+
coord w = to<coord>(argv[2]);
|
158
|
+
coord h = to<coord>(argv[3]);
|
159
|
+
coord rw = argc >= 5 ? to<coord>(argv[4]) : 0;
|
160
|
+
coord rh = argc >= 6 ? to<coord>(argv[5]) : rw;
|
161
|
+
THIS->rect(x, y, w, h, rw, rh);
|
155
162
|
}
|
156
163
|
|
157
164
|
return self;
|
@@ -195,23 +202,23 @@ RUCY_DEFN(arc)
|
|
195
202
|
if (argv[0].is_kind_of(Rays::bounds_class()))
|
196
203
|
{
|
197
204
|
const Rays::Bounds& b = to<Rays::Bounds&>(argv[0]);
|
198
|
-
float
|
199
|
-
float
|
200
|
-
coord min_
|
201
|
-
uint nseg
|
202
|
-
THIS->arc(b,
|
205
|
+
float begin = (argc >= 2) ? to<float>(argv[1]) : 0;
|
206
|
+
float end = (argc >= 3) ? to<float>(argv[2]) : 360;
|
207
|
+
coord min_ = (argc >= 4) ? to<coord>(argv[3]) : 0;
|
208
|
+
uint nseg = (argc >= 5) ? to<uint> (argv[4]) : 0;
|
209
|
+
THIS->arc(b, begin, end, min_, nseg);
|
203
210
|
}
|
204
211
|
else
|
205
212
|
{
|
206
|
-
coord x
|
207
|
-
coord y
|
208
|
-
coord w
|
209
|
-
coord h
|
210
|
-
float
|
211
|
-
float
|
212
|
-
coord min_
|
213
|
-
uint nseg
|
214
|
-
THIS->arc(x, y, w, h,
|
213
|
+
coord x = to<coord>(argv[0]);
|
214
|
+
coord y = to<coord>(argv[1]);
|
215
|
+
coord w = to<coord>(argv[2]);
|
216
|
+
coord h = (argc >= 4) ? to<coord>(argv[3]) : 0;
|
217
|
+
float begin = (argc >= 5) ? to<float>(argv[4]) : 0;
|
218
|
+
float end = (argc >= 6) ? to<float>(argv[5]) : 360;
|
219
|
+
coord min_ = (argc >= 7) ? to<coord>(argv[6]) : 0;
|
220
|
+
uint nseg = (argc >= 8) ? to<uint> (argv[7]) : 0;
|
221
|
+
THIS->arc(x, y, w, h, begin, end, min_, nseg);
|
215
222
|
}
|
216
223
|
|
217
224
|
return self;
|
data/ext/rays/point.cpp
CHANGED
@@ -100,6 +100,31 @@ RUCY_DEFN(move_by)
|
|
100
100
|
}
|
101
101
|
RUCY_END
|
102
102
|
|
103
|
+
static
|
104
|
+
RUCY_DEF0(length)
|
105
|
+
{
|
106
|
+
CHECK;
|
107
|
+
return value(THIS->length());
|
108
|
+
}
|
109
|
+
RUCY_END
|
110
|
+
|
111
|
+
static
|
112
|
+
RUCY_DEF0(normalize)
|
113
|
+
{
|
114
|
+
CHECK;
|
115
|
+
THIS->normalize();
|
116
|
+
return self;
|
117
|
+
}
|
118
|
+
RUCY_END
|
119
|
+
|
120
|
+
static
|
121
|
+
RUCY_DEF0(normal)
|
122
|
+
{
|
123
|
+
CHECK;
|
124
|
+
return value(THIS->normal());
|
125
|
+
}
|
126
|
+
RUCY_END
|
127
|
+
|
103
128
|
static
|
104
129
|
RUCY_DEF1(set_x, x)
|
105
130
|
{
|
@@ -241,6 +266,9 @@ Init_point ()
|
|
241
266
|
cPoint.define_private_method("initialize_copy", initialize_copy);
|
242
267
|
cPoint.define_method("move_to!", move_to);
|
243
268
|
cPoint.define_method("move_by!", move_by);
|
269
|
+
cPoint.define_method("length", length);
|
270
|
+
cPoint.define_method("normalize", normalize);
|
271
|
+
cPoint.define_method("normal", normal);
|
244
272
|
cPoint.define_method("x=", set_x);
|
245
273
|
cPoint.define_method("x", get_x);
|
246
274
|
cPoint.define_method("y=", set_y);
|
data/include/rays/color.h
CHANGED
data/include/rays/painter.h
CHANGED
@@ -39,6 +39,13 @@ namespace Rays
|
|
39
39
|
|
40
40
|
public:
|
41
41
|
|
42
|
+
enum
|
43
|
+
{
|
44
|
+
|
45
|
+
ELLIPSE_NSEGMENT = 32
|
46
|
+
|
47
|
+
};
|
48
|
+
|
42
49
|
Painter ();
|
43
50
|
|
44
51
|
~Painter ();
|
@@ -76,9 +83,21 @@ namespace Rays
|
|
76
83
|
|
77
84
|
void polygon (const Coord3* points, size_t size);
|
78
85
|
|
79
|
-
void rect (
|
86
|
+
void rect (
|
87
|
+
coord x, coord y, coord width, coord height,
|
88
|
+
coord round = 0);
|
89
|
+
|
90
|
+
void rect (
|
91
|
+
coord x, coord y, coord width, coord height,
|
92
|
+
coord round_width, coord round_height);
|
80
93
|
|
81
|
-
void rect (
|
94
|
+
void rect (
|
95
|
+
const Bounds& bounds,
|
96
|
+
coord round = 0);
|
97
|
+
|
98
|
+
void rect (
|
99
|
+
const Bounds& bounds,
|
100
|
+
coord round_width, coord round_height);
|
82
101
|
|
83
102
|
void ellipse (
|
84
103
|
coord x, coord y, coord width, coord height = 0,
|
@@ -242,7 +261,7 @@ namespace Rays
|
|
242
261
|
|
243
262
|
void rotate (float angle, coord x = 0, coord y = 0, coord z = 1);
|
244
263
|
|
245
|
-
void rotate (float angle, const Point&
|
264
|
+
void rotate (float angle, const Point& axis);
|
246
265
|
|
247
266
|
void set_matrix (float value = 1);
|
248
267
|
|
data/include/rays/point.h
CHANGED
data/lib/rays/color.rb
CHANGED
@@ -11,8 +11,16 @@ module Rays
|
|
11
11
|
|
12
12
|
include Comparable
|
13
13
|
|
14
|
-
def self.
|
15
|
-
|
14
|
+
def self.color (*args)
|
15
|
+
c = case arg0 = args[0]
|
16
|
+
when Color then arg0
|
17
|
+
when Symbol then COLORS[arg0]
|
18
|
+
when /^\s*#[\da-fA-F]+\s*$/ then Color.new arg0
|
19
|
+
when String then COLORS[arg0.intern]
|
20
|
+
else Color.new *args
|
21
|
+
end
|
22
|
+
raise ArgumentError, "invalid argument '#{args}.'" unless c
|
23
|
+
c
|
16
24
|
end
|
17
25
|
|
18
26
|
def initialize (*args)
|
@@ -73,13 +81,31 @@ module Rays
|
|
73
81
|
"#<Rays::Color r=#{red}, g=#{green}, b=#{blue}, a=#{alpha}>"
|
74
82
|
end
|
75
83
|
|
84
|
+
COLORS = {
|
85
|
+
black: [0, 0, 0],
|
86
|
+
red: [1, 0, 0],
|
87
|
+
green: [0, 1, 0],
|
88
|
+
blue: [0, 0, 1],
|
89
|
+
yellow: [1, 1, 0],
|
90
|
+
cyan: [0, 1, 1],
|
91
|
+
magenta: [1, 0, 1],
|
92
|
+
white: [1, 1, 1],
|
93
|
+
gray: [0.5, 0.5, 0.5],
|
94
|
+
no: [0, 0],
|
95
|
+
none: [0, 0],
|
96
|
+
nil: [0, 0],
|
97
|
+
}.inject({}) {|h, (k, v)| h[k] = Color.new *v; h}
|
98
|
+
|
76
99
|
private
|
77
100
|
|
101
|
+
RE_RGBA = /^\s*##{'([\da-fA-F]{1})' * 4}?\s*$/
|
102
|
+
RE_RRGGBBAA = /^\s*##{'([\da-fA-F]{2})' * 4}?\s*$/
|
103
|
+
|
78
104
|
def parse (str)
|
79
105
|
case str
|
80
|
-
when
|
106
|
+
when RE_RGBA
|
81
107
|
[$1, $2, $3, $4 || 'f' ].map {|s| s.to_i(16) / 15.0}
|
82
|
-
when
|
108
|
+
when RE_RRGGBBAA
|
83
109
|
[$1, $2, $3, $4 || 'ff'].map {|s| s.to_i(16) / 255.0}
|
84
110
|
else raise ArgumentError, "can not parse '#{str}'."
|
85
111
|
end
|
data/lib/rays/painter.rb
CHANGED
@@ -99,18 +99,18 @@ module Rays
|
|
99
99
|
|
100
100
|
private
|
101
101
|
|
102
|
-
NONES = [:no, :none]
|
102
|
+
NONES = [:no, :none, nil]
|
103
103
|
|
104
104
|
def send_set (setter, getter, no, args, mode = nil)
|
105
105
|
args = args[0] if args[0].kind_of? Array
|
106
106
|
raise ArgumentError if args.empty?
|
107
107
|
|
108
108
|
arg0 = args[0]
|
109
|
-
if args.size == 1 &&
|
109
|
+
if args.size == 1 && NONES.include?(arg0)
|
110
110
|
no ? send(no) : send(setter, nil)
|
111
111
|
else
|
112
112
|
case mode
|
113
|
-
when :color then args =
|
113
|
+
when :color then args = Color.color *args
|
114
114
|
end
|
115
115
|
send setter, *args
|
116
116
|
end
|
@@ -135,26 +135,6 @@ module Rays
|
|
135
135
|
org
|
136
136
|
end
|
137
137
|
|
138
|
-
COLORS = {
|
139
|
-
black: [0, 0, 0],
|
140
|
-
red: [1, 0, 0],
|
141
|
-
green: [0, 1, 0],
|
142
|
-
blue: [0, 0, 1],
|
143
|
-
yellow: [1, 1, 0],
|
144
|
-
cyan: [0, 1, 1],
|
145
|
-
magenta: [1, 0, 1],
|
146
|
-
white: [1, 1, 1],
|
147
|
-
gray: [0.5, 0.5, 0.5],
|
148
|
-
}.inject({}) {|hash, (name, array)| hash[name] = Color.new *array; hash}
|
149
|
-
|
150
|
-
def to_color (args)
|
151
|
-
case arg0 = args[0]
|
152
|
-
when Symbol then [COLORS[arg0]]
|
153
|
-
when String then [(arg0 =~ /^\s*#[\da-fA-F]+\s*$/) ? Color.new(arg0) : COLORS[arg0.intern]]
|
154
|
-
else args
|
155
|
-
end
|
156
|
-
end
|
157
|
-
|
158
138
|
end# Painter
|
159
139
|
|
160
140
|
|
data/src/painter.cpp
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
|
2
|
-
|
3
1
|
#include "rays/painter.h"
|
4
2
|
|
5
3
|
|
@@ -37,7 +35,7 @@ namespace Rays
|
|
37
35
|
};// ColorType
|
38
36
|
|
39
37
|
|
40
|
-
static const float PI =
|
38
|
+
static const float PI = M_PI;
|
41
39
|
|
42
40
|
static const float PI_2 = PI * 2;
|
43
41
|
|
@@ -486,7 +484,15 @@ namespace Rays
|
|
486
484
|
}
|
487
485
|
|
488
486
|
void
|
489
|
-
Painter::rect (coord x, coord y, coord width, coord height)
|
487
|
+
Painter::rect (coord x, coord y, coord width, coord height, coord round)
|
488
|
+
{
|
489
|
+
rect(x, y, width, height, round, round);
|
490
|
+
}
|
491
|
+
|
492
|
+
void
|
493
|
+
Painter::rect (
|
494
|
+
coord x, coord y, coord width, coord height,
|
495
|
+
coord round_width, coord round_height)
|
490
496
|
{
|
491
497
|
static const GLenum MODES[] = {GL_TRIANGLE_FAN, GL_LINE_LOOP};
|
492
498
|
static const uint INDICES[] =
|
@@ -523,12 +529,20 @@ namespace Rays
|
|
523
529
|
}
|
524
530
|
|
525
531
|
void
|
526
|
-
Painter::rect (const Bounds& bounds)
|
532
|
+
Painter::rect (const Bounds& bounds, coord round)
|
527
533
|
{
|
528
|
-
rect(
|
534
|
+
rect(
|
535
|
+
bounds.x, bounds.y, bounds.width, bounds.height,
|
536
|
+
round);
|
529
537
|
}
|
530
538
|
|
531
|
-
|
539
|
+
void
|
540
|
+
Painter::rect (const Bounds& bounds, coord round_width, coord round_height)
|
541
|
+
{
|
542
|
+
rect(
|
543
|
+
bounds.x, bounds.y, bounds.width, bounds.height,
|
544
|
+
round_width, round_height);
|
545
|
+
}
|
532
546
|
|
533
547
|
static void
|
534
548
|
draw_ellipse (
|
@@ -546,7 +560,7 @@ namespace Rays
|
|
546
560
|
invalid_state_error(__FILE__, __LINE__, "self->painting should be true.");
|
547
561
|
|
548
562
|
if (height == 0) height = width;
|
549
|
-
if (nsegment <= 0) nsegment = ELLIPSE_NSEGMENT;
|
563
|
+
if (nsegment <= 0) nsegment = Painter::ELLIPSE_NSEGMENT;
|
550
564
|
|
551
565
|
coord radius_x = width / 2;
|
552
566
|
coord radius_y = height / 2;
|
@@ -584,7 +598,7 @@ namespace Rays
|
|
584
598
|
Coord2* vertex = vertices.get();
|
585
599
|
assert(vertex);
|
586
600
|
|
587
|
-
for (
|
601
|
+
for (uint seg = 0; seg < nsegment; ++seg, ++vertex)
|
588
602
|
{
|
589
603
|
float pos = (float) seg / (float) nsegment;
|
590
604
|
float radian = (from + (to - from) * pos) * PI_2;
|
@@ -619,7 +633,9 @@ namespace Rays
|
|
619
633
|
Painter::ellipse (
|
620
634
|
const Point& center, coord radius, coord radius_min, uint nsegment)
|
621
635
|
{
|
622
|
-
ellipse(
|
636
|
+
ellipse(
|
637
|
+
center.x - radius, center.y - radius, radius * 2, radius * 2,
|
638
|
+
radius_min, nsegment);
|
623
639
|
}
|
624
640
|
|
625
641
|
void
|
@@ -1193,9 +1209,9 @@ namespace Rays
|
|
1193
1209
|
}
|
1194
1210
|
|
1195
1211
|
void
|
1196
|
-
Painter::rotate (float angle, const Point&
|
1212
|
+
Painter::rotate (float angle, const Point& axis)
|
1197
1213
|
{
|
1198
|
-
rotate(angle,
|
1214
|
+
rotate(angle, axis.x, axis.y, axis.z);
|
1199
1215
|
}
|
1200
1216
|
|
1201
1217
|
void
|
data/src/point.cpp
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
#include "rays/point.h"
|
2
2
|
|
3
3
|
|
4
|
+
#include <math.h>
|
4
5
|
#include <xot/string.h>
|
5
6
|
#include "rays/exception.h"
|
6
7
|
|
@@ -114,6 +115,30 @@ namespace Rays
|
|
114
115
|
return *this;
|
115
116
|
}
|
116
117
|
|
118
|
+
coord
|
119
|
+
Point::length () const
|
120
|
+
{
|
121
|
+
return sqrt(x * x + y * y + z * z);
|
122
|
+
}
|
123
|
+
|
124
|
+
void
|
125
|
+
Point::normalize ()
|
126
|
+
{
|
127
|
+
coord len = length();
|
128
|
+
if (len == 0)
|
129
|
+
invalid_state_error(__FILE__, __LINE__);
|
130
|
+
|
131
|
+
*this /= len;
|
132
|
+
}
|
133
|
+
|
134
|
+
Point
|
135
|
+
Point::normal () const
|
136
|
+
{
|
137
|
+
Point t = *this;
|
138
|
+
t.normalize();
|
139
|
+
return t;
|
140
|
+
}
|
141
|
+
|
117
142
|
String
|
118
143
|
Point::inspect () const
|
119
144
|
{
|
data/test/test_color.rb
CHANGED
@@ -14,8 +14,8 @@ class TestColor < Test::Unit::TestCase
|
|
14
14
|
color *[r, g, b, a].map {|n| n / div.to_f}
|
15
15
|
end
|
16
16
|
|
17
|
-
def
|
18
|
-
Rays::Color.
|
17
|
+
def to_color (*args)
|
18
|
+
Rays::Color.color *args
|
19
19
|
end
|
20
20
|
|
21
21
|
def test_initialize ()
|
@@ -28,22 +28,22 @@ class TestColor < Test::Unit::TestCase
|
|
28
28
|
assert_raise(ArgumentError) {color(1, 2, 3, 4, 5)}
|
29
29
|
end
|
30
30
|
|
31
|
-
def
|
32
|
-
assert_equal color(0, 0, 0, 1),
|
33
|
-
assert_equal color(0, 0, 0, 1),
|
34
|
-
assert_equal color(0, 0, 0, 0),
|
35
|
-
assert_equal color(0, 0, 0, 0),
|
36
|
-
assert_equal color8(0x01, 0x23, 0x45, 0x67),
|
37
|
-
assert_equal color8(0x89, 0xab, 0xcd, 0xef),
|
38
|
-
assert_equal color8(0x0, 0x2, 0x4, 0x6, 15),
|
39
|
-
assert_equal color8(0x9, 0xb, 0xd, 0xf, 15),
|
40
|
-
assert_equal color(0, 0, 0, 1),
|
41
|
-
assert_raise(ArgumentError) {
|
42
|
-
assert_raise(ArgumentError) {
|
43
|
-
assert_raise(ArgumentError) {
|
44
|
-
assert_raise(ArgumentError) {
|
45
|
-
assert_raise(ArgumentError) {
|
46
|
-
assert_raise(ArgumentError) {
|
31
|
+
def test_color ()
|
32
|
+
assert_equal color(0, 0, 0, 1), to_color('#000')
|
33
|
+
assert_equal color(0, 0, 0, 1), to_color('#000000')
|
34
|
+
assert_equal color(0, 0, 0, 0), to_color('#0000')
|
35
|
+
assert_equal color(0, 0, 0, 0), to_color('#00000000')
|
36
|
+
assert_equal color8(0x01, 0x23, 0x45, 0x67), to_color('#01234567')
|
37
|
+
assert_equal color8(0x89, 0xab, 0xcd, 0xef), to_color('#89abcdef')
|
38
|
+
assert_equal color8(0x0, 0x2, 0x4, 0x6, 15), to_color('#0246')
|
39
|
+
assert_equal color8(0x9, 0xb, 0xd, 0xf, 15), to_color('#9bdf')
|
40
|
+
assert_equal color(0, 0, 0, 1), to_color(' #000 ')
|
41
|
+
assert_raise(ArgumentError) {to_color '#'}
|
42
|
+
assert_raise(ArgumentError) {to_color '000'}
|
43
|
+
assert_raise(ArgumentError) {to_color '#0'}
|
44
|
+
assert_raise(ArgumentError) {to_color '#00'}
|
45
|
+
assert_raise(ArgumentError) {to_color '#00000'}
|
46
|
+
assert_raise(ArgumentError) {to_color '#0000000'}
|
47
47
|
end
|
48
48
|
|
49
49
|
def test_get_rgb ()
|
data/test/test_point.rb
CHANGED
@@ -78,6 +78,25 @@ class TestPoint < Test::Unit::TestCase
|
|
78
78
|
assert_equal point(5, 7, 9), o1
|
79
79
|
end
|
80
80
|
|
81
|
+
def test_length ()
|
82
|
+
assert_in_delta 0, point(0).length
|
83
|
+
assert_in_delta 1, point(1, 0, 0).length
|
84
|
+
assert_in_delta Math.sqrt(2), point(1, 1, 0).length
|
85
|
+
end
|
86
|
+
|
87
|
+
def test_normalize ()
|
88
|
+
assert_in_delta 1, point( 1, 0, 0) .normalize.length
|
89
|
+
assert_in_delta 1, point( 1, 1, 0) .normalize.length
|
90
|
+
assert_in_delta 1, point( 1, 1, 1) .normalize.length
|
91
|
+
assert_in_delta 1, point(-1, -1, -1) .normalize.length
|
92
|
+
assert_in_delta 1, point( 10, 200, 3000).normalize.length
|
93
|
+
assert_raise(Rucy::NativeError) {point(0).normalize}
|
94
|
+
end
|
95
|
+
|
96
|
+
def test_normal ()
|
97
|
+
assert_equal point(1, 2, 3).normalize, point(1, 2, 3).normal
|
98
|
+
end
|
99
|
+
|
81
100
|
def test_to_a ()
|
82
101
|
o = point 1, 2, 3
|
83
102
|
assert_equal [1, 2], o.to_a
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rays
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- snori
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-11-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|