Skip to content

Commit af7e11b

Browse files
committed
Merge remote-tracking branch 'upstream/master' into sd-integration
2 parents 2645f0c + 6eed828 commit af7e11b

File tree

189 files changed

+6804
-2800
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

189 files changed

+6804
-2800
lines changed

.github/workflows/alpine/Dockerfile.ci

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,6 @@ RUN apk add \
5252
poppler-dev \
5353
proj-dev \
5454
proj-util \
55-
py3-pyarrow \
56-
py3-pyarrow-pyc \
57-
py3-numpy \
58-
py3-numpy-dev \
59-
py3-numpy-tests \
60-
py3-pip \
61-
py3-setuptools \
62-
python3-dev \
6355
qhull-dev \
6456
sfcgal-dev \
6557
snappy-dev \
@@ -69,9 +61,31 @@ RUN apk add \
6961
unixodbc-dev \
7062
xerces-c-dev \
7163
xz-dev \
64+
wget \
7265
zlib-dev \
7366
zstd-dev
7467

68+
# py3-pyarrow \
69+
# py3-pyarrow-pyc \
70+
# py3-numpy \
71+
# py3-numpy-dev \
72+
# py3-numpy-tests \
73+
# py3-pip \
74+
# py3-setuptools \
75+
# python3-dev \
76+
77+
# Build a free-standing/no-gil Python
78+
RUN wget https://www.python.org/ftp/python/3.14.0/Python-3.14.0.tar.xz && \
79+
tar xJvf Python-3.14.0.tar.xz && \
80+
cd Python-3.14.0 && \
81+
./configure --enable-shared --disable-gil --prefix=/usr && \
82+
make -j$(nproc) && \
83+
make -j$(nproc) install && \
84+
cd .. \
85+
rm -rf Python-3.14.0 Python-3.14.0.tar.xz
86+
87+
RUN PYTHON_CMD=python3 && $PYTHON_CMD -m pip install --break-system-packages numpy setuptools pyarrow
88+
7589
COPY requirements.txt /tmp/
7690
RUN PYTHON_CMD=python3 && $PYTHON_CMD -m pip install --break-system-packages -U -r /tmp/requirements.txt
7791

.github/workflows/conda.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727

2828
runs-on: ${{ matrix.platform }}
2929
strategy:
30-
fail-fast: true
30+
fail-fast: false
3131
matrix:
3232
# macos-15-intel: Intel
3333
# macos-14: arm64

alg/llrasterize.cpp

Lines changed: 66 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -85,20 +85,16 @@ void GDALdllImageFilledPolygon(int nRasterXSize, int nRasterYSize,
8585
{
8686
dminy = padfY[i];
8787
}
88-
if (padfY[i] > dmaxy)
88+
else if (padfY[i] > dmaxy)
8989
{
9090
dmaxy = padfY[i];
9191
}
9292
}
93-
int miny = static_cast<int>(dminy);
94-
int maxy = static_cast<int>(dmaxy);
93+
const int miny = static_cast<int>(std::max(0.0, dminy));
94+
const int maxy =
95+
static_cast<int>(std::min<double>(dmaxy, nRasterYSize - 1));
9596

96-
if (miny < 0)
97-
miny = 0;
98-
if (maxy >= nRasterYSize)
99-
maxy = nRasterYSize - 1;
100-
101-
int minx = 0;
97+
constexpr int minx = 0;
10298
const int maxx = nRasterXSize - 1;
10399

