Coverage Report

Created: 2026-05-30 06:46

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/PROJ/src/projections/ccon.cpp
Line
Count
Source
1
/******************************************************************************
2
 * Copyright (c) 2017, Lukasz Komsta
3
 *
4
 * Permission is hereby granted, free of charge, to any person obtaining a
5
 * copy of this software and associated documentation files (the "Software"),
6
 * to deal in the Software without restriction, including without limitation
7
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8
 * and/or sell copies of the Software, and to permit persons to whom the
9
 * Software is furnished to do so, subject to the following conditions:
10
 *
11
 * The above copyright notice and this permission notice shall be included
12
 * in all copies or substantial portions of the Software.
13
 *
14
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20
 * DEALINGS IN THE SOFTWARE.
21
 *****************************************************************************/
22
23
#include "proj.h"
24
#include "proj_internal.h"
25
#include <errno.h>
26
#include <math.h>
27
28
14
#define EPS10 1e-10
29
30
namespace { // anonymous namespace
31
struct pj_ccon_data {
32
    double phi1;
33
    double ctgphi1;
34
    double sinphi1;
35
    double cosphi1;
36
    double *en;
37
};
38
} // anonymous namespace
39
40
PROJ_HEAD(ccon, "Central Conic")
41
"\n\tCentral Conic, Sph\n\tlat_1=";
42
43
0
static PJ_XY ccon_forward(PJ_LP lp, PJ *P) {
44
0
    PJ_XY xy = {0.0, 0.0};
45
0
    struct pj_ccon_data *Q = static_cast<struct pj_ccon_data *>(P->opaque);
46
0
    double r;
47
48
0
    r = Q->ctgphi1 - tan(lp.phi - Q->phi1);
49
0
    xy.x = r * sin(lp.lam * Q->sinphi1);
50
0
    xy.y = Q->ctgphi1 - r * cos(lp.lam * Q->sinphi1);
51
52
0
    return xy;
53
0
}
54
55
0
static PJ_LP ccon_inverse(PJ_XY xy, PJ *P) {
56
0
    PJ_LP lp = {0.0, 0.0};
57
0
    struct pj_ccon_data *Q = static_cast<struct pj_ccon_data *>(P->opaque);
58
59
0
    xy.y = Q->ctgphi1 - xy.y;
60
0
    lp.phi = Q->phi1 - atan(hypot(xy.x, xy.y) - Q->ctgphi1);
61
0
    lp.lam = atan2(xy.x, xy.y) / Q->sinphi1;
62
63
0
    return lp;
64
0
}
65
66
14
static PJ *pj_ccon_destructor(PJ *P, int errlev) {
67
14
    if (nullptr == P)
68
0
        return nullptr;
69
70
14
    if (nullptr == P->opaque)
71
0
        return pj_default_destructor(P, errlev);
72
73
14
    free(static_cast<struct pj_ccon_data *>(P->opaque)->en);
74
14
    return pj_default_destructor(P, errlev);
75
14
}
76
77
14
PJ *PJ_PROJECTION(ccon) {
78
79
14
    struct pj_ccon_data *Q = static_cast<struct pj_ccon_data *>(
80
14
        calloc(1, sizeof(struct pj_ccon_data)));
81
14
    if (nullptr == Q)
82
0
        return pj_default_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/);
83
14
    P->opaque = Q;
84
14
    P->destructor = pj_ccon_destructor;
85
86
14
    Q->phi1 = pj_param(P->ctx, P->params, "rlat_1").f;
87
14
    if (fabs(Q->phi1) < EPS10) {
88
3
        proj_log_error(P, _("Invalid value for lat_1: |lat_1| should be > 0"));
89
3
        return pj_ccon_destructor(P, PROJ_ERR_INVALID_OP_ILLEGAL_ARG_VALUE);
90
3
    }
91
11
    if (!(Q->en = pj_enfn(P->n)))
92
0
        return pj_ccon_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/);
93
94
11
    Q->sinphi1 = sin(Q->phi1);
95
11
    Q->cosphi1 = cos(Q->phi1);
96
11
    Q->ctgphi1 = Q->cosphi1 / Q->sinphi1;
97
98
11
    P->inv = ccon_inverse;
99
11
    P->fwd = ccon_forward;
100
101
11
    return P;
102
11
}
103
104
#undef EPS10