procedure TGraphConstraints.ConfineRect(var Rect: TRect);

Please post bug reports, feature requests, or any question regarding the DELPHI AREA projects here.

procedure TGraphConstraints.ConfineRect(var Rect: TRect);

Postby elias » December 16th, 2005, 12:09 pm

Although two points (TopLeft and BottomRight) are enough to confine a Rectangle inside the bounds of SimpleGraph, it is necessary the points to keep the same relation of distance at x and y coordinates to keep the size of the rectangle; not only confining the two points separately:


Code: Select all
procedure TGraphConstraints.ConfineRect(var Rect: TRect);  //(It doesnt keep the size of the rect)
begin
  ConfinePt(Rect.TopLeft);     //confining point (TopLeft)
  ConfinePt(Rect.BottomRight);    //confining point (BottomRight)
end;


The alternative I found to this code is the following:

Code: Select all
procedure TGraphConstraints.ConfineRect(var Rect: TRect); //(Keeping the size of the Rect)
var DistanceBetweenYs,DistanceBetweenXs:integer;
begin

DistanceBetweenYs:=(Rect.Right-Rect.Left);   //   Right:Top
DistanceBetweenXs:=(Rect.Top-Rect.Bottom);   //   Left:Bottom

  if Rect.Left < BoundsRect.Left then
    Rect.Left := BoundsRect.Left;
  if Rect.Right - DistanceBetweenYs < BoundsRect.Left then
    Rect.Right := BoundsRect.Left+ DistanceBetweenYs;

  if Rect.Right > BoundsRect.Right then
    Rect.Right := BoundsRect.Right;
  if Rect.Left + DistanceBetweenYs > BoundsRect.Right then
    Rect.Left := BoundsRect.Right - DistanceBetweenYs;

  if Rect.Bottom > BoundsRect.Bottom then
    Rect.Bottom := BoundsRect.Bottom;
  if Rect.Top - DistanceBetweenXs > BoundsRect.Bottom then
    Rect.Top := BoundsRect.Bottom + DistanceBetweenXs;

  if Rect.Top < BoundsRect.Top then
    Rect.Top := BoundsRect.Top;
  if Rect.Bottom + DistanceBetweenXs < BoundsRect.Top then
    Rect.Bottom := BoundsRect.Top - DistanceBetweenXs;

end;


...yes...
elias
Senior Member
Senior Member
 
Posts: 90
Joined: November 8th, 2005, 12:09 pm
Location: Galicia, Spain

Postby Kambiz » December 17th, 2005, 10:39 am

Thank you elias!

I was missed this important issue.
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2429
Joined: March 7th, 2003, 7:10 pm


Return to DELPHI AREA Projects

Who is online

Users browsing this forum: No registered users and 3 guests

cron