There's three bugs in Function RectangularHull. I've
posted the complete source for the revised function
here below with comments on my suggestions for
correction.
Function RectangularHull(Poly:TPolygon2D):TRectangle;
Var MaxX,MaxY,MinX,MinY:Double;
I:Integer;
Begin
MaxX := MinimumX;
MaxY := MinimumY;
MinX := MaximumX;
MinY := MaximumY;
For I:= 0 to Length(Poly)-1 Do // was "Length(Poly)"
and overran the end of the polygon
Begin
If Poly[I].x < MinX Then
MinX:=Poly[I].x; // these two tests can't be coupled or
they become input sensitive to the
// order that the high and low X coords arrive and may
not update one or
// the other with a larger or smaller value.
// Else
If Poly[I].x > MaxX Then
MaxX:=Poly[I].x;
If Poly[I].y < MinY Then
MinY:=Poly[I].y; // these two tests can't be coupled or
they become input sensitive to the
// order that the high and low Y coords arrive and may
not update one or
// the other with a larger or smaller value.
// Else
If Poly[I].y > MaxY Then
MaxY:=Poly[I].y;
End;
Result := EquateRectangle(MinX,MinY,MaxX,MaxY);
End;
(* End Of RectangularHull *)