Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {==============================================================================]
- Explanation: Set minimum / maximum size to bx.
- size.X1 = min. X1, size.Y1 = min. Y1, size.X2 = max. X2, size.Y2 = max. Y2
- Returns true if constraints were set to bx.
- [==============================================================================}
- function SetBoxConstraints(var bx: TBox; size: TBox): Boolean;
- var
- tmp: TBox;
- begin
- if ((size.X1 <= size.X2) and (size.Y1 <= size.Y2)) then
- begin
- tmp := TBox(bx);
- if (bx.X1 < size.X1) then
- bx.X1 := Integer(size.X1);
- if (bx.X1 > size.X2) then
- bx.X1 := Integer(size.X2);
- if (bx.Y1 < size.Y1) then
- bx.Y1 := Integer(size.Y1);
- if (bx.Y1 > size.Y2) then
- bx.Y1 := Integer(size.Y2);
- if (bx.X2 > size.X2) then
- bx.X2 := Integer(size.X2);
- if (bx.X2 < size.X1) then
- bx.X2 := Integer(size.X1);
- if (bx.Y2 > size.Y2) then
- bx.Y2 := Integer(size.Y2);
- if (bx.Y2 < size.Y1) then
- bx.Y2 := Integer(size.Y1);
- Result := ((bx.X1 <> tmp.X1) or (bx.Y1 <> tmp.Y1) or (bx.X2 <> tmp.X2) or (bx.Y2 <> tmp.Y2));
- end else
- Result := False;
- end;
- var
- b: TBox;
- begin
- b := IntToBox(100, 100, 400, 400);
- if SetBoxConstraints(b, IntToBox(250, 250, 500, 500)) then
- WriteLn(b);
- b := IntToBox(100, 100, 400, 400);
- if SetBoxConstraints(b, IntToBox(0, 0, 300, 300)) then
- WriteLn(b);
- end.
Advertisement
Add Comment
Please, Sign In to add comment