Ignore:
Timestamp:
Nov 23, 2017, 7:05:37 PM (7 years ago)
Author:
chronos
Message:
  • Modified: Use specialized TPointF type from generic class.
  • Modified: Part of fixes for Voronoi map generation.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Packages/Common/UGeometryClasses.pas

    r170 r171  
    2626function PointsToRect(const P1, P2: TPoint): TRect;
    2727function PointInRect(const P: TPoint; aRect: TRect): Boolean;
     28function PtInPoly(const Points: array of TPoint; Pos: TPoint): Boolean;
    2829function HalfDistancePoint(const P1, P2: TPoint): TPoint;
    2930function NormalizeAngle(const Angle: Double): Double;
     
    172173end;
    173174
     175function PtInPoly(const Points: array of TPoint; Pos: TPoint): Boolean;
     176var
     177  Count, K, J : Integer;
     178begin
     179  Result := False;
     180  Count := Length(Points) ;
     181  J := Count - 1;
     182  for K := 0 to Count - 1 do begin
     183  if ((Points[K].Y <= Pos.Y) and (Pos.Y < Points[J].Y)) or
     184    ((Points[J].Y <= Pos.Y) and (Pos.Y < Points[K].Y)) then
     185    begin
     186    if (Pos.X < (Points[j].X - Points[K].X) *
     187       (Pos.Y - Points[K].Y) /
     188       (Points[j].Y - Points[K].Y) + Points[K].X) then
     189        Result := not Result;
     190    end;
     191    J := K;
     192  end;
     193end;
    174194
    175195end.
Note: See TracChangeset for help on using the changeset viewer.