# Board index » delphi » tpoint - tRect

## tpoint - tRect

Is there a function that can test if a tPoint falls within a tRect?

## Re:tpoint - tRect

Hi,
Try this

function PointInRect(aPoint: TPoint; aRect: TRect): boolean;
begin
result := (aPoint.X > aRect.Left) and (aPoint.X < aRect.Right) and
(aPoint.Y > aRect.Top) and (aPoint.Y < aRect.Bottom);
end;

Hope this helps,

Regards,
Ananth B.

##### Quote
"D Whaley" <dwha...@hs-technologies.com> wrote in message

news:3e958cd4@newsgroups.borland.com...
##### Quote
> Is there a function that can test if a tPoint falls [snip]

## Re:tpoint - tRect

Hi Ananth,

Ananth B. wrote in <3e958...@newsgroups.borland.com>:

##### Quote
> function PointInRect(aPoint: TPoint; aRect: TRect): boolean;
> begin
>   result := (aPoint.X > aRect.Left) and (aPoint.X < aRect.Right) and
> (aPoint.Y > aRect.Top) and (aPoint.Y < aRect.Bottom);
> end;

Note, that TRect.Right and TRect.Bottom are always outside from the
rectangle, but TRect.Left and TRect.Top can be part of the rectangle
(dependant from the definition).

function PointInRect(const APoint: TPoint; const ARect: TRect): Boolean;
begin
Result := (ARect.Left <= APoint.X) and (APoint.X < ARect.Right) and
(ARect.Top <= APoint.Y) and (APoint.Y < ARect.Bottom);
end;

or

function PointInRect(const APoint: TPoint; const ARect: TRect): Boolean;
begin
Result := (ARect.Left < APoint.X) and (APoint.X < ARect.Right - 1) and
(ARect.Top < APoint.Y) and (APoint.Y < ARect.Bottom - 1);
end;

Bye Peter.
--
Why should we be interested is someone who considers us a waste basket?
Robert Marquardt (Team JEDI) in <b4mf4g\$u0...@talkto.net> to me
regarding JEDI's disinterest on my contribution attempts.
Maybe JEDI users have more interest: http://jediplus.pjh2.de/index.php

## Re:tpoint - tRect

BOOL PtInRect(

CONST RECT *lprc, // address of structure with rectangle
POINT pt  // structure with point
);
WIn32.. API..

##### Quote
D Whaley wrote:
> Is there a function that can test if a tPoint falls within a tRect?

## Re:tpoint - tRect

PtInRect

--
Regards
Boris Novgorodov

##### Quote
> Is there a function that can test if a tPoint falls within a tRect?

## Re:tpoint - tRect

Thanks, Peter. I didnt know that.

##### Quote
"Peter Haas" <newsgroupfeedb...@pjh2.de> wrote in message

news:3e95a24d\$1@newsgroups.borland.com...
##### Quote
> Hi Ananth,

> Ananth B. wrote in <3e958...@newsgroups.borland.com>:
> > function PointInRect(aPoint: TPoint; aRect: TRect): boolean;
> > begin [snip]