| 1 | unit Rectangle;
|
|---|
| 2 |
|
|---|
| 3 | // Date: 2011-03-20
|
|---|
| 4 |
|
|---|
| 5 | interface
|
|---|
| 6 |
|
|---|
| 7 | uses
|
|---|
| 8 | Classes, SysUtils;
|
|---|
| 9 |
|
|---|
| 10 | type
|
|---|
| 11 | { TRectangle }
|
|---|
| 12 |
|
|---|
| 13 | TRectangle = class
|
|---|
| 14 | private
|
|---|
| 15 | function GetBottomLeft: TPoint;
|
|---|
| 16 | function GetBottomRight: TPoint;
|
|---|
| 17 | function GetHeight: Integer;
|
|---|
| 18 | function GetTopLeft: TPoint;
|
|---|
| 19 | function GetTopRight: TPoint;
|
|---|
| 20 | function GetTRect: TRect;
|
|---|
| 21 | function GetWidth: Integer;
|
|---|
| 22 | procedure SetBottomLeft(const AValue: TPoint);
|
|---|
| 23 | procedure SetBottomRight(const AValue: TPoint);
|
|---|
| 24 | procedure SetHeight(const AValue: Integer);
|
|---|
| 25 | procedure SetTopLeft(const AValue: TPoint);
|
|---|
| 26 | procedure SetTopRight(const AValue: TPoint);
|
|---|
| 27 | procedure SetTRect(const AValue: TRect);
|
|---|
| 28 | procedure SetWidth(const AValue: Integer);
|
|---|
| 29 | public
|
|---|
| 30 | Left: Integer;
|
|---|
| 31 | Top: Integer;
|
|---|
| 32 | Right: Integer;
|
|---|
| 33 | Bottom: Integer;
|
|---|
| 34 |
|
|---|
| 35 | procedure Assign(Source: TRectangle);
|
|---|
| 36 | function IsInside(Pos: TPoint): Boolean;
|
|---|
| 37 |
|
|---|
| 38 | property Width: Integer read GetWidth write SetWidth;
|
|---|
| 39 | property Height: Integer read GetHeight write SetHeight;
|
|---|
| 40 |
|
|---|
| 41 | property TopLeft: TPoint read GetTopLeft write SetTopLeft;
|
|---|
| 42 | property TopRight: TPoint read GetTopRight write SetTopRight;
|
|---|
| 43 | property BottomLeft: TPoint read GetBottomLeft write SetBottomLeft;
|
|---|
| 44 | property BottomRight: TPoint read GetBottomRight write SetBottomRight;
|
|---|
| 45 |
|
|---|
| 46 | property AsTRect: TRect read GetTRect write SetTRect;
|
|---|
| 47 | end;
|
|---|
| 48 |
|
|---|
| 49 |
|
|---|
| 50 | implementation
|
|---|
| 51 |
|
|---|
| 52 | { TRectangle }
|
|---|
| 53 |
|
|---|
| 54 | function TRectangle.GetBottomLeft: TPoint;
|
|---|
| 55 | begin
|
|---|
| 56 | Result.X := Left;
|
|---|
| 57 | Result.Y := Bottom;
|
|---|
| 58 | end;
|
|---|
| 59 |
|
|---|
| 60 | function TRectangle.GetBottomRight: TPoint;
|
|---|
| 61 | begin
|
|---|
| 62 | Result.X := Right;
|
|---|
| 63 | Result.Y := Bottom;
|
|---|
| 64 | end;
|
|---|
| 65 |
|
|---|
| 66 | function TRectangle.GetHeight: Integer;
|
|---|
| 67 | begin
|
|---|
| 68 | Result := Bottom - Top;
|
|---|
| 69 | end;
|
|---|
| 70 |
|
|---|
| 71 | function TRectangle.GetTopLeft: TPoint;
|
|---|
| 72 | begin
|
|---|
| 73 | Result.X := Left;
|
|---|
| 74 | Result.Y := Top;
|
|---|
| 75 | end;
|
|---|
| 76 |
|
|---|
| 77 | function TRectangle.GetTopRight: TPoint;
|
|---|
| 78 | begin
|
|---|
| 79 | Result.X := Right;
|
|---|
| 80 | Result.Y := Top;
|
|---|
| 81 | end;
|
|---|
| 82 |
|
|---|
| 83 | function TRectangle.GetTRect: TRect;
|
|---|
| 84 | begin
|
|---|
| 85 | Result.Left := Left;
|
|---|
| 86 | Result.Top := Top;
|
|---|
| 87 | Result.Bottom := Bottom;
|
|---|
| 88 | Result.Right := Right;
|
|---|
| 89 | end;
|
|---|
| 90 |
|
|---|
| 91 | function TRectangle.GetWidth: Integer;
|
|---|
| 92 | begin
|
|---|
| 93 | Result := Right - Left;
|
|---|
| 94 | end;
|
|---|
| 95 |
|
|---|
| 96 | procedure TRectangle.SetBottomLeft(const AValue: TPoint);
|
|---|
| 97 | begin
|
|---|
| 98 | Left := AValue.X;
|
|---|
| 99 | Bottom := AValue.Y;
|
|---|
| 100 | end;
|
|---|
| 101 |
|
|---|
| 102 | procedure TRectangle.SetBottomRight(const AValue: TPoint);
|
|---|
| 103 | begin
|
|---|
| 104 | Right := AValue.X;
|
|---|
| 105 | Bottom := AValue.Y;
|
|---|
| 106 | end;
|
|---|
| 107 |
|
|---|
| 108 | procedure TRectangle.SetHeight(const AValue: Integer);
|
|---|
| 109 | begin
|
|---|
| 110 | Bottom := Top + AValue;
|
|---|
| 111 | end;
|
|---|
| 112 |
|
|---|
| 113 | procedure TRectangle.SetTopLeft(const AValue: TPoint);
|
|---|
| 114 | begin
|
|---|
| 115 | Left := AValue.X;
|
|---|
| 116 | Top := AValue.Y;
|
|---|
| 117 | end;
|
|---|
| 118 |
|
|---|
| 119 | procedure TRectangle.SetTopRight(const AValue: TPoint);
|
|---|
| 120 | begin
|
|---|
| 121 | Right := AValue.X;
|
|---|
| 122 | Top := AValue.Y;
|
|---|
| 123 | end;
|
|---|
| 124 |
|
|---|
| 125 | procedure TRectangle.SetTRect(const AValue: TRect);
|
|---|
| 126 | begin
|
|---|
| 127 | Left := AValue.Left;
|
|---|
| 128 | Top := AValue.Top;
|
|---|
| 129 | Bottom := AValue.Bottom;
|
|---|
| 130 | Right := AValue.Right;
|
|---|
| 131 | end;
|
|---|
| 132 |
|
|---|
| 133 | procedure TRectangle.SetWidth(const AValue: Integer);
|
|---|
| 134 | begin
|
|---|
| 135 | Right := Left + AValue;
|
|---|
| 136 | end;
|
|---|
| 137 |
|
|---|
| 138 | procedure TRectangle.Assign(Source: TRectangle);
|
|---|
| 139 | begin
|
|---|
| 140 | Left := Source.Left;
|
|---|
| 141 | Top := Source.Top;
|
|---|
| 142 | Right := Source.Right;
|
|---|
| 143 | Bottom := Source.Bottom;
|
|---|
| 144 | end;
|
|---|
| 145 |
|
|---|
| 146 | function TRectangle.IsInside(Pos: TPoint): Boolean;
|
|---|
| 147 | begin
|
|---|
| 148 | Result := (Pos.X >= Left) and (Pos.Y >= Top) and
|
|---|
| 149 | (Pos.X <= Right) and (Pos.Y <= Bottom);
|
|---|
| 150 | end;
|
|---|
| 151 |
|
|---|
| 152 | end.
|
|---|
| 153 |
|
|---|