- Timestamp:
- Nov 23, 2017, 7:05:37 PM (7 years ago)
- Location:
- trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Forms/UFormMain.pas
r170 r171 247 247 procedure TFormMain.AZoomAllExecute(Sender: TObject); 248 248 var 249 Factor: T FloatPoint;249 Factor: TPointF; 250 250 MapRect: TRect; 251 251 NewZoom: Single; … … 253 253 with Core, Game, CurrentClient, View do begin 254 254 MapRect := Map.CalculatePixelRect; 255 Factor := FloatPoint(DestRect.Size.X / MapRect.Size.X,255 Factor := TPointF.Create(DestRect.Size.X / MapRect.Size.X, 256 256 DestRect.Size.Y / MapRect.Size.Y); 257 257 if Factor.X < Factor.Y then NewZoom := Factor.X -
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. -
trunk/UGame.pas
r170 r171 30 30 TMapArea = class; 31 31 TClient = class; 32 33 TFloatPoint = record34 X, Y: Double;35 end;36 32 37 33 TTerrainType = (ttVoid, ttNormal, ttCity); … … 525 521 526 522 procedure InitStrings; 527 function FloatPoint(AX, AY: Double): TFloatPoint;528 523 529 524 resourcestring … … 554 549 PlayerModeText[pmHuman] := SHuman; 555 550 PlayerModeText[pmComputer] := SComputer; 556 end;557 558 function FloatPoint(AX, AY: Double): TFloatPoint;559 begin560 Result.X := AX;561 Result.Y := AY;562 551 end; 563 552 … … 1393 1382 var 1394 1383 Points: array of Classes.TPoint; 1395 FPoints: array of T FloatPoint;1384 FPoints: array of TPointF; 1396 1385 I: Integer; 1397 1386 ArrowSize: TPoint; … … 1403 1392 ArrowSize := TPoint.Create(Trunc(DefaultCellSize.X / 3 * View.Zoom), 1404 1393 Trunc(DefaultCellSize.Y / 3 * View.Zoom)); 1405 FPoints[0] := FloatPoint(+0.5 * ArrowSize.X, +0 * ArrowSize.Y);1406 FPoints[1] := FloatPoint(+0 * ArrowSize.X, +0.5 * ArrowSize.Y);1407 FPoints[2] := FloatPoint(+0 * ArrowSize.X, +0.25 * ArrowSize.Y);1408 FPoints[3] := FloatPoint(-0.5 * ArrowSize.X, +0.25 * ArrowSize.Y);1409 FPoints[4] := FloatPoint(-0.5 * ArrowSize.X, -0.25 * ArrowSize.Y);1410 FPoints[5] := FloatPoint(+0 * ArrowSize.X, -0.25 * ArrowSize.Y);1411 FPoints[6] := FloatPoint(+0 * ArrowSize.X, -0.5 * ArrowSize.Y);1412 FPoints[7] := FloatPoint(+0.5 * ArrowSize.X, 0 * ArrowSize.Y);1394 FPoints[0] := TPointF.Create(+0.5 * ArrowSize.X, +0 * ArrowSize.Y); 1395 FPoints[1] := TPointF.Create(+0 * ArrowSize.X, +0.5 * ArrowSize.Y); 1396 FPoints[2] := TPointF.Create(+0 * ArrowSize.X, +0.25 * ArrowSize.Y); 1397 FPoints[3] := TPointF.Create(-0.5 * ArrowSize.X, +0.25 * ArrowSize.Y); 1398 FPoints[4] := TPointF.Create(-0.5 * ArrowSize.X, -0.25 * ArrowSize.Y); 1399 FPoints[5] := TPointF.Create(+0 * ArrowSize.X, -0.25 * ArrowSize.Y); 1400 FPoints[6] := TPointF.Create(+0 * ArrowSize.X, -0.5 * ArrowSize.Y); 1401 FPoints[7] := TPointF.Create(+0.5 * ArrowSize.X, 0 * ArrowSize.Y); 1413 1402 // Rotate 1414 1403 for I := 0 to Length(Points) - 1 do 1415 FPoints[I] := FloatPoint(FPoints[I].X * Cos(Angle) - FPoints[I].Y * Sin(Angle),1404 FPoints[I] := TPointF.Create(FPoints[I].X * Cos(Angle) - FPoints[I].Y * Sin(Angle), 1416 1405 FPoints[I].X * Sin(Angle) + FPoints[I].Y * Cos(Angle)); 1417 1406 // Shift -
trunk/UMap.pas
r170 r171 6 6 7 7 uses 8 Classes, SysUtils, UGame, XMLRead, XMLWrite, DOM, Contnrs,UGeometryClasses,9 UGeometry ;8 Classes, SysUtils, UGame, XMLRead, XMLWrite, DOM, UGeometryClasses, 9 UGeometry, fgl; 10 10 11 11 type … … 64 64 function THexMap.GetHexagonPolygon(Pos: TPoint; Size: TPoint): TPolygon; 65 65 var 66 Shift: T FloatPoint;67 begin 68 Shift := FloatPoint(0.5 * cos(30 / 180 * Pi), 0.5 * sin(30 / 180 * Pi));66 Shift: TPointF; 67 begin 68 Shift := TPointF.Create(0.5 * cos(30 / 180 * Pi), 0.5 * sin(30 / 180 * Pi)); 69 69 SetLength(Result.Points, 6); 70 70 Result.Points[0] := TPoint.Create(Trunc(Pos.X + 0 * Size.X), Trunc(Pos.Y - 0.5 * Size.Y)); … … 246 246 end; 247 247 248 function CompareDistanceReverse( C1, C2: Pointer): Integer;249 begin 250 if TCellsDistance(C1).Distance > TCellsDistance(C2).Distance then Result := -1251 else if TCellsDistance(C1).Distance < TCellsDistance(C2).Distance then Result := 1248 function CompareDistanceReverse(const C1, C2: TCellsDistance): Integer; 249 begin 250 if C1.Distance > C2.Distance then Result := -1 251 else if C1.Distance < C2.Distance then Result := 1 252 252 else Result := 0; 253 253 end; … … 258 258 I1, I2: Integer; 259 259 NewCell: TCell; 260 CellsDistance: T ObjectList; // TObjectList<TCellsDistance>260 CellsDistance: TFPGObjectList<TCellsDistance>; 261 261 NewCellDist: TCellsDistance; 262 SelectedCells: T ObjectList; // TObjectList<TCellsDistance>262 SelectedCells: TFPGObjectList<TCellsDistance>; 263 263 I, J: Integer; 264 264 Intersected: Boolean; … … 312 312 313 313 // Calculate distance between all cells 314 CellsDistance := T ObjectList.Create;314 CellsDistance := TFPGObjectList<TCellsDistance>.Create; 315 315 for I1 := 1 to Cells.Count - 1 do 316 316 for I2 := I1 + 1 to Cells.Count - 1 do begin … … 324 324 325 325 // Keep shortest non-intersected cell pairs 326 SelectedCells := T ObjectList.Create;327 SelectedCells. OwnsObjects := False;326 SelectedCells := TFPGObjectList<TCellsDistance>.Create; 327 SelectedCells.FreeObjects := False; 328 328 I := CellsDistance.Count - 1; 329 329 while I >= 0 do begin
Note:
See TracChangeset
for help on using the changeset viewer.