Skip to content

Commit

Permalink
Revert "no need to clone to get the area of a hole #12"
Browse files Browse the repository at this point in the history
This reverts commit ad624c0.
  • Loading branch information
behrisch committed Jan 24, 2024
1 parent 8ffdadd commit 9b6ca8c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/microsim/transportables/MSPModel_JuPedSim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,16 @@ MSPModel_JuPedSim::convertToJPSPoints(const GEOSGeometry* geometry) {
}


double
MSPModel_JuPedSim::getHoleArea(const GEOSGeometry* hole) {
double area;
GEOSGeometry* linearRingAsPolygon = GEOSGeom_createPolygon(GEOSGeom_clone(hole), nullptr, 0);
GEOSArea(linearRingAsPolygon, &area);
GEOSGeom_destroy(linearRingAsPolygon);
return area;
}


void
MSPModel_JuPedSim::preparePolygonForDrawing(const GEOSGeometry* polygon, const std::string& polygonId) {
const GEOSGeometry* exterior = GEOSGetExteriorRing(polygon);
Expand All @@ -682,10 +692,9 @@ MSPModel_JuPedSim::preparePolygonForDrawing(const GEOSGeometry* polygon, const s
std::vector<PositionVector> holes;
int nbrInteriorRings = GEOSGetNumInteriorRings(polygon);
if (nbrInteriorRings != -1) {
double area = -1.;
for (unsigned int k = 0; k < (unsigned int)nbrInteriorRings; k++) {
const GEOSGeometry* linearRing = GEOSGetInteriorRingN(polygon, k);
GEOSArea(linearRing, &area);
double area = getHoleArea(linearRing);
if (area > GEOS_MIN_AREA) {
PositionVector hole = getCoordinates(linearRing);
holes.push_back(hole);
Expand All @@ -709,10 +718,9 @@ MSPModel_JuPedSim::preparePolygonForJPS(const GEOSGeometry* polygon) {
// Handle the interior polygons (holes).
int nbrInteriorRings = GEOSGetNumInteriorRings(polygon);
if (nbrInteriorRings != -1) {
double area = -1.;
for (unsigned int k = 0; k < (unsigned int)nbrInteriorRings; k++) {
const GEOSGeometry* linearRing = GEOSGetInteriorRingN(polygon, k);
GEOSArea(linearRing, &area);
double area = getHoleArea(linearRing);
if (area > GEOS_MIN_AREA) {
std::vector<JPS_Point> holeCoordinates = convertToJPSPoints(linearRing);
JPS_GeometryBuilder_ExcludeFromAccessibleArea(myJPSGeometryBuilder, holeCoordinates.data(), holeCoordinates.size());
Expand Down
1 change: 1 addition & 0 deletions src/microsim/transportables/MSPModel_JuPedSim.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ class MSPModel_JuPedSim : public MSPModel {
static PositionVector getCoordinates(const GEOSGeometry* geometry);
static std::vector<JPS_Point> convertToJPSPoints(const GEOSGeometry* geometry);
static std::vector<JPS_Point> convertToJPSPoints(const PositionVector& coordinates);
static double getHoleArea(const GEOSGeometry* hole);
void preparePolygonForDrawing(const GEOSGeometry* polygon, const std::string& polygonId);
void preparePolygonForJPS(const GEOSGeometry* polygon);
static void dumpGeometry(const GEOSGeometry* polygon, const std::string& filename);
Expand Down

0 comments on commit 9b6ca8c

Please sign in to comment.