This documentation is automatically generated by online-judge-tools/verification-helper
View the Project on GitHub Luzhiled/comp-geometry
#include "src/real-geometry/position/point-polygon-positional-relationships.hpp"
#pragma once #include "src/real-geometry/class/point.hpp" #include "src/real-geometry/class/polygon.hpp" #include "src/real-geometry/numbers/posision-of-point-polygon.hpp" #include "src/real-geometry/operation/cross-product.hpp" #include "src/real-geometry/operation/inner-product.hpp" #include "src/real-geometry/common/size-alias.hpp" #include "src/real-geometry/utility/next-idx.hpp" #include "src/real-geometry/utility/sign.hpp" #include <algorithm> namespace geometry { // O(N) template< typename R > int point_polygon_positional_relationships(const point<R> &p, const polygon<R> &poly) { using namespace number::point_polygon_positional_relationships; usize n = poly.size(); bool in = false; for (usize i = 0; i < n; i++) { usize j = next_idx(i, n); point<R> a = poly[i] - p, b = poly[j] - p; if (a.y() > b.y()) std::swap(a, b); if (a.y() <= 0 and 0 < b.y() and cross_product(a, b) < 0) { in = not in; } if (sign(cross_product(a, b)) == 0 and sign(inner_product(a, b)) <= 0) { return ON_EDGE; } } return in ? IN : OUT; } }
#line 2 "src/real-geometry/position/point-polygon-positional-relationships.hpp" #line 2 "src/real-geometry/class/point.hpp" #line 2 "src/real-geometry/class/vector.hpp" #include <complex> #include <iostream> namespace geometry { template< typename R > class vec2d : public std::complex< R > { using complex = std::complex< R >; public: using complex::complex; vec2d(const complex &c): complex::complex(c) {} const R x() const { return this->real(); } const R y() const { return this->imag(); } friend vec2d operator*(const vec2d &v, const R &k) { return vec2d(v.x() * k, v.y() * k); } friend vec2d operator*(const R &k, const vec2d &v) { return vec2d(v.x() * k, v.y() * k); } friend std::istream &operator>>(std::istream &is, vec2d &v) { R x, y; is >> x >> y; v = vec2d(x, y); return is; } }; } #line 4 "src/real-geometry/class/point.hpp" #include <vector> namespace geometry { template< typename R > using point = vec2d<R>; template< typename R > using points = std::vector< point< R > >; } #line 2 "src/real-geometry/class/polygon.hpp" #line 4 "src/real-geometry/class/polygon.hpp" #line 6 "src/real-geometry/class/polygon.hpp" namespace geometry { template< typename R > using polygon = std::vector< point<R> >; template< typename R > using polygons = std::vector< polygon<R> >; } #line 2 "src/real-geometry/numbers/posision-of-point-polygon.hpp" namespace geometry::number::point_polygon_positional_relationships { constexpr int OUT = 0; constexpr int ON_EDGE = 1; constexpr int IN = 2; } #line 2 "src/real-geometry/operation/cross-product.hpp" #line 4 "src/real-geometry/operation/cross-product.hpp" namespace geometry { template< typename R > R cross_product(const vec2d<R> &a, const vec2d<R> &b) { return a.x() * b.y() - a.y() * b.x(); } } #line 2 "src/real-geometry/operation/inner-product.hpp" #line 4 "src/real-geometry/operation/inner-product.hpp" namespace geometry { template< typename R > R inner_product(const vec2d<R> &a, const vec2d<R> &b) { return a.x() * b.x() + a.y() * b.y(); } } #line 2 "src/real-geometry/common/size-alias.hpp" #include <cstddef> namespace geometry { using isize = std::ptrdiff_t; using usize = std::size_t; } #line 2 "src/real-geometry/utility/next-idx.hpp" #line 4 "src/real-geometry/utility/next-idx.hpp" namespace geometry { inline usize next_idx(usize idx, usize size) { return idx + 1 == size ? 0 : idx + 1; } } #line 2 "src/real-geometry/utility/sign.hpp" #line 2 "src/real-geometry/common/const/eps.hpp" #line 2 "src/real-geometry/common/float-alias.hpp" namespace geometry { using f80 = long double; using f64 = double; } #line 4 "src/real-geometry/common/const/eps.hpp" namespace geometry { inline static f80 &eps() { static f80 EPS = 1e-10; return EPS; } void set_eps(f80 EPS) { eps() = EPS; } } #line 2 "src/real-geometry/numbers/sign.hpp" #line 2 "src/real-geometry/common/int-alias.hpp" namespace geometry { using i32 = int; using i64 = long long; } #line 4 "src/real-geometry/numbers/sign.hpp" namespace geometry::number::sign { constexpr i32 PLUS = +1; constexpr i32 ZERO = 0; constexpr i32 MINUS = -1; } #line 5 "src/real-geometry/utility/sign.hpp" namespace geometry { using namespace geometry::number::sign; template< typename R > inline int sign(R r) { if (r < -eps()) return MINUS; if (r > +eps()) return PLUS; return ZERO; } } #line 11 "src/real-geometry/position/point-polygon-positional-relationships.hpp" #include <algorithm> namespace geometry { // O(N) template< typename R > int point_polygon_positional_relationships(const point<R> &p, const polygon<R> &poly) { using namespace number::point_polygon_positional_relationships; usize n = poly.size(); bool in = false; for (usize i = 0; i < n; i++) { usize j = next_idx(i, n); point<R> a = poly[i] - p, b = poly[j] - p; if (a.y() > b.y()) std::swap(a, b); if (a.y() <= 0 and 0 < b.y() and cross_product(a, b) < 0) { in = not in; } if (sign(cross_product(a, b)) == 0 and sign(inner_product(a, b)) <= 0) { return ON_EDGE; } } return in ? IN : OUT; } }