GEOS( JTS Topology Suite)BufferOp / Offset Curve 产生额外的点

GEOS (​JTS Topology Suite) BufferOp / Offset Curve producing additional points

我正在使用 GEOS(JTS 拓扑套件的 C 端口)生成线串的偏移曲线。

我已经成功地生成了偏移曲线,但是对于某些情况(即开始和结束线都是水平的并且在相同的 x 位置结束/或垂直的并且在相同的 y 位置结束),一个额外的点是在偏移量的开始和结束处创建。

用图片最容易解释:

Example Image

Example Image 2

如果有什么地方我没有做,或者这是库的错误,我无法解决,这是我的代码:

#include "geos_c.h"

std::vector<vec2> Geos::offsetLine(const std::vector<vec2>& points, float offset, int quadrantSegments, int joinStyle, double mitreLimit) 
{    
    // make coord sequence from points
    GEOSCoordSequence* seq = makeCoordSequence(points);

    // Define line string
    GEOSGeometry* lineString = GEOSGeom_createLineString(seq); 
    if(!lineString) return {};

    // offset line
    GEOSGeometry* bufferOp = GEOSOffsetCurve(lineString, offset, quadrantSegments, joinStyle, mitreLimit);
    if(!bufferOp) return {};

    // put coords into vector
    std::vector<vec2> output = outputCoords(bufferOp, (offset < 0.0f));

    // Frees memory of all as memory ownership is passed along
    GEOSGeom_destroy(bufferOp);

    return move(output);
}

GEOSCoordSequence* Geos::makeCoordSequence(const std::vector<vec2>& points) 
{
    GEOSCoordSequence* seq = GEOSCoordSeq_create(points.size(), 2);
    if(!seq) return {};

    for (size_t i = 0; i < points.size(); i++) { 
        GEOSCoordSeq_setX(seq, i, points[i].x);
        GEOSCoordSeq_setY(seq, i, points[i].y);
    }
    return seq;
}

std::vector<vec2> Geos::outputCoords(const GEOSGeometry* points, bool reversePoints) 
{
    // Convert to coord sequence and draw points
    const GEOSCoordSequence *coordSeq = GEOSGeom_getCoordSeq(points);
    if(!coordSeq) return {};

    // get number of points
    int nPoints = GEOSGeomGetNumPoints(points);
    if(nPoints == -1) return {};

    // output onto vector to return
    std::vector<vec2> output;

    // build vector
    for (size_t i = 0; i < (size_t)nPoints; i++) {
        // points are in reverse order if negative offset
        size_t index = reversePoints ? nPoints-i-1 : i;
        double xCoord, yCoord;
        GEOSCoordSeq_getX(coordSeq, index, &xCoord);
        GEOSCoordSeq_getY(coordSeq, index, &yCoord);
        output.push_back({ xCoord, yCoord });
    }
    return move(output);
}

最新版本的 Geos 现在解决了这个问题。

看这里:Issue