<commit_before>/**********************************************************************
 *
 * GEOS - Geometry Engine Open Source
 * http://geos.osgeo.org
 *
 * Copyright (C) 2001-2002 Vivid Solutions Inc.
 *
 * This is free software; you can redistribute and/or modify it under
 * the terms of the GNU Lesser General Public Licence as published
 * by the Free Software Foundation.
 * See the COPYING file for more information.
 *
 **********************************************************************
 *
 * Last port: geom/prep/PreparedPolygonPredicate.java rev. 1.4 (JTS-1.10)
 * (2007-12-12)
 *
 **********************************************************************/

#include <geos/geom/prep/PreparedPolygonPredicate.h>
#include <geos/geom/prep/PreparedPolygon.h>
#include <geos/geom/Coordinate.h>
#include <geos/geom/CoordinateFilter.h>
#include <geos/geom/util/ComponentCoordinateExtracter.h>
#include <geos/geom/Location.h>
#include <geos/algorithm/locate/PointOnGeometryLocator.h>
#include <geos/algorithm/locate/SimplePointInAreaLocator.h>
// std
#include <algorithm> // std::max
#include <cstddef>

namespace geos {
namespace geom { // geos.geom
namespace prep { // geos.geom.prep
//
// private:
//

//
// protected:
//
struct AnyMatchingLocationFilter : public GeometryComponentFilter {
    explicit AnyMatchingLocationFilter(algorithm::locate::PointOnGeometryLocator* locator, int loc) :
        pt_locator(locator), test_loc(loc), found(false) {}

    algorithm::locate::PointOnGeometryLocator* pt_locator;
    const int test_loc;
    bool found;

    void filter_ro(const Geometry* g) override {
        const Coordinate* pt = g->getCoordinate();
        const int loc = pt_locator->locate(pt);

        if (loc == test_loc) {
            found = true;
        }
    }

    bool isDone() override {
        return found;
    }
};

struct AnyNotMatchingLocationFilter : public GeometryComponentFilter {
    explicit AnyNotMatchingLocationFilter(algorithm::locate::PointOnGeometryLocator* locator, int loc) :
            pt_locator(locator), test_loc(loc), found(false) {}

    algorithm::locate::PointOnGeometryLocator* pt_locator;
    const int test_loc;
    bool found;

    void filter_ro(const Geometry* g) override {
        const Coordinate* pt = g->getCoordinate();
        const int loc = pt_locator->locate(pt);

        if (loc != test_loc) {
            found = true;
        }
    }

    bool isDone() override {
        return found;
    }
};

struct OutermostLocationFilter : public GeometryComponentFilter {
    explicit OutermostLocationFilter(algorithm::locate::PointOnGeometryLocator* locator) :
    pt_locator(locator),
    max_loc(geom::Location::UNDEF),
    found(false) {}

    algorithm::locate::PointOnGeometryLocator* pt_locator;
    Location::Value max_loc;
    bool found;

    void filter_ro(const Geometry* g) override {
        const Coordinate* pt = g->getCoordinate();
        auto loc = static_cast<Location::Value>(pt_locator->locate(pt));

        max_loc = std::max(max_loc, loc);
        if (max_loc == geom::Location::EXTERIOR) {
            found = true;
        }
    }

    bool isDone() override {
        return found;
    }

