root/trunk/examples/polygons/polygons.lgt

Revision 4601, 3.5 KB (checked in by pmoura, 7 weeks ago)

Added svn:mime-type property to source files (set to text/x-logtalk).

  • Property svn:mime-type set to text/x-logtalk
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1
2:- object(polygon,
3    instantiates(abstract_class),
4    specializes(object)).
5
6    :- info([
7        version is 1.2,
8        date is 2005/8/15,
9        author is 'Paulo Moura',
10        comment is 'Polygon predicates.']).
11
12    :- public(move/2).
13    :- mode(move(+integer, +integer), one).
14
15    :- public(trans_x/2).
16    :- mode(trans_x(+integer), one).
17
18    :- public(trans_y/2).
19    :- mode(trans_y(+integer), one).
20
21    :- public(number_of_sides/1).
22    :- mode(number_of_sides(?integer), zero_or_one).
23
24    :- public(position/2).
25    :- mode(position(?integer, ?integer), zero_or_one).
26
27    :- private(position_/2).
28    :- dynamic(position_/2).
29    :- mode(position_(?integer, ?integer), zero_or_one).
30
31    position(X, Y) :-
32        ::position_(X, Y).
33
34    move(X, Y) :-
35        ::retractall(position_(_, _)),
36        ::assertz(position_(X, Y)).
37
38    trans_x(X) :-
39        ::retractall(position_(_, Y)),
40        ::assertz(position_(X, Y)).
41
42    trans_y(Y) :-
43        ::retractall(position_(X, _)),
44        ::assertz(position_(X, Y)).
45
46    default_init_option(position-(0, 0)).
47    default_init_option(Default) :-
48        ^^default_init_option(Default).
49
50    process_init_option(position-(X, Y)) :-
51        ::move(X, Y).
52    process_init_option(Option) :-
53        ^^process_init_option(Option).
54
55:- end_object.
56
57
58
59
60:- object(triangle,
61    instantiates(class),
62    specializes(polygon)).
63
64    :- info([
65        version is 1.0,
66        date is 1998/3/23,
67        author is 'Paulo Moura',
68        comment is 'Triangle class.']).
69
70    number_of_sides(3).
71
72    instance_base_name(tri).
73
74:- end_object.
75
76
77
78
79:- object(square,
80    instantiates(class),
81    specializes(polygon)).
82
83    :- info([
84        version is 1.0,
85        date is 1998/3/23,
86        author is 'Paulo Moura',
87        comment is 'Square class.']).
88
89    number_of_sides(4).
90
91    instance_base_name(sq).
92
93:- end_object.
94
95
96
97
98
99:- object(pentagon,
100    instantiates(class),
101    specializes(polygon)).
102
103    :- info([
104        version is 1.0,
105        date is 1998/3/23,
106        author is 'Paulo Moura',
107        comment is 'Pentagon class.']).
108
109    number_of_sides(5).
110
111    instance_base_name(pen).
112
113:- end_object.
114
115
116
117
118:- object(hexagon,
119    instantiates(class),
120    specializes(polygon)).
121
122    :- info([
123        version is 1.0,
124        date is 1998/3/23,
125        author is 'Paulo Moura',
126        comment is 'Hexagon class.']).
127
128    number_of_sides(6).
129
130    instance_base_name(hex).
131
132:- end_object.
133
134
135
136
137:- object(concentric,
138    instantiates(constrained_relation)).
139
140    :- info([
141        version is 1.1,
142        date is 2004/8/15,
143        author is 'Paulo Moura',
144        comment is 'Concentric polygons as a constrained binary relation.']).
145
146    :- uses(list,
147        [member/2, select/3]).
148
149    descriptor_([x1, x2]).
150
151    domain_(x1, polygon).
152    domain_(x2, polygon).
153
154    key_([x1, x2]).
155
156    cardinality_(x1, 0, n).
157    cardinality_(x2, 0, n).
158
159    delete_option_(x1, cascade).
160    delete_option_(x2, cascade).
161
162    add_tuple([Polygon| Polygons]) :-
163        Polygon::position(X, Y),
164        forall(member(Polygon2, Polygons), {Polygon2::move(X, Y)}),
165        ^^add_tuple([Polygon| Polygons]).
166
167    activ_points_(x1, before, []).
168    activ_points_(x1, after, [move(_, _), trans_x(_), trans_y(_)]).
169
170    activ_points_(x2, before, []).
171    activ_points_(x2, after, [move(_, _), trans_x(_), trans_y(_)]).
172
173    propagate(after, move(X, Y), Polygon, _, Tuple) :-
174        select(Polygon, Tuple, Polygons),
175        !,
176        forall(
177            (member(Polygon2, Polygons),\+ Polygon2::position(X, Y)),
178            {Polygon2::move(X, Y)}).
179
180    propagate(after, trans_x(X), Polygon, _, Tuple) :-
181        select(Polygon, Tuple, Polygons),
182        !,
183        forall(
184            (member(Polygon2, Polygons), \+ Polygon2::position(X, _)),
185            {Polygon2::trans_x(X)}).
186
187    propagate(after, trans_y(Y), Polygon, _, Tuple) :-
188        select(Polygon, Tuple, Polygons),
189        !,
190        forall(
191            (member(Polygon2, Polygons), \+ Polygon2::position(_, Y)),
192            {Polygon2::trans_y(Y)}).
193
194:- end_object.
Note: See TracBrowser for help on using the browser.