-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.wavefront.m
More file actions
86 lines (75 loc) · 2.86 KB
/
test.wavefront.m
File metadata and controls
86 lines (75 loc) · 2.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
:- module test.wavefront.
%==============================================================================%
:- interface.
%==============================================================================%
:- use_module io.
%------------------------------------------------------------------------------%
:- pred test(io.io::di, io.io::uo) is det.
%==============================================================================%
:- implementation.
%==============================================================================%
:- use_module wavefront.
:- use_module model.
:- import_module list.
%------------------------------------------------------------------------------%
:- type vt == wavefront.vertex.
:- type tx == model.tex.
%------------------------------------------------------------------------------%
:- func test1src = string.
:- func test1src_comment = string.
:- pred test1ver(wavefront.shape::in) is semidet.
:- pred wavefront_tester(string::in, wavefront.shape::out) is det.
wavefront_tester(Src, Out) :- wavefront.load(Src, wavefront.init_shape, Out).
test1src = "
v 0.0 0.0 0.0
v 0.0 1.0 0.0
v 1.0 0.0 0.0
f 1 2 3
".
test1src_comment = "
v 0.0 0.0 0.0 # This is a comment.
v 0.0 1.0 0.0
v 1.0 0.0 0.0
# A comment here, too.
# v 0.0 0.0 0.0
f 1 2 3
".
test1ver(Shape) :-
Shape = wavefront.shape(
[model.point(0.0, 0.0, 0.0) |
[model.point(0.0, 1.0, 0.0) |
[model.point(1.0, 0.0, 0.0) | []]]],
[],
[],
[wavefront.face([
wavefront.vertex(0, 0) | [
wavefront.vertex(1, 0) | [
wavefront.vertex(2, 0) | []]]])|[]]).
%------------------------------------------------------------------------------%
:- pred test(io.io::di, io.io::uo, int::di, int::uo, int::di, int::uo) is det.
test(!IO) :- test(!IO, 0, OK, 0, Sum), sum_suite(!IO, "Wavefront", OK, Sum).
test(!IO, !N, !Sum) :-
run_test(!IO, "Triangle", test1src, test1ver, wavefront_tester, !N, !Sum),
run_test(!IO, "Comment", test1src_comment, test1ver, wavefront_tester, !N, !Sum),
% Do a full reflective test.
io.write_string("\nREFLECTIVE TEST: \n", !IO),
wavefront.load(test1src, wavefront.init_shape, Out),
io.write_string("Num faces: ", !IO),
io.write_int(list.length(Out ^ wavefront.faces), !IO),
io.nl(!IO),
( Out ^ wavefront.faces = [wavefront.face([P0|[P1|[P2|[]]]]) | []] ->
io.write_string("Face 1: ", !IO), io.nl(!IO),
wavefront.write_vertex(P0, !IO), io.nl(!IO),
wavefront.write_vertex(P1, !IO), io.nl(!IO),
wavefront.write_vertex(P2, !IO), io.nl(!IO)
;
true
),
( Out ^ wavefront.vertices = [V0 | [ V1 | [ V2 | [] ] ] ] ->
io.write_string("Points: ", !IO), io.nl(!IO),
wavefront.write_point(V0, !IO), io.nl(!IO),
wavefront.write_point(V1, !IO), io.nl(!IO),
wavefront.write_point(V2, !IO), io.nl(!IO)
;
true
).