locationtech / locationtech/jts
Negative buffer operation leaves some collinear points (regression from 1.19.0)
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 2.2k
- Forks
- 475
- Avg merge
- 14d 10h
- Merged PRs (30d)
- 1
Description
While testing 1.20.0-SNAPSHOT version built from https://github.com/locationtech/jts/pull/1005 I noticed a minor change in behavior since 1.19.0.
A negative buffer operation no longer removes some collinear points (blue is input geometry, red is result after positive and then negative buffering. Problematic points are marked in red):
Context:
We have a geometry of photovoltaic (PV) module array (a MultiPolygon) and we want to "fill the gaps" between individual PV modules to arrive at a single polygon for the whole PV module array.
For this we use an inflate-deflate approach, where we buffer the geometry using a positive distance, and then buffer the result using an equal but negative distance. In general this seems to work reliably.
Test case that reproduces it (and from which the example image was generated):
@Test
void simplifyByInflateDeflate() throws ParseException {
MultiPolygon polygons = (MultiPolygon) new WKTReader().read(
"MULTIPOLYGON (((0 0, 1 0, 1 1.5, 0 1.5, 0 0)), ((1.01 0, 2.01 0, 2.01 1.5, 1.01 1.5, 1.01 0)), ((2.02 0, 3.0199999999999996 0, 3.0199999999999996 1.5, 2.02 1.5, 2.02 0)), ((0 1.53, 1 1.53, 1 3.0300000000000002, 0 3.0300000000000002, 0 1.53)), ((1.01 1.53, 2.01 1.53, 2.01 3.0300000000000002, 1.01 3.0300000000000002, 1.01 1.53)), ((2.02 1.53, 3.0199999999999996 1.53, 3.0199999999999996 3.0300000000000002, 2.02 3.0300000000000002, 2.02 1.53)), ((0 3.06, 1 3.06, 1 4.5600000000000005, 0 4.5600000000000005, 0 3.06)), ((1.01 3.06, 2.01 3.06, 2.01 4.5600000000000005, 1.01 4.5600000000000005, 1.01 3.06)), ((2.02 3.06, 3.0199999999999996 3.06, 3.0199999999999996 4.5600000000000005, 2.02 4.5600000000000005, 2.02 3.06)))"
);
var bufferParameters = new BufferParameters();
bufferParameters.setJoinStyle(BufferParameters.JOIN_MITRE);
bufferParameters.setMitreLimit(10);
var inflatedResult = BufferOp.bufferOp(polygons, 0.05, bufferParameters);
var deflatedResult = BufferOp.bufferOp(inflatedResult, -0.05, bufferParameters);
// 1.18.2:
// IR: POLYGON ((-0.05 -0.05, -0.05 1.48, -0.05 1.55, -0.05 3.0100000000000002, -0.05 3.08, -0.05 4.61, 0.96 4.61, 1.05 4.61, 1.97 4.61, 2.0599999999999996 4.61, 3.0699999999999994 4.61, 3.0699999999999994 3.08, 3.0699999999999994 3.0100000000000002, 3.0699999999999994 1.55, 3.0699999999999994 1.48, 3.0699999999999994 -0.05, 2.0599999999999996 -0.05, 1.97 -0.05, 1.05 -0.05, 0.96 -0.05, -0.05 -0.05))
// DR: POLYGON ((0 0, 0 4.5600000000000005, 3.0199999999999996 4.5600000000000005, 3.0199999999999996 0, 0 0))
// 1.19.0:
// IR: POLYGON ((-0.05 -0.05, -0.05 1.48, -0.05 1.55, -0.05 3.0100000000000002, -0.05 3.08, -0.05 4.61, 0.96 4.61, 1.05 4.61, 1.97 4.61, 2.0599999999999996 4.61, 3.0699999999999994 4.61, 3.0699999999999994 3.08, 3.0699999999999994 3.0100000000000002, 3.0699999999999994 1.55, 3.0699999999999994 1.48, 3.0699999999999994 -0.05, 2.0599999999999996 -0.05, 1.97 -0.05, 1.05 -0.05, 0.96 -0.05, -0.05 -0.05))
// DR: POLYGON ((0 0, 0 4.5600000000000005, 3.0199999999999996 4.5600000000000005, 3.0199999999999996 0, 0 0))
// 1.20.0-SNAPSHOT (built from "Improve OverlayNG difference check heuristic" PR):
// IR: POLYGON ((-0.05 -0.05, -0.05 1.55, -0.05 1.55, -0.05 3.0100000000000002, -0.05 3.08, -0.05 4.61, 0.96 4.61, 1.05 4.61, 1.97 4.61, 2.0599999999999996 4.61, 3.0699999999999994 4.61, 3.0699999999999994 3.08, 3.0699999999999994 3.0100000000000002, 3.0699999999999994 1.55, 3.0699999999999994 1.48, 3.0699999999999994 -0.05, 2.0599999999999996 -0.05, 1.97 -0.05, 1.05 -0.05, 0.96 -0.05, -0.05 -0.05))
// DR: POLYGON ((0 0, 0 1.5, 0 1.55, 0 4.5600000000000005, 3.0199999999999996 4.5600000000000005, 3.0199999999999996 0, 0 0))
}
It seems that inflatedResult (IR) is the same in all 3 tested versions.
deflatedResult (DR) is less optimal in 1.20.0-SNAPSHOT (has some extra collinear points).
This is not a big problem for us, but wanted to report anyway in case this regression is important for some other use cases.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the supplied simplifyByInflateDeflate test and run the BufferOp.bufferOp calls using BufferParameters, comparing the 1.19.0 and 1.20.0-SNAPSHOT results. Trace the negative-buffer path related to the referenced OverlayNG difference-check heuristic; done means the deflated result no longer retains the extra collinear points while preserving the expected geometry.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 50/100