LCOV - code coverage report
Current view: top level - frmts/raw - atlsci_spheroid.cpp (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 45 61 73.8 %
Date: 2024-05-04 12:52:34 Functions: 10 12 83.3 %

          Line data    Source code
       1             : /******************************************************************************
       2             :  *
       3             :  * Project:  Spheroid classes
       4             :  * Purpose:  Provide spheroid lookup table base classes.
       5             :  * Author:   Gillian Walter
       6             :  *
       7             :  ******************************************************************************
       8             :  * Copyright (c) 1999, Frank Warmerdam
       9             :  *
      10             :  * Permission is hereby granted, free of charge, to any person obtaining a
      11             :  * copy of this software and associated documentation files (the "Software"),
      12             :  * to deal in the Software without restriction, including without limitation
      13             :  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
      14             :  * and/or sell copies of the Software, and to permit persons to whom the
      15             :  * Software is furnished to do so, subject to the following conditions:
      16             :  *
      17             :  * The above copyright notice and this permission notice shall be included
      18             :  * in all copies or substantial portions of the Software.
      19             :  *
      20             :  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
      21             :  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
      22             :  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
      23             :  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
      24             :  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
      25             :  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
      26             :  * DEALINGS IN THE SOFTWARE.
      27             :  ****************************************************************************/
      28             : 
      29             : #include "atlsci_spheroid.h"
      30             : #include "cpl_string.h"
      31             : 
      32             : /**********************************************************************/
      33             : /* ================================================================== */
      34             : /*          Spheroid definitions                                      */
      35             : /* ================================================================== */
      36             : /**********************************************************************/
      37             : 
      38       15104 : SpheroidItem::SpheroidItem()
      39             :     : spheroid_name(nullptr), equitorial_radius(-1.0), polar_radius(-1.0),
      40       15104 :       inverse_flattening(-1.0)
      41             : {
      42       15104 : }
      43             : 
      44       30208 : SpheroidItem::~SpheroidItem()
      45             : {
      46       15104 :     CPLFree(spheroid_name);
      47       15104 : }
      48             : 
      49         270 : void SpheroidItem::SetValuesByRadii(const char *spheroidname, double eq_radius,
      50             :                                     double p_radius)
      51             : {
      52         270 :     spheroid_name = CPLStrdup(spheroidname);
      53         270 :     equitorial_radius = eq_radius;
      54         270 :     polar_radius = p_radius;
      55         270 :     inverse_flattening =
      56         270 :         eq_radius == polar_radius ? 0 : eq_radius / (eq_radius - polar_radius);
      57         270 : }
      58             : 
      59        2552 : void SpheroidItem::SetValuesByEqRadiusAndInvFlattening(const char *spheroidname,
      60             :                                                        double eq_radius,
      61             :                                                        double inverseflattening)
      62             : {
      63        2552 :     spheroid_name = CPLStrdup(spheroidname);
      64        2552 :     equitorial_radius = eq_radius;
      65        2552 :     inverse_flattening = inverseflattening;
      66        5104 :     polar_radius = inverse_flattening == 0
      67        2552 :                        ? eq_radius
      68        2552 :                        : eq_radius * (1.0 - (1.0 / inverse_flattening));
      69        2552 : }
      70             : 
      71       15163 : SpheroidList::SpheroidList() : num_spheroids(0), epsilonR(0.0), epsilonI(0.0)
      72             : {
      73          59 : }
      74             : 
      75       15163 : SpheroidList::~SpheroidList()
      76             : {
      77          59 : }
      78             : 
      79           0 : char *SpheroidList::GetSpheroidNameByRadii(double eq_radius,
      80             :                                            double polar_radius)
      81             : {
      82           0 :     for (int index = 0; index < num_spheroids; index++)
      83             :     {
      84           0 :         const double er = spheroids[index].equitorial_radius;
      85           0 :         const double pr = spheroids[index].polar_radius;
      86           0 :         if ((fabs(er - eq_radius) < epsilonR) &&
      87           0 :             (fabs(pr - polar_radius) < epsilonR))
      88           0 :             return CPLStrdup(spheroids[index].spheroid_name);
      89             :     }
      90             : 
      91           0 :     return nullptr;
      92             : }
      93             : 
      94          35 : char *SpheroidList::GetSpheroidNameByEqRadiusAndInvFlattening(
      95             :     double eq_radius, double inverse_flattening)
      96             : {
      97         878 :     for (int index = 0; index < num_spheroids; index++)
      98             :     {
      99         869 :         const double er = spheroids[index].equitorial_radius;
     100         869 :         const double invf = spheroids[index].inverse_flattening;
     101         869 :         if ((fabs(er - eq_radius) < epsilonR) &&
     102          60 :             (fabs(invf - inverse_flattening) < epsilonI))
     103          26 :             return CPLStrdup(spheroids[index].spheroid_name);
     104             :     }
     105             : 
     106           9 :     return nullptr;
     107             : }
     108             : 
     109          10 : double SpheroidList::GetSpheroidEqRadius(const char *spheroid_name)
     110             : {
     111          66 :     for (int index = 0; index < num_spheroids; index++)
     112             :     {
     113          66 :         if (EQUAL(spheroids[index].spheroid_name, spheroid_name))
     114          10 :             return spheroids[index].equitorial_radius;
     115             :     }
     116             : 
     117           0 :     return -1.0;
     118             : }
     119             : 
     120          23 : int SpheroidList::SpheroidInList(const char *spheroid_name)
     121             : {
     122             :     /* Return 1 if the spheroid name is recognized; 0 otherwise */
     123         474 :     for (int index = 0; index < num_spheroids; index++)
     124             :     {
     125         474 :         if (EQUAL(spheroids[index].spheroid_name, spheroid_name))
     126          23 :             return 1;
     127             :     }
     128             : 
     129           0 :     return 0;
     130             : }
     131             : 
     132          10 : double SpheroidList::GetSpheroidInverseFlattening(const char *spheroid_name)
     133             : {
     134          66 :     for (int index = 0; index < num_spheroids; index++)
     135             :     {
     136          66 :         if (EQUAL(spheroids[index].spheroid_name, spheroid_name))
     137          10 :             return spheroids[index].inverse_flattening;
     138             :     }
     139             : 
     140           0 :     return -1.0;
     141             : }
     142             : 
     143           0 : double SpheroidList::GetSpheroidPolarRadius(const char *spheroid_name)
     144             : {
     145           0 :     for (int index = 0; index < num_spheroids; index++)
     146             :     {
     147           0 :         if (strcmp(spheroids[index].spheroid_name, spheroid_name) == 0)
     148           0 :             return spheroids[index].polar_radius;
     149             :     }
     150             : 
     151           0 :     return -1.0;
     152             : }

Generated by: LCOV version 1.14