    Location::Value getOutermostLocation() {
        return max_loc;
    }
};

Location::Value
PreparedPolygonPredicate::getOutermostTestComponentLocation(const geom::Geometry* testGeom) const
{
    OutermostLocationFilter filter(prepPoly->getPointLocator());
    testGeom->apply_ro(&filter);

    return filter.getOutermostLocation();<commit_msg>Avoid relying on numeric ordering of Location<commit_after>/**********************************************************************
 *
 * GEOS - Geometry Engine Open Source
 * http://geos.osgeo.org
 *
 * Copyright (C) 2001-2002 Vivid Solutions Inc.
 *
 * This is free software; you can redistribute and/or modify it under
 * the terms of the GNU Lesser General Public Licence as published
 * by the Free Software Foundation.
 * See the COPYING file for more information.
 *
 **********************************************************************
 *
 * Last port: geom/prep/PreparedPolygonPredicate.java rev. 1.4 (JTS-1.10)
 * (2007-12-12)
 *
 **********************************************************************/

#include <geos/geom/prep/PreparedPolygonPredicate.h>
#include <geos/geom/prep/PreparedPolygon.h>
#include <geos/geom/Coordinate.h>
#include <geos/geom/CoordinateFilter.h>
#include <geos/geom/util/ComponentCoordinateExtracter.h>
#include <geos/geom/Location.h>
#include <geos/algorithm/locate/PointOnGeometryLocator.h>
#include <geos/algorithm/locate/SimplePointInAreaLocator.h>
// std
#include <cstddef>

namespace geos {
namespace geom { // geos.geom
namespace prep { // geos.geom.prep
//
// private:
//

//
// protected:
//
struct AnyMatchingLocationFilter : public GeometryComponentFilter {
    explicit AnyMatchingLocationFilter(algorithm::locate::PointOnGeometryLocator* locator, int loc) :
        pt_locator(locator), test_loc(loc), found(false) {}

    algorithm::locate::PointOnGeometryLocator* pt_locator;
    const int test_loc;
    bool found;

    void filter_ro(const Geometry* g) override {
        const Coordinate* pt = g->getCoordinate();
        const int loc = pt_locator->locate(pt);

        if (loc == test_loc) {
            found = true;
        }
    }

    bool isDone() override {
        return found;
    }
};

struct AnyNotMatchingLocationFilter : public GeometryComponentFilter {
    explicit AnyNotMatchingLocationFilter(algorithm::locate::PointOnGeometryLocator* locator, int loc) :
            pt_locator(locator), test_loc(loc), found(false) {}

    algorithm::locate::PointOnGeometryLocator* pt_locator;
    const int test_loc;
    bool found;

    void filter_ro(const Geometry* g) override {
        const Coordinate* pt = g->getCoordinate();
        const int loc = pt_locator->locate(pt);

        if (loc != test_loc) {
            found = true;
        }
    }

    bool isDone() override {
        return found;
    }
};

struct OutermostLocationFilter : public GeometryComponentFilter {
    explicit OutermostLocationFilter(algorithm::locate::PointOnGeometryLocator* locator) :
    pt_locator(locator),
    outermost_loc(geom::Location::UNDEF),
    done(false) {}

    algorithm::locate::PointOnGeometryLocator* pt_locator;
    Location::Value outermost_loc;
    bool done;

    void filter_ro(const Geometry* g) override {
        const Coordinate* pt = g->getCoordinate();
        auto loc = static_cast<Location::Value>(pt_locator->locate(pt));

        if (outermost_loc == Location::UNDEF || outermost_loc == Location::INTERIOR) {
            outermost_loc = loc;
        } else if (Location::EXTERIOR) {
            outermost_loc = loc;
            done = true;
        }
    }

    bool isDone() override {
        return done;
    }

    Location::Value getOutermostLocation() {
        return outermost_loc;
    }
};

Location::Value
PreparedPolygonPredicate::getOutermostTestComponentLocation(const geom::Geometry* testGeom) const
{
    OutermostLocationFilter filter(prepPoly->getPointLocator());
    testGeom->apply_ro(&filter);

    return filter.getOutermostLocation();
{'fraction_non_alphanumeric': 0.16424986056887897, 'fraction_numerical': 0.005856107083100948, 'mean_word_length': 3.7128777923784493, 'pattern_counts': {'":': 0, '<': 24, '<?xml version=': 0, '>': 40, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2546977', 'n_tokens_mistral': 2200, 'n_tokens_neox': 2085, 'n_words': 458}