disjoint((_,R,_,_),(L1,_,_,_)) :- R #=< L1.
disjoint((L,_,_,_),(_,R1,_,_)) :- L #>= R1.
disjoint((_,_,_,U),(_,_,D1,_)) :- U #=< D1.
disjoint((_,_,D,_),(_,_,_,U1)) :- D #>= U1.

alldisjoint(_,[]).
alldisjoint(Q,[H|T]) :- disjoint(Q,H), alldisjoint(Q,T).

p([],_,_,[],[]).
p([(X,Y)|Rest], Width, Height, [(L,R,D,U)|Plan], [L,R,D,U|Vars]) :-
	fd_domain([L,R],0,Width),
	fd_domain([D,U],0,Height),
	R #= L + X,
	U #= D + Y,
	p(Rest,Width, Height, Plan, Vars),
	alldisjoint((L,R,D,U), Plan).

paving(In,Width,Height,Plan) :-
	p(In,Width,Height,Plan,Vars),
	fd_labeling(Vars).
    