Janilabo

Untitled

Aug 26th, 2013
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.43 KB | None | 0 0
  1. {==============================================================================]
  2.   Explanation: Set minimum / maximum size to bx.
  3.                size.X1 = min. X1, size.Y1 = min. Y1, size.X2 = max. X2, size.Y2 = max. Y2
  4.                Returns true if constraints were set to bx.
  5. [==============================================================================}
  6. function SetBoxConstraints(var bx: TBox; size: TBox): Boolean;
  7. var
  8.   tmp: TBox;
  9. begin
  10.   if ((size.X1 <= size.X2) and (size.Y1 <= size.Y2)) then
  11.   begin
  12.     tmp := TBox(bx);
  13.     if (bx.X1 < size.X1) then
  14.       bx.X1 := Integer(size.X1);
  15.     if (bx.X1 > size.X2) then
  16.       bx.X1 := Integer(size.X2);
  17.     if (bx.Y1 < size.Y1) then
  18.       bx.Y1 := Integer(size.Y1);
  19.     if (bx.Y1 > size.Y2) then
  20.       bx.Y1 := Integer(size.Y2);
  21.     if (bx.X2 > size.X2) then
  22.       bx.X2 := Integer(size.X2);
  23.     if (bx.X2 < size.X1) then
  24.       bx.X2 := Integer(size.X1);
  25.     if (bx.Y2 > size.Y2) then
  26.       bx.Y2 := Integer(size.Y2);
  27.     if (bx.Y2 < size.Y1) then
  28.       bx.Y2 := Integer(size.Y1);
  29.     Result := ((bx.X1 <> tmp.X1) or (bx.Y1 <> tmp.Y1) or (bx.X2 <> tmp.X2) or (bx.Y2 <> tmp.Y2));
  30.   end else
  31.     Result := False;
  32. end;
  33.  
  34. var
  35.   b: TBox;
  36.  
  37. begin
  38.   b := IntToBox(100, 100, 400, 400);
  39.   if SetBoxConstraints(b, IntToBox(250, 250, 500, 500)) then
  40.     WriteLn(b);
  41.   b := IntToBox(100, 100, 400, 400);
  42.   if SetBoxConstraints(b, IntToBox(0, 0, 300, 300)) then
  43.     WriteLn(b);
  44. end.
Advertisement
Add Comment
Please, Sign In to add comment