Changeset 165 for trunk/Packages
- Timestamp:
- Nov 22, 2017, 4:48:33 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Packages/Common/UGeometry.pas
r164 r165 14 14 15 15 TLine = record 16 private 17 function GetDistance: Double; 18 procedure SetDistance(AValue: Double); 19 public 16 20 P1: TPoint; 17 21 P2: TPoint; 18 22 function Create(P1, P2: TPoint): TLine; 19 function Distance: Double;20 23 function GetMiddle: TPoint; 21 24 function GetAngle: Double; … … 25 28 procedure Rotate(Angle: Double); 26 29 class operator Equal(A, B: TLine): Boolean; 30 property Distance: Double read GetDistance write SetDistance; 27 31 end; 28 32 … … 56 60 function PointInRect(P: TPoint; aRect: TRect): Boolean; 57 61 function HalfDistancePoint(P1, P2: TPoint): TPoint; 62 function NormalizeAngle(Angle: Double): Double; 63 function SubAngle(A1, A2: Double): Double; 58 64 59 65 implementation … … 208 214 begin 209 215 Result := Point(P1.X + (P2.X - P1.X) div 2, P1.Y + (P2.Y - P1.Y) div 2) 216 end; 217 218 function NormalizeAngle(Angle: Double): Double; 219 begin 220 if Angle < 0 then Result := Angle + (Trunc(Angle / (2 * Pi)) + 1) * (2 * Pi) 221 else if Angle > 2 * Pi then Result := Angle - Trunc(Angle / (2 * Pi)) * (2 * Pi) 222 else Result := Angle; 223 end; 224 225 function SubAngle(A1, A2: Double): Double; 226 begin 227 A1 := NormalizeAngle(A1); 228 A2 := NormalizeAngle(A2); 229 if A1 < A2 then Result := A1 + 2 * Pi - A2 230 else Result := A1 - A2; 210 231 end; 211 232 … … 310 331 end else begin 311 332 // Crossing line, end polygon. If point NewPolygonStarted, the use polygon as result 333 NewPoly.AddPoint(Points[I]); 312 334 NewPoly.AddPoint(Intersection); 313 335 if NewPoly.IsPointInside(PointInside) then begin … … 326 348 if PointsChecked > 2 * Length(Points) then Break; 327 349 end; 328 if Success then Points := NewPoly.Points 329 else Clear; 350 if Success then Points := NewPoly.Points; 330 351 end; 331 352 332 353 { TLine } 354 355 function TLine.GetDistance: Double; 356 begin 357 Result := Sqrt(Sqr(P2.X - P1.X) + Sqr(P2.Y - P1.Y)); 358 end; 359 360 procedure TLine.SetDistance(AValue: Double); 361 var 362 Angle: Double; 363 begin 364 Angle := GetAngle; 365 P2 := Point(Round(P1.X + Cos(Angle) * AValue), 366 Round(P1.Y + Sin(Angle) * AValue)); 367 end; 333 368 334 369 function TLine.Create(P1, P2: TPoint): TLine; … … 336 371 Result.P1 := P1; 337 372 Result.P2 := P2; 338 end;339 340 function TLine.Distance: Double;341 begin342 Result := Sqrt(Sqr(P2.X - P1.X) + Sqr(P2.Y - P1.Y));343 373 end; 344 374
Note:
See TracChangeset
for help on using the changeset viewer.