yanweiyuan3
2023-08-09 588bc7829387dfc761cc25f06f77d4c81818bd10
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
Quintiq file version 2.0
#parent: #root
Function CalcATCFDistance
{
  TextBody:
  [*
    // boon kiat Dec-4-2013 (created)
    /*
    see http://mathworld.wolfram.com/GreatCircle.html
    */
    value := 0.0;
    
    earthRadius := 6378
    
    selectedunit := guard( this.Unit().GIS_UnitAddress().GIS_UnitGeocodeResult().Selected(), null( LibGIS_GeocodedAddress ) );
    selectedsp := guard( this.StockingPoint_MP().GIS_StockingPointAddress().GIS_StockingPointGeocodeResult().Selected(), null( LibGIS_GeocodedAddress ) );
    
    if( not ( isnull( selectedunit ) or isnull( selectedsp ) ) )
    {
    
      unitlat := pi * selectedunit.Y() / 180.0
      unitlong := pi * selectedunit.X() / 180.0
      splat := pi * selectedsp.Y() / 180.0
      splong := pi * selectedsp.X() / 180.0
    
      theCos := cos( splat ) * cos( unitlat )* cos( splong  - unitlong )  + sin( splat ) * sin ( unitlat )
    
      // round-off errors.
      // M AF Putting the 1.0 as the first parameter causes trouble, submited rfc
      theCos := maxvalue( theCos,  -1.0 )
      theCos := minvalue( theCos,  1.0 )
    
      angle :=  acos( theCos )
    
      value := angle * earthRadius;
    }
    
    this.ATCFDistance( value );
  *]
}