hedgewars/uFloat.pas
changeset 7714 981001b84f0b
parent 7688 9daa06188551
child 7715 8b653edac2a2
equal deleted inserted replaced
7713:3833741d8752 7714:981001b84f0b
    89 function hwSqrt(const t: hwFloat): hwFloat; inline; // Returns the the positive square root of parameter t.
    89 function hwSqrt(const t: hwFloat): hwFloat; inline; // Returns the the positive square root of parameter t.
    90 function Distance(const dx, dy: hwFloat): hwFloat; // Returns the distance between two points in 2-dimensional space, of which the parameters are the horizontal and vertical distance.
    90 function Distance(const dx, dy: hwFloat): hwFloat; // Returns the distance between two points in 2-dimensional space, of which the parameters are the horizontal and vertical distance.
    91 function DistanceI(const dx, dy: LongInt): hwFloat; // Same as above for integer parameters.
    91 function DistanceI(const dx, dy: LongInt): hwFloat; // Same as above for integer parameters.
    92 function AngleSin(const Angle: Longword): hwFloat;
    92 function AngleSin(const Angle: Longword): hwFloat;
    93 function AngleCos(const Angle: Longword): hwFloat;
    93 function AngleCos(const Angle: Longword): hwFloat;
       
    94 function vector2Angle(const x, y: hwFloat): LongInt;
    94 function SignAs(const num, signum: hwFloat): hwFloat; inline; // Returns an hwFloat with the value of parameter num and the sign of signum.
    95 function SignAs(const num, signum: hwFloat): hwFloat; inline; // Returns an hwFloat with the value of parameter num and the sign of signum.
    95 function hwSign(r: hwFloat): LongInt; inline; // Returns an integer with value 1 and sign of parameter r.
    96 function hwSign(r: hwFloat): LongInt; inline; // Returns an integer with value 1 and sign of parameter r.
    96 function hwSignf(r: real): LongInt; inline; // Returns an integer with value 1 and sign of parameter r.
    97 function hwSignf(r: real): LongInt; inline; // Returns an integer with value 1 and sign of parameter r.
    97 function isZero(const z: hwFloat): boolean; inline;
    98 function isZero(const z: hwFloat): boolean; inline;
    98 {$IFDEF FPC}
    99 {$IFDEF FPC}
   584 if Angle < 1024 then
   585 if Angle < 1024 then
   585     AngleCos.QWordValue:= SinTable[1024 - Angle]
   586     AngleCos.QWordValue:= SinTable[1024 - Angle]
   586 else
   587 else
   587     AngleCos.QWordValue:= SinTable[Angle - 1024]
   588     AngleCos.QWordValue:= SinTable[Angle - 1024]
   588 end;
   589 end;
       
   590 
       
   591 function vector2Angle(const x, y: hwFloat): LongInt;
       
   592 var d: hwFloat;
       
   593     l, r, c, oc: Longword;
       
   594     n: QWord;
       
   595 begin
       
   596     d:= _1 / Distance(x, y);
       
   597 
       
   598     n:= (y * d).QWordValue;
       
   599 
       
   600     l:= 0;
       
   601     r:= 1024;
       
   602     c:= 0;
       
   603 
       
   604     repeat
       
   605         oc:= c;
       
   606 
       
   607         c:= (l + r) shr 1;
       
   608 
       
   609         if n >= SinTable[c] then
       
   610             l:= c
       
   611         else
       
   612             r:= c;
       
   613 
       
   614     until (oc = c);
       
   615 
       
   616     if x.isNegative then c:= 2048 - c;
       
   617     if y.isNegative then c:= - c;
       
   618 
       
   619     vector2Angle:= c
       
   620 end;
       
   621 
   589 {$ENDIF}
   622 {$ENDIF}
   590 
   623 
   591 end.
   624 end.