library

This documentation is automatically generated by online-judge-tools/verification-helper

View the Project on GitHub kk2a/library

:heavy_check_mark: geometry/argument_sort.hpp

Depends on

Verified with

Code

#ifndef KK2_GEOMETRY_ARGUMENT_SORT_HPP
#define KK2_GEOMETRY_ARGUMENT_SORT_HPP 1

#include <algorithm>
#include <vector>

#include "point.hpp"

namespace kk2 {

template <class T> struct ArgumentSort {
    using point = Point<T>;
    point O;

    ArgumentSort(const point &O_ = point()) : O(O_) {}

    // p - O = (x, y)
    // 1 : y < 0
    // 2 : y >= 0 and x >= 0
    // 3 : otherwise
    int location(const point &p) {
        point q = p - O;
        return q.y < 0 ? 1 : q.x >= 0 ? 2 : 3;
    }

    bool cmp(const point &a, const point &b) {
        int loc_a = location(a), loc_b = location(b);
        T cr = cross(a, b, O);
        return loc_a != loc_b ? loc_a < loc_b : cr == 0 ? norm(a, O) < norm(b, O) : cr > 0;
    }

    void argument_sort(std::vector<point> &ps) {
        std::sort(
            ps.begin(), ps.end(), [this](auto &&a, auto &&b) -> bool { return this->cmp(a, b); });
    }

    template <class Iterator>
    Iterator min_up_argument(Iterator first, Iterator last, const point &p) {
        return std::lower_bound(
            first, last, p, [this](auto &&a, auto &&b) -> bool { return this->cmp(a, b); });
    }
};

} // namespace kk2

#endif // KK2_GEOMETRY_ARGUMENT_SORT_HPP
Traceback (most recent call last):
  File "/opt/hostedtoolcache/Python/3.12.0/x64/lib/python3.12/site-packages/onlinejudge_verify/documentation/build.py", line 71, in _render_source_code_stat
    bundled_code = language.bundle(stat.path, basedir=basedir, options={'include_paths': [basedir]}).decode()
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.12.0/x64/lib/python3.12/site-packages/onlinejudge_verify/languages/cplusplus.py", line 187, in bundle
    bundler.update(path)
  File "/opt/hostedtoolcache/Python/3.12.0/x64/lib/python3.12/site-packages/onlinejudge_verify/languages/cplusplus_bundle.py", line 401, in update
    self.update(self._resolve(pathlib.Path(included), included_from=path))
  File "/opt/hostedtoolcache/Python/3.12.0/x64/lib/python3.12/site-packages/onlinejudge_verify/languages/cplusplus_bundle.py", line 312, in update
    raise BundleErrorAt(path, i + 1, "#pragma once found in a non-first line")
onlinejudge_verify.languages.cplusplus_bundle.BundleErrorAt: geometry/point.hpp: line 4: #pragma once found in a non-first line
Back to top page