104100
// Fix in 1.3: count a vertex only once.
@@ -159,13 +155,16 @@ void GDALdllImageFilledPolygon(int nRasterXSize, int nRasterYSize,
159155
// -Fill them separately-
160156
if (padfX[ind1] > padfX[ind2])
161157
{
162-
const int horizontal_x1 =
163-
static_cast<int>(floor(padfX[ind2] + 0.5));
164-
const int horizontal_x2 =
165-
static_cast<int>(floor(padfX[ind1] + 0.5));
158+
const double dhorizontal_x1 = floor(padfX[ind2] + 0.5);
159+
const double dhorizontal_x2 = floor(padfX[ind1] + 0.5);
166160

167-
if ((horizontal_x1 > maxx) || (horizontal_x2 <= minx))
161+
if ((dhorizontal_x1 > static_cast<double>(maxx)) ||
162+
(dhorizontal_x2 <= 0))
168163
continue;
164+
const int horizontal_x1 =
165+
static_cast<int>(std::max(dhorizontal_x1, 0.0));
166+
const int horizontal_x2 = static_cast<int>(
167+
std::min<double>(dhorizontal_x2, nRasterXSize));
169168

170169
// Fill the horizontal segment (separately from the rest).
171170
if (bAvoidBurningSamePoints)
@@ -187,8 +186,9 @@ void GDALdllImageFilledPolygon(int nRasterXSize, int nRasterYSize,
187186

188187
if (dy < dy2 && dy >= dy1)
189188
{
190-
const double intersect =
191-
(dy - dy1) * (dx2 - dx1) / (dy2 - dy1) + dx1;
189+
const double intersect = std::clamp<double>(
190+
(dy - dy1) * (dx2 - dx1) / (dy2 - dy1) + dx1, INT_MIN,
191+
INT_MAX);
192192

193193
polyInts[ints++] = static_cast<int>(floor(intersect + 0.5));
194194
}
@@ -237,14 +237,15 @@ void GDALdllImagePoint(int nRasterXSize, int nRasterYSize, int nPartCount,
237237
{
238238
for (int i = 0; i < nPartCount; i++)
239239
{
240-
const int nX = static_cast<int>(floor(padfX[i]));
241-
const int nY = static_cast<int>(floor(padfY[i]));
240+
const double dfX = padfX[i];
241+
const double dfY = padfY[i];
242242
double dfVariant = 0.0;
243243
if (padfVariant != nullptr)
244244
dfVariant = padfVariant[i];
245245

246-
if (0 <= nX && nX < nRasterXSize && 0 <= nY && nY < nRasterYSize)
247-
pfnPointFunc(pCBData, nY, nX, dfVariant);
246+
if (0 <= dfX && dfX < nRasterXSize && 0 <= dfY && dfY < nRasterYSize)
247+
pfnPointFunc(pCBData, static_cast<int>(dfY), static_cast<int>(dfX),
248+
dfVariant);
248249
}
249250
}
250251

@@ -264,11 +265,34 @@ void GDALdllImageLine(int nRasterXSize, int nRasterYSize, int nPartCount,
264265
{
265266
for (int j = 1; j < panPartSize[i]; j++)
266267
{
267-
int iX = static_cast<int>(floor(padfX[n + j - 1]));
268-
int iY = static_cast<int>(floor(padfY[n + j - 1]));
268+
double dfX = padfX[n + j - 1];
269+
double dfY = padfY[n + j - 1];
270+
double dfXEnd = padfX[n + j];
271+
double dfYEnd = padfY[n + j];
272+
273+
// Skip segments that are off the target region.
274+
if ((dfY < 0.0 && dfYEnd < 0.0) ||
275+
(dfY > nRasterYSize && dfYEnd > nRasterYSize) ||
276+
(dfX < 0.0 && dfXEnd < 0.0) ||
277+
(dfX > nRasterXSize && dfXEnd > nRasterXSize))
278+
continue;
279+
280+
// TODO: clamp coordinates to [0, nRasterXSize] * [0, nRasterYSize]
281+
if (!(dfX >= INT_MIN && dfX <= INT_MAX && dfY >= INT_MIN &&
282+
dfY <= INT_MAX && dfXEnd >= INT_MIN && dfXEnd <= INT_MAX &&
283+
dfYEnd >= INT_MIN && dfYEnd <= INT_MAX))
284+
{
285+
CPLErrorOnce(
286+
CE_Warning, CPLE_AppDefined,
287+
"GDALdllImageLine(): coordinates outside of int range");
288+
continue;
289+
}
290+
291+
int iX = static_cast<int>(floor(dfX));
292+
int iY = static_cast<int>(floor(dfY));
269293

270-
const int iX1 = static_cast<int>(floor(padfX[n + j]));
271-
const int iY1 = static_cast<int>(floor(padfY[n + j]));
294+
const int iX1 = static_cast<int>(floor(dfXEnd));
295+
const int iY1 = static_cast<int>(floor(dfYEnd));
272296

273297
double dfVariant = 0.0;
274298
double dfVariant1 = 0.0;
@@ -412,6 +436,24 @@ void GDALdllImageLineAllTouched(
412436
double dfXEnd = padfX[n + j];
413437
double dfYEnd = padfY[n + j];
414438

439+
// Skip segments that are off the target region.
440+
if ((dfY < 0.0 && dfYEnd < 0.0) ||
441+
(dfY > nRasterYSize && dfYEnd > nRasterYSize) ||
442+
(dfX < 0.0 && dfXEnd < 0.0) ||
443+
(dfX > nRasterXSize && dfXEnd > nRasterXSize))
444+
continue;
445+
446+
// TODO: clamp coordinates to [0, nRasterXSize] * [0, nRasterYSize]
447+
if (!(dfX >= INT_MIN && dfX <= INT_MAX && dfY >= INT_MIN &&
448+
dfY <= INT_MAX && dfXEnd >= INT_MIN && dfXEnd <= INT_MAX &&
449+
dfYEnd >= INT_MIN && dfYEnd <= INT_MAX))
450+
{
451+
CPLErrorOnce(CE_Warning, CPLE_AppDefined,
452+
"GDALdllImageLineAllTouched(): coordinates "
453+
"outside of int range");
454+
continue;
455+
}
456+
415457
double dfVariant = 0.0;
416458
double dfVariantEnd = 0.0;
417459
if (padfVariant != nullptr &&
@@ -422,13 +464,6 @@ void GDALdllImageLineAllTouched(
422464
dfVariantEnd = padfVariant[n + j];
423465
}
424466

425-
// Skip segments that are off the target region.
426-
if ((dfY < 0.0 && dfYEnd < 0.0) ||
427-
(dfY > nRasterYSize && dfYEnd > nRasterYSize) ||
428-
(dfX < 0.0 && dfXEnd < 0.0) ||
429-
(dfX > nRasterXSize && dfXEnd > nRasterXSize))
430-
continue;
431-
432467
// Swap if needed so we can proceed from left2right (X increasing)
433468
if (dfX > dfXEnd)
434469
{

0 commit comments

Comments
 (0)