Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions include/geode/geometry/is_point_inside.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright (c) 2019 - 2026 Geode-solutions
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*/

#pragma once
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: avoid 'pragma once' directive; use include guards instead [portability-avoid-pragma-once]

#pragma once
^


#include <geode/geometry/common.hpp>

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: included header common.hpp is not used directly [misc-include-cleaner]

Suggested change

namespace geode
{
FORWARD_DECLARATION_DIMENSION_CLASS( Point );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no header providing "FORWARD_DECLARATION_DIMENSION_CLASS" is directly included [misc-include-cleaner]

include/geode/geometry/is_point_inside.hpp:25:

- #include <geode/geometry/common.hpp>
+ #include "geode/basic/common.hpp"
+ #include <geode/geometry/common.hpp>

FORWARD_DECLARATION_DIMENSION_CLASS( Polygon );
ALIAS_2D( Point );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no header providing "ALIAS_2D" is directly included [misc-include-cleaner]

    ALIAS_2D( Point );
    ^

ALIAS_2D( Polygon );
} // namespace geode

namespace geode
{
/*!
* Find if point is inside a polygon.
* @param[in] point The point to rotate.
*/
[[nodiscard]] bool opengeode_geometry_api is_point_inside_polygon(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no header providing "opengeode_geometry_api" is directly included [misc-include-cleaner]

include/geode/geometry/is_point_inside.hpp:25:

- #include <geode/geometry/common.hpp>
+ #include "geode/geometry/opengeode_geometry_export.hpp"
+ #include <geode/geometry/common.hpp>

const Point2D& point, const Polygon2D& polygon );

} // namespace geode
2 changes: 2 additions & 0 deletions src/geode/geometry/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ add_geode_library(
"information.cpp"
"intersection.cpp"
"intersection_detection.cpp"
"is_point_inside.cpp"
"mensuration.cpp"
"nn_search.cpp"
"normal_frame_transform.cpp"
Expand Down Expand Up @@ -86,6 +87,7 @@ add_geode_library(
"information.hpp"
"intersection.hpp"
"intersection_detection.hpp"
"is_point_inside.hpp"
"mensuration.hpp"
"nn_search.hpp"
"normal_frame_transform.hpp"
Expand Down
79 changes: 79 additions & 0 deletions src/geode/geometry/is_point_inside.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* Copyright (c) 2019 - 2026 Geode-solutions
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*/

#include <geode/geometry/is_point_inside.hpp>

#include <geode/geometry/basic_objects/polygon.hpp>
#include <geode/geometry/point.hpp>

namespace
{
bool is_left( const geode::Point2D& p0,

Check warning on line 31 in src/geode/geometry/is_point_inside.cpp

View workflow job for this annotation

GitHub Actions / test / tidy

src/geode/geometry/is_point_inside.cpp:31:41 [readability-identifier-length]

parameter name 'p0' is too short, expected at least 3 characters
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: parameter name 'p0' is too short, expected at least 3 characters [readability-identifier-length]

    bool is_left( const geode::Point2D& p0,
                                        ^

const geode::Point2D& p1,

Check warning on line 32 in src/geode/geometry/is_point_inside.cpp

View workflow job for this annotation

GitHub Actions / test / tidy

src/geode/geometry/is_point_inside.cpp:32:31 [readability-identifier-length]

parameter name 'p1' is too short, expected at least 3 characters
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: parameter name 'p1' is too short, expected at least 3 characters [readability-identifier-length]

        const geode::Point2D& p1,
                              ^

const geode::Point2D& p2 )

Check warning on line 33 in src/geode/geometry/is_point_inside.cpp

View workflow job for this annotation

GitHub Actions / test / tidy

src/geode/geometry/is_point_inside.cpp:33:31 [readability-identifier-length]

parameter name 'p2' is too short, expected at least 3 characters
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: parameter name 'p2' is too short, expected at least 3 characters [readability-identifier-length]

        const geode::Point2D& p2 )
                              ^

{
return ( p1.value( 0 ) - p0.value( 0 ) )
* ( p2.value( 1 ) - p0.value( 1 ) )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: '*' has higher precedence than '-'; add parentheses to explicitly specify the order of operations [readability-math-missing-parentheses]

Suggested change
* ( p2.value( 1 ) - p0.value( 1 ) )
return (( p1.value( 0 ) - p0.value( 0 ) )
* ( p2.value( 1 ) - p0.value( 1 ) ))

- ( p2.value( 0 ) - p0.value( 0 ) )
* ( p1.value( 1 ) - p0.value( 1 ) )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: '*' has higher precedence than '-'; add parentheses to explicitly specify the order of operations [readability-math-missing-parentheses]

Suggested change
* ( p1.value( 1 ) - p0.value( 1 ) )
- (( p2.value( 0 ) - p0.value( 0 ) )
* ( p1.value( 1 ) - p0.value( 1 ) ))

> 0;
}
} // namespace

namespace geode
{
bool is_point_inside_polygon(

Check warning on line 45 in src/geode/geometry/is_point_inside.cpp

View workflow job for this annotation

GitHub Actions / test / tidy

src/geode/geometry/is_point_inside.cpp:45:10 [readability-function-cognitive-complexity]

function 'is_point_inside_polygon' has cognitive complexity of 18 (threshold 10)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: function 'is_point_inside_polygon' has cognitive complexity of 18 (threshold 10) [readability-function-cognitive-complexity]

    bool is_point_inside_polygon(
         ^
Additional context

src/geode/geometry/is_point_inside.cpp:49: +1, including nesting penalty of 0, nesting level increased to 1

        for( const auto polygon_vertex : geode::Range{ polygon.nb_vertices() } )
        ^

src/geode/geometry/is_point_inside.cpp:55: +2, including nesting penalty of 1, nesting level increased to 2

            if( v0.get().value( 1 ) <= point.value( 1 ) )
            ^

src/geode/geometry/is_point_inside.cpp:57: +3, including nesting penalty of 2, nesting level increased to 3

                if( v1.get().value( 1 ) > point.value( 1 ) )
                ^

src/geode/geometry/is_point_inside.cpp:59: +4, including nesting penalty of 3, nesting level increased to 4

                    if( is_left( v0, v1, point ) )
                    ^

src/geode/geometry/is_point_inside.cpp:65: +1, nesting level increased to 2

            else
            ^

src/geode/geometry/is_point_inside.cpp:67: +3, including nesting penalty of 2, nesting level increased to 3

                if( v1.get().value( 1 ) <= point.value( 1 ) )
                ^

src/geode/geometry/is_point_inside.cpp:69: +4, including nesting penalty of 3, nesting level increased to 4

                    if( !is_left( v0, v1, point ) )
                    ^

const Point2D& point, const Polygon2D& polygon )
{
double winding_number{ 0 };
const auto& vertices = polygon.vertices();
for( const auto polygon_vertex : geode::Range{ polygon.nb_vertices() } )
{
const auto& v0 = vertices[polygon_vertex];

Check warning on line 52 in src/geode/geometry/is_point_inside.cpp

View workflow job for this annotation

GitHub Actions / test / tidy

src/geode/geometry/is_point_inside.cpp:52:25 [readability-identifier-length]

variable name 'v0' is too short, expected at least 3 characters
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: variable name 'v0' is too short, expected at least 3 characters [readability-identifier-length]

            const auto& v0 = vertices[polygon_vertex];
                        ^

const auto& next_polygon_vertex =
( polygon_vertex + 1 ) % vertices.size();
const auto& v1 = vertices[next_polygon_vertex];

Check warning on line 55 in src/geode/geometry/is_point_inside.cpp

View workflow job for this annotation

GitHub Actions / test / tidy

src/geode/geometry/is_point_inside.cpp:55:25 [readability-identifier-length]

variable name 'v1' is too short, expected at least 3 characters
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: variable name 'v1' is too short, expected at least 3 characters [readability-identifier-length]

            const auto& v1 = vertices[next_polygon_vertex];
                        ^

if( v0.get().value( 1 ) <= point.value( 1 ) )
{
if( v1.get().value( 1 ) > point.value( 1 ) )
{
if( is_left( v0, v1, point ) )
{
winding_number++;
}
}
}
else
{
if( v1.get().value( 1 ) <= point.value( 1 ) )
{
if( !is_left( v0, v1, point ) )
{
winding_number--;
}
}
}
}
return winding_number != 0;
}
} // namespace geode
Loading