<commit_before>/**
*   IntersectsOtherOperation.hpp
*
*   Copyright 2015 <NAME>
*
*   Licensed under the Apache License, Version 2.0 (the "License");
*   you may not use this file except in compliance with the License.
*   You may obtain a copy of the License at
*
*   http://www.apache.org/licenses/LICENSE-2.0
*
*   Unless required by applicable law or agreed to in writing, software
*   distributed under the License is distributed on an "AS IS" BASIS,
*   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*   See the License for the specific language governing permissions and
*   limitations under the License.
*
*   Created by <NAME> on 10/6/15.
*/

#ifndef __GeoFeature_Intersects_Other_Operation_HPP_
#define __GeoFeature_Intersects_Other_Operation_HPP_

#include <boost/variant/variant.hpp>
#include <boost/geometry/strategies/strategies.hpp>
#include <boost/geometry/algorithms/intersects.hpp>

#include "GeometryVariant.hpp"

namespace geofeatures {
    namespace operators {

        /**
         * @class       IntersectsSelfOperation
         *
         * @brief       Operation to test for self intersection.
         *
         * @author      <NAME>
         * @date        10/6/15
         */
        struct IntersectsOtherOperation : public  boost::static_visitor<bool> {

            //
            // Internal class to convert from GeometryCollection variant
            // to the GeometryPtrVariant type.
            //
            struct VariantToPtrVariant : public boost::static_visitor<GeometryPtrVariant> {
                template <typename T>
                GeometryPtrVariant operator()(const T & v) const {
                    return GeometryPtrVariant(&v);
                }
            };
            //
            // Intersects operation methods
            //
            bool operator()(const MultiPoint * lhs, const Ring * rhs) const {
                return false;
            }
            bool operator()(const Ring * lhs, const MultiPoint * rhs) const {
                return false;
            }
            
            bool operator()(const Polygon * lhs, const MultiPoint * rhs) const {
                return false;
            }
            bool operator()(const MultiPoint * lhs, const Polygon * rhs) const {
                return false;
            }
            
            bool operator()(const MultiPoint * lhs, const MultiPolygon * rhs) const {
                return false;
            }
            bool operator()(const MultiPolygon * lhs, const MultiPoint * rhs) const {
                return false;
            }
            
            // Generic intersects that aere implemented by boost
            template <typename T, typename TO>
            bool operator()(const T * lhs, const TO * rhs) const {
                return boost::geometry::intersects(*lhs,*rhs);
            }

            // GeometryCollection intersects
            bool operator()(const GeometryCollection<> * lhs, const GeometryCollection<> * rhs) const {
                auto variantToPtrVariantVisitor = VariantToPtrVariant();
                auto intersectsOperationVisitor = IntersectsOtherOperation();
                
                auto variantToPrVariant(boost::apply_visitor(variantToPtrVariantVisitor));
                auto intersects(boost::apply_visitor(intersectsOperationVisitor));
<commit_msg>Update IntersectsOtherOperation.hpp - Add multiIntersects free function template. - Completed intersects specialization MultiPoint Ring. - Completed intersects specialization Ring MultiPoint. - Completed intersects specialization Polygon MultiPoint. - Completed intersects specialization MultiPoint Polygon. - Completed intersects specialization MultiPoint MultiPolygon. - Completed intersects specialization MultiPolygon MultiPoint.<commit_after>/**
*   IntersectsOtherOperation.hpp
*
*   Copyright 2015 <NAME>
*
*   Licensed under the Apache License, Version 2.0 (the "License");
*   you may not use this file except in compliance with the License.
*   You may obtain a copy of the License at
*
*   http://www.apache.org/licenses/LICENSE-2.0
*
*   Unless required by applicable law or agreed to in writing, software
*   distributed under the License is distributed on an "AS IS" BASIS,
*   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*   See the License for the specific language governing permissions and
*   limitations under the License.
*
*   Created by <NAME> on 10/6/15.
*/

#ifndef __GeoFeature_Intersects_Other_Operation_HPP_
#define __GeoFeature_Intersects_Other_Operation_HPP_

#include <boost/variant/apply_visitor.hpp>
#include <boost/variant/static_visitor.hpp>
#include <boost/variant/variant_fwd.hpp>

#include <boost/geometry/strategies/strategies.hpp>
#include <boost/geometry/algorithms/intersects.hpp>

#include <boost/geometry/geometries/concepts/check.hpp>

#include "internal/geofeatures/MultiPointView.hpp"

#include "GeometryVariant.hpp"

namespace geofeatures {
    namespace operators {
        
        /**
         * Free function template to apply intersection to a multiType to
         * another type.
         */
        template<typename T1, typename T2>
        inline bool multiIntersects(const T1 * t1, const T2 * t2) {
            //
            // If any point in the item in the multi intersects the other geoemtry,
            // we have an intersection.
            //
            for (auto it = t1->begin(); it != t1->end(); it++) {
                if (boost::geometry::intersects(*it,*t2)) {
                    return true;
                }
            }
            return false;
        };

        /**
         * @class       IntersectsSelfOperation
         *
         * @brief       Operation to test for self intersection.
         *
         * @author      <NAME>
         * @date        10/6/15
         */
        struct IntersectsOtherOperation : public  boost::static_visitor<bool> {

            //
            // Internal class to convert from GeometryCollection variant
            // to the GeometryPtrVariant type.
            //
            struct VariantToPtrVariant : public boost::static_visitor<GeometryPtrVariant> {
                template <typename T>
                GeometryPtrVariant operator()(const T & v) const {
                    return GeometryPtrVariant(&v);
                }
            };

            // Generic intersects that are implemented by boost
            template <typename T, typename TO>
            bool operator()(const T * lhs, const TO * rhs) const {
                return boost::geometry::intersects(*lhs,*rhs);
            }

            //
            // Intersects operation methods specific to 2 types
            //
            bool operator()(const MultiPoint * multiPoint, const Ring * ring) const {
                return multiIntersects(multiPoint,ring);
            }

            bool operator()(const Ring * ring, const MultiPoint * multiPoint) const {
                // reverse them and use the multiIntersect
                return multiIntersects(multiPoint,ring);
            }
            
            bool operator()(const Polygon * polygon, const MultiPoint * multiPoint) const {
                // reverse them and use the multiIntersect
                return multiIntersects(multiPoint,polygon);
            }

            bool operator()(const MultiPoint * multiPoint, const Polygon * polygon) const {
                return multiIntersects(multiPoint,polygon);
            }
            
            bool operator()(const MultiPoint * multiPoint, const MultiPolygon * multiPolygon) const {
                return multiIntersects(multiPoint,multiPolygon);
            }

            bool operator()(const MultiPolygon * multiPolygon, const MultiPoint * multiPoint) const {
                // reverse them and use the multiIntersect
                return multiIntersects(multiPoint,multiPolygon);
            }

            bool operator()(const GeometryCollection<> * lhs, const GeometryCollection<> * rhs) const {
                auto variantToPtrVariantVisitor = VariantToPtrVariant();
                auto intersectsOperationVisitor = IntersectsOtherOperation();
                
                auto variantToPrVariant(boost::apply_visitor(variantToPtrVariantVisitor));
                auto intersects(boost::apply_visitor(intersectsOperationVisitor));

{'fraction_non_alphanumeric': 0.07868383404864092, 'fraction_numerical': 0.005484024797329518, 'mean_word_length': 2.084191176470588, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '3524221', 'n_tokens_mistral': 2137, 'n_tokens_neox': 1996, 'n_words': 620}