-
-
Notifications
You must be signed in to change notification settings - Fork 15
feat(IspointInside): check if a point is inside a polygon #1240
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
1bc458d
15b4e2c
4861366
5c7db62
181a4ed
2730337
a8daaeb
7c67d6d
994de2e
883191f
14cd58d
fc639c5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| /* | ||
| * 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 | ||
|
|
||
| #include <geode/geometry/basic_objects/polygon.hpp> | ||
| #include <geode/geometry/common.hpp> | ||
| #include <geode/geometry/point.hpp> | ||
|
|
||
| namespace geode | ||
| { | ||
| /*! | ||
| * Find if point is inside a polygon. | ||
| * @param[in] point The point to rotate. | ||
| * @param[in] axis Axis for the rotation (not null but not necessary | ||
| * normalized). | ||
| * @param[in] angle Rotation angle expresses in radians. | ||
|
panquez marked this conversation as resolved.
Outdated
|
||
| */ | ||
| [[nodiscard]] bool opengeode_geometry_api is_point_inside_polygon( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, absl::Span< const Point2D > polygon_points ); | ||
|
panquez marked this conversation as resolved.
Outdated
|
||
|
|
||
| } // namespace geode | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| /* | ||
| * 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/basic/logger.hpp> | ||
|
|
||
| namespace | ||
| { | ||
| double is_left( const geode::Point2D& p0, | ||
|
panquez marked this conversation as resolved.
Outdated
|
||
| const geode::Point2D& p1, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 ) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 ) ) | ||
| - ( p2.value( 0 ) - p0.value( 0 ) ) | ||
| * ( p1.value( 1 ) - p0.value( 1 ) ); | ||
| } | ||
| } // namespace | ||
|
|
||
| namespace geode | ||
| { | ||
| bool opengeode_geometry_api is_point_inside_polygon( | ||
|
panquez marked this conversation as resolved.
Outdated
|
||
| const Point2D& point, absl::Span< const Point2D > polygon_points ) | ||
| { | ||
| double widing_number{ 0 }; | ||
|
panquez marked this conversation as resolved.
Outdated
|
||
| DEBUG( "is_point_inside_polygon" ); | ||
| SDEBUG( point ); | ||
| for( const auto polygon_vertex : | ||
| geode::Range{ 0, polygon_points.size() } ) | ||
| { | ||
| const auto v0 = polygon_points[polygon_vertex]; | ||
| const auto next_polygon_vertex = | ||
| ( polygon_vertex + 1 ) % polygon_points.size(); | ||
| const auto v1 = polygon_points[next_polygon_vertex]; | ||
| SDEBUG( v0 ); | ||
| SDEBUG( v1 ); | ||
|
panquez marked this conversation as resolved.
Outdated
|
||
| if( v0.value( 1 ) <= point.value( 1 ) ) | ||
| { | ||
| if( v1.value( 1 ) > point.value( 1 ) ) | ||
| { | ||
| if( is_left( v0, v1, point ) > 0 ) | ||
| { | ||
| DEBUG( "widing_number++" ); | ||
| widing_number++; | ||
| } | ||
| } | ||
| } | ||
| else | ||
| { | ||
| if( v1.value( 1 ) <= point.value( 1 ) ) | ||
| { | ||
| if( is_left( v0, v1, point ) < 0 ) | ||
| { | ||
| DEBUG( "widing_number--" ); | ||
| widing_number--; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| DEBUG( widing_number ); | ||
| return widing_number != 0; | ||
| } | ||
| } // namespace geode | ||
There was a problem hiding this comment.
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 ^