Changeset 171 for trunk/Packages/Common
- Timestamp:
- Nov 23, 2017, 7:05:37 PM (7 years ago)
- Location:
- trunk/Packages/Common
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Packages/Common/UGeometry.pas
r170 r171 6 6 7 7 uses 8 Classes, SysUtils, Math ;8 Classes, SysUtils, Math, typinfo; 9 9 10 10 type … … 16 16 Y: T; 17 17 constructor Create(const X, Y: T); 18 procedure Rotate(Base: TGPoint<T>; Angle: Double);19 18 class operator Add(const A, B: TGPoint<T>): TGPoint<T>; 20 19 class operator Subtract(const A, B: TGPoint<T>): TGPoint<T>; 21 20 class operator GreaterThan(const A, B: TGPoint<T>): Boolean; 21 class operator GreaterThanOrEqual(const A, B: TGPoint<T>): Boolean; 22 22 class operator LessThan(const A, B: TGPoint<T>): Boolean; 23 class operator LessThanOrEqual(const A, B: TGPoint<T>): Boolean; 23 24 class operator Equal(const A, B: TGPoint<T>): Boolean; 24 25 function Min(const A, B: TGPoint<T>): TGPoint<T>; 25 26 function Max(const A, B: TGPoint<T>): TGPoint<T>; 27 procedure Rotate(Base: TGPoint<T>; Angle: Double); 26 28 end; 27 29 … … 94 96 procedure AddPoint(const P: T); 95 97 procedure Clear; 96 procedure CutLine( constVector: TGLine<T>; const PointInside: T);98 procedure CutLine(Vector: TGLine<T>; const PointInside: T); 97 99 property Items[Index: Integer]: T read GetPoint write SetPoint; default; 98 100 end; … … 185 187 end; 186 188 187 function PtInPoly(const Points: array of TPoint; Pos: TPoint): Boolean;188 var189 Count, K, J : Integer;190 begin191 Result := False;192 Count := Length(Points) ;193 J := Count - 1;194 for K := 0 to Count - 1 do begin195 if ((Points[K].Y <= Pos.Y) and (Pos.Y < Points[J].Y)) or196 ((Points[J].Y <= Pos.Y) and (Pos.Y < Points[K].Y)) then197 begin198 if (Pos.X < (Points[j].X - Points[K].X) *199 (Pos.Y - Points[K].Y) /200 (Points[j].Y - Points[K].Y) + Points[K].X) then201 Result := not Result;202 end;203 J := K;204 end;205 end;206 207 208 189 constructor TGPolygon<T>.Create(const Points: TPointArray); 209 190 var … … 227 208 var 228 209 I: Integer; 229 P1: TGPoint<T>;230 210 begin 231 211 if Length(Points) = 0 then … … 252 232 end; 253 233 254 procedure TGPolygon<T>.CutLine( constVector: TGLine<T>; const PointInside: T);234 procedure TGPolygon<T>.CutLine(Vector: TGLine<T>; const PointInside: T); 255 235 var 256 236 I: Integer; … … 359 339 end; 360 340 361 { TGPoint3D }362 363 constructor TGPoint3D<T>.Create(const X, Y, Z: T);364 begin365 Self.X := X;366 Self.Y := Y;367 Self.Z := Z;368 end;369 370 { TGPoint }371 372 constructor TGPoint<T>.Create(const X, Y: T);373 begin374 Self.X := X;375 Self.Y := Y;376 end;377 378 class operator TGPoint<T>.Equal(const A, B: TGPoint<T>): Boolean;379 begin380 Result := (A.X = B.X) and (A.Y = B.Y);381 end;382 383 class operator TGPoint<T>.Add(const A, B: TGPoint<T>): TGPoint<T>;384 begin385 Result.X := A.X + B.X;386 Result.Y := A.Y + B.Y;387 end;388 389 class operator TGPoint<T>.Subtract(const A, B: TGPoint<T>): TGPoint<T>;390 begin391 Result.X := A.X - B.X;392 Result.Y := A.Y - B.Y;393 end;394 395 class operator TGPoint<T>.GreaterThan(const A, B: TGPoint<T>): Boolean;396 begin397 Result := (B.X > A.X) and (B.Y > A.Y);398 end;399 400 class operator TGPoint<T>.LessThan(const A, B: TGPoint<T>): Boolean;401 begin402 Result := (B.X < A.X) and (B.Y < A.Y);403 end;404 405 { TGLine }406 407 341 class function TGLine<T>.LineIntersect(const LineA, LineB: TGLine<T>; out 408 342 Intersection: T): Boolean; … … 435 369 end; 436 370 437 procedure TGPoint<T>.Rotate(Base: TGPoint<T>; Angle: Double); 438 var 439 D: TGPoint<T>; 440 begin 441 D := TGPoint<T>.Create(X - Base.X, Y - Base.Y); 442 //X := Base.X + TypedRound(D.X * Cos(Angle) - D.Y * Sin(Angle)); 443 //Y := Base.Y + TypedRound(D.X * Sin(Angle) + D.Y * Cos(Angle)); 371 { TGPoint3D } 372 373 constructor TGPoint3D<T>.Create(const X, Y, Z: T); 374 begin 375 Self.X := X; 376 Self.Y := Y; 377 Self.Z := Z; 378 end; 379 380 { TGPoint } 381 382 constructor TGPoint<T>.Create(const X, Y: T); 383 begin 384 Self.X := X; 385 Self.Y := Y; 386 end; 387 388 class operator TGPoint<T>.Equal(const A, B: TGPoint<T>): Boolean; 389 begin 390 Result := (A.X = B.X) and (A.Y = B.Y); 391 end; 392 393 class operator TGPoint<T>.Add(const A, B: TGPoint<T>): TGPoint<T>; 394 begin 395 Result.X := A.X + B.X; 396 Result.Y := A.Y + B.Y; 397 end; 398 399 class operator TGPoint<T>.Subtract(const A, B: TGPoint<T>): TGPoint<T>; 400 begin 401 Result.X := A.X - B.X; 402 Result.Y := A.Y - B.Y; 403 end; 404 405 class operator TGPoint<T>.GreaterThan(const A, B: TGPoint<T>): Boolean; 406 begin 407 Result := (A.X > B.X) and (A.Y > B.Y); 408 end; 409 410 class operator TGPoint<T>.GreaterThanOrEqual(const A, B: TGPoint<T>): Boolean; 411 begin 412 Result := (A.X >= B.X) and (A.Y >= B.Y); 413 end; 414 415 class operator TGPoint<T>.LessThan(const A, B: TGPoint<T>): Boolean; 416 begin 417 Result := (A.X < B.X) and (A.Y < B.Y); 418 end; 419 420 class operator TGPoint<T>.LessThanOrEqual(const A, B: TGPoint<T>): Boolean; 421 begin 422 Result := (A.X <= B.X) and (A.Y <= B.Y); 444 423 end; 445 424 … … 456 435 end; 457 436 437 procedure TGPoint<T>.Rotate(Base: TGPoint<T>; Angle: Double); 438 var 439 D: TGPoint<T>; 440 begin 441 D := TGPoint<T>.Create(X - Base.X, Y - Base.Y); 442 X := Base.X + TypedRound(D.X * Cos(Angle) - D.Y * Sin(Angle)); 443 Y := Base.Y + TypedRound(D.X * Sin(Angle) + D.Y * Cos(Angle)); 444 end; 445 458 446 { TGRect } 459 447 460 448 function TGRect<T>.IsPointInside(const P: T): Boolean; 461 449 begin 462 Result := (P > P1) and (P <P2);450 Result := (P >= P1) and (P <= P2); 463 451 end; 464 452 -
trunk/Packages/Common/UGeometryClasses.pas
r170 r171 26 26 function PointsToRect(const P1, P2: TPoint): TRect; 27 27 function PointInRect(const P: TPoint; aRect: TRect): Boolean; 28 function PtInPoly(const Points: array of TPoint; Pos: TPoint): Boolean; 28 29 function HalfDistancePoint(const P1, P2: TPoint): TPoint; 29 30 function NormalizeAngle(const Angle: Double): Double; … … 172 173 end; 173 174 175 function PtInPoly(const Points: array of TPoint; Pos: TPoint): Boolean; 176 var 177 Count, K, J : Integer; 178 begin 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; 193 end; 174 194 175 195 end.
Note:
See TracChangeset
for help on using the changeset viewer.