Coverage Report

Created: 2025-08-30 06:52

/src/geos/src/operation/grid/Grid.cpp
Line
Count
Source (jump to first uncovered line)
1
/**********************************************************************
2
 *
3
 * GEOS - Geometry Engine Open Source
4
 * http://geos.osgeo.org
5
 *
6
 * Copyright (C) 2018-2025 ISciences, LLC
7
 *
8
 * This is free software; you can redistribute and/or modify it under
9
 * the terms of the GNU Lesser General Public Licence as published
10
 * by the Free Software Foundation.
11
 * See the COPYING file for more information.
12
 *
13
 **********************************************************************/
14
15
#include <geos/operation/grid/Grid.h>
16
17
using geos::geom::Envelope;
18
19
namespace geos::operation::grid {
20
21
template<>
22
Envelope
23
Grid<bounded_extent>::getCellEnvelope(size_t row, size_t col) const
24
0
{
25
    // The ternary clauses below are used to make sure that the cells along
26
    // the right and bottom edges of our grid are slightly larger than m_dx,dy
27
    // if needed to make sure that we capture our whole extent. This is necessary
28
    // because xmin + nx*m_dx may be less than xmax because of floating point
29
    // errors.
30
0
    return {
31
0
        xmin() + static_cast<double>(col) * dx(),
32
0
        row == (getNumRows() - 1) ? ymin() : (ymax() - static_cast<double>(row + 1) * dy()),
33
0
        col == (getNumCols() - 1) ? xmax() : (xmin() + static_cast<double>(col + 1) * dx()),
34
0
        ymax() - static_cast<double>(row) * dy()
35
0
    };
36
0
}
37
38
template<>
39
Envelope
40
Grid<infinite_extent>::getCellEnvelope(size_t row, size_t col) const
41
0
{
42
0
    double cell_xmin, cell_xmax, cell_ymin, cell_ymax;
43
44
0
    constexpr double PADDED_CELL_SIZE = 1.0;
45
46
0
    if (col == 0) {
47
0
        cell_xmin = std::min(xmin() - PADDED_CELL_SIZE, m_domain.getMinX());
48
0
    } else if (col == getNumCols() - 1) {
49
0
        cell_xmin = xmax(); // because rightmost col of regular may have different width from others
50
0
    } else {
51
0
        cell_xmin = xmin() + static_cast<double>(col - 1) * dx();
52
0
    }
53
54
0
    switch (getNumCols() - col) {
55
0
        case 1:
56
0
            cell_xmax = std::max(xmax() + PADDED_CELL_SIZE, m_domain.getMaxX());
57
0
            break;
58
0
        case 2:
59
0
            cell_xmax = xmax();
60
0
            break;
61
0
        default:
62
0
            cell_xmax = xmin() + static_cast<double>(col) * dx();
63
0
    }
64
65
0
    if (row == 0) {
66
0
        cell_ymax = std::max(xmax() + PADDED_CELL_SIZE, m_domain.getMaxX());
67
0
    } else if (row == getNumRows() - 1) {
68
0
        cell_ymax = ymin(); // because bottom row of regular may have different height from others
69
0
    } else {
70
0
        cell_ymax = ymax() - static_cast<double>(row - 1) * dy();
71
0
    }
72
73
0
    switch (getNumRows() - row) {
74
0
        case 1:
75
0
            cell_ymin = std::min(xmin() - PADDED_CELL_SIZE, m_domain.getMinY());
76
0
            break;
77
0
        case 2:
78
0
            cell_ymin = ymin();
79
0
            break;
80
0
        default:
81
0
            cell_ymin = ymax() - static_cast<double>(row) * dy();
82
0
    }
83
84
0
    return { cell_xmin, cell_xmax, cell_ymin, cell_ymax };
85
0
}
86
87
Grid<infinite_extent>
88
make_infinite(const Grid<bounded_extent>& grid, const Envelope& domain)
89
0
{
90
0
    return { grid.getExtent(), grid.dx(), grid.dy() , domain };
91
0
}
92
93
Grid<bounded_extent>
94
make_finite(const Grid<infinite_extent>& grid)
95
0
{
96
0
    return { grid.getExtent(), grid.dx(), grid.dy() };
97
0
}
98
99
}