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
|
Type
TBoundingBox = record
TopLeft : TPoint;
BottomRight : TPoint;
end;
TLayer = record
BoundingBox : TBoundingBox;
Bitmap : TBitmap;
end;
TLayers = specialize TFPGList<TLayer>; // cf : https://wiki.freepascal.org/Generics et https://www.freepascal.org/docs-html/current/rtl/fgl/tfpglist.html
procedure ComputeBoundingBox(Calque : TLayer; x,y : Integer);
begin
if x<Calque.BoundingBox.TopLeft.x then Calque.BoundingBox.TopLeft.x := x
else if x> Calque.BoundingBox.BottomRight.x then Calque.BoundingBox.BottomRight.x := x;
if y<Calque.BoundingBox.TopLeft.y then Calque.BoundingBox.TopLeft.y := y
else if y> Calque.BoundingBox.BottomRight.y then Calque.BoundingBox.BottomRight.y := y;
end;
Function IsInBoundingBox(Calque : TLayer; x,y : Integer): Boolean;
begin
// Algo Clipping Cohen-Sutherland
Result := (Ord(X < Calque.BoundingBox.TopLeft.x) + Ord(X > Calque.BoundingBox.BottomRight.x) Shl 1 + Ord(Y < Calque.BoundingBox.TopLeft.y) Shl 2 + Ord(Y > Calque.BoundingBox.BottomRight.y) Shl 3) = 0;
end; |
Partager