-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathepf_geo.pl
98 lines (85 loc) · 2.91 KB
/
epf_geo.pl
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
87
88
89
90
91
92
93
94
95
96
97
98
:- module(epf_geo, [termp//1, terms//1, selectp//1, find//2, vertical_layout//3]).
:- use_module(library(delay)).
:- use_module(library(clpBNR)).
:- use_module(ccx).
:- use_module(seg).
:- use_module(epf).
:- use_module(state).
:- use_module(cond).
:- use_module(geo).
:- use_module(utils).
delay:mode(epf_geo:in_scope(nonvar, _)).
in_scope(Term, Scopes) :-
delay(compound_name_arity(Term, Name, _)),
in_scope(Name, Term, Scopes).
in_scope(seg, Seg, Scopes) :-
segEtiqs(Seg, Etiqs),
maplist(in_scope_end(Etiqs), Scopes).
in_scope(ccx, Ccx, Scopes) :-
ccxEtiqs(Ccx, Etiqs),
maplist(in_scope_end(Etiqs), Scopes).
in_scope_end(Etiqs, Scope) :-
delay(memberchk(Scope, Etiqs)).
in_bounding_box(Term, BBoxes) :-
in_bounding_box_(BBoxes, Term).
in_bounding_box_([], _).
in_bounding_box_([BBox | _], Term) :-
debug(in_bounding_box, "BBox ~p~n", [BBox]),
debug(in_bounding_box, "Term ~p~n", [Term]),
delay(inside(Term, BBox)).
termp(Term) -->
statep(delay:delay(epf_geo:in_scope(Term)), [o(scope)]),
statep(in_bounding_box(Term), [o(bbox)]),
cursor(term, Term).
terms(Term) -->
statep(delay:delay(epf_geo:in_scope(Term)), [o(scope)]),
cursor(term, Term).
selectp(Term) -->
statep(delay:delay(geo:inside(Term)), [o(page)]),
statep(in_bounding_box(Term), [o(bbox)]),
cursor(select, Term),
{debug(epf_geo, "selectp Term ~p~n", [Term])}.
:- meta_predicate cursor(3, ?, ?, ?).
cursor_state(term, Cursor) -->
state(-(cursor, Cursor, noEl)).
cursor_state(select, Cursor) -->
state(o(cursor, Cursor)).
cursor(Mod:Goal, Term) -->
cursor_state(Goal, Cursor),
cursor_(Cursor, Mod:Goal, Term).
cursor_(cursor(Term), _, Term) -->
{true}.
cursor_(noEl, Goal, Term) -->
call(Goal, Term).
:- meta_predicate find(1, ?, ?, ?).
find(Goal, Arg) -->
state(o(cursor, Cursor)),
find_(Cursor, Goal, Arg).
find_(cursor(_), Goal, Arg) -->
call(Goal, Arg).
find_(noEl, Goal, Arg) -->
term(Term),
state(+(cursor, cursor(Term))),
call(Goal, Arg).
:- meta_predicate vertical_layout(4, ?, ?, ?, ?).
vertical_layout(Goal, Margin, SequenceIn) -->
state(o(bbox, [box(P, _) | _])),
{Box = box(P, _)},
reify(bbox(call(Goal, SequenceIn, SequenceOut), Box), Result),
vertical_layout(Result, Goal, Margin, Box, SequenceIn, SequenceOut).
vertical_layoutCond(Margin, PrevBox, Box, Unit, Eps) :-
PrevBox = box(point(X1, _), point(X2, Y2)),
Box = box(point(X1, Y1), point(X2, _)),
eps(Eps, Y2 + Margin*Unit, Y1).
vertical_layout(Goal, Margin, PrevBox, SequenceIn) -->
statep(vertical_layoutCond(Margin, PrevBox, Box), [o(unit), o(eps)]),
reify(bbox(call(Goal, SequenceIn, SequenceOut), Box), Result),
vertical_layout(Result, Goal, Margin, Box, SequenceIn, SequenceOut).
vertical_layout(true, Goal, Margin, Box, _, Sequence) -->
{
Box = box(_, point(_, Y)),
global_minimize(Y, Y)
},
vertical_layout(Goal, Margin, Box, Sequence).
vertical_layout(false, _, _, box(_, point(X, _)), [], _) -->
{ global_minimize(X, X) }.