add noexcepts (#2119)

Co-authored-by: Bart Louwers <bart@emeel.net>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Bart Louwers <bart.louwers@gmail.com>
This commit is contained in:
Tim Sylvester
2024-04-08 08:39:18 -07:00
committed by GitHub
parent f868e0806f
commit 705bdfb3de
128 changed files with 1135 additions and 990 deletions

View File

@@ -5,7 +5,7 @@
namespace mbgl {
template <typename T>
void updateBBox(GeometryBBox<T>& bbox, const Point<T>& p) {
void updateBBox(GeometryBBox<T>& bbox, const Point<T>& p) noexcept {
bbox[0] = std::min(p.x, bbox[0]);
bbox[1] = std::min(p.y, bbox[1]);
bbox[2] = std::max(p.x, bbox[2]);
@@ -14,7 +14,7 @@ void updateBBox(GeometryBBox<T>& bbox, const Point<T>& p) {
// check if bbox1 is within bbox2
template <typename T>
bool boxWithinBox(const GeometryBBox<T>& bbox1, const GeometryBBox<T>& bbox2) {
bool boxWithinBox(const GeometryBBox<T>& bbox1, const GeometryBBox<T>& bbox2) noexcept {
if (bbox1[0] <= bbox2[0]) return false;
if (bbox1[2] >= bbox2[2]) return false;
if (bbox1[1] <= bbox2[1]) return false;
@@ -23,13 +23,13 @@ bool boxWithinBox(const GeometryBBox<T>& bbox1, const GeometryBBox<T>& bbox2) {
}
template <typename T>
bool rayIntersect(const Point<T>& p, const Point<T>& p1, const Point<T>& p2) {
bool rayIntersect(const Point<T>& p, const Point<T>& p1, const Point<T>& p2) noexcept {
return ((p1.y > p.y) != (p2.y > p.y)) && (p.x < (p2.x - p1.x) * (p.y - p1.y) / (p2.y - p1.y) + p1.x);
}
// check if point p is on line segment with end points p1 and p2
template <typename T>
bool pointOnBoundary(const Point<T>& p, const Point<T>& p1, const Point<T>& p2) {
bool pointOnBoundary(const Point<T>& p, const Point<T>& p1, const Point<T>& p2) noexcept {
// requirements of point p on line segment:
// 1. colinear: cross product of vector p->p1(x1, y1) and vector p->p2(x2, y2) equals to 0
// 2. p is between p1 and p2
@@ -41,21 +41,21 @@ bool pointOnBoundary(const Point<T>& p, const Point<T>& p1, const Point<T>& p2)
}
template <typename T>
bool segmentIntersectSegment(const Point<T>& a, const Point<T>& b, const Point<T>& c, const Point<T>& d) {
bool segmentIntersectSegment(const Point<T>& a, const Point<T>& b, const Point<T>& c, const Point<T>& d) noexcept {
// a, b are end points for line segment1, c and d are end points for line segment2
const auto perp = [](const Point<T>& v1, const Point<T>& v2) {
const auto perp = [](const Point<T>& v1, const Point<T>& v2) noexcept {
return (v1.x * v2.y - v1.y * v2.x);
};
// check if two segments are parallel or not
// precondition is end point a, b is inside polygon, if line a->b is
// parallel to polygon edge c->d, then a->b won't intersect with c->d
auto vectorP = Point<T>(b.x - a.x, b.y - a.y);
auto vectorQ = Point<T>(d.x - c.x, d.y - c.y);
const auto vectorP = Point<T>(b.x - a.x, b.y - a.y);
const auto vectorQ = Point<T>(d.x - c.x, d.y - c.y);
if (perp(vectorQ, vectorP) == 0) return false;
// check if p1 and p2 are in different sides of line segment q1->q2
const auto twoSided = [](const Point<T>& p1, const Point<T>& p2, const Point<T>& q1, const Point<T>& q2) {
const auto twoSided = [](const Point<T>& p1, const Point<T>& p2, const Point<T>& q1, const Point<T>& q2) noexcept {
// q1->p1 (x1, y1), q1->p2 (x2, y2), q1->q2 (x3, y3)
T x1 = p1.x - q1.x;
T y1 = p1.y - q1.y;
@@ -75,7 +75,7 @@ bool segmentIntersectSegment(const Point<T>& a, const Point<T>& b, const Point<T
}
template <typename T>
bool lineIntersectPolygon(const Point<T>& p1, const Point<T>& p2, const Polygon<T>& polygon) {
bool lineIntersectPolygon(const Point<T>& p1, const Point<T>& p2, const Polygon<T>& polygon) noexcept {
for (auto ring : polygon) {
auto length = ring.size();
// loop through every edge of the ring
@@ -90,7 +90,7 @@ bool lineIntersectPolygon(const Point<T>& p1, const Point<T>& p2, const Polygon<
// ray casting algorithm for detecting if point is in polygon
template <typename T>
bool pointWithinPolygon(const Point<T>& point, const Polygon<T>& polygon, bool trueOnBoundary) {
bool pointWithinPolygon(const Point<T>& point, const Polygon<T>& polygon, bool trueOnBoundary) noexcept {
bool within = false;
for (const auto& ring : polygon) {
const auto length = ring.size();
@@ -106,7 +106,7 @@ bool pointWithinPolygon(const Point<T>& point, const Polygon<T>& polygon, bool t
}
template <typename T>
bool pointWithinPolygons(const Point<T>& point, const MultiPolygon<T>& polygons, bool trueOnBoundary) {
bool pointWithinPolygons(const Point<T>& point, const MultiPolygon<T>& polygons, bool trueOnBoundary) noexcept {
for (const auto& polygon : polygons) {
if (pointWithinPolygon(point, polygon, trueOnBoundary)) return true;
}
@@ -114,7 +114,7 @@ bool pointWithinPolygons(const Point<T>& point, const MultiPolygon<T>& polygons,
}
template <typename T>
bool lineStringWithinPolygon(const LineString<T>& line, const Polygon<T>& polygon) {
bool lineStringWithinPolygon(const LineString<T>& line, const Polygon<T>& polygon) noexcept {
const auto length = line.size();
// First, check if geometry points of line segments are all inside polygon
for (std::size_t i = 0; i < length; ++i) {
@@ -133,35 +133,41 @@ bool lineStringWithinPolygon(const LineString<T>& line, const Polygon<T>& polygo
}
template <typename T>
bool lineStringWithinPolygons(const LineString<T>& line, const MultiPolygon<T>& polygons) {
bool lineStringWithinPolygons(const LineString<T>& line, const MultiPolygon<T>& polygons) noexcept {
for (const auto& polygon : polygons) {
if (lineStringWithinPolygon(line, polygon)) return true;
}
return false;
}
template void updateBBox(GeometryBBox<int64_t>& bbox, const Point<int64_t>& p);
template bool boxWithinBox(const GeometryBBox<int64_t>& bbox1, const GeometryBBox<int64_t>& bbox2);
template void updateBBox(GeometryBBox<int64_t>& bbox, const Point<int64_t>& p) noexcept;
template bool boxWithinBox(const GeometryBBox<int64_t>& bbox1, const GeometryBBox<int64_t>& bbox2) noexcept;
template bool segmentIntersectSegment(const Point<int64_t>& a,
const Point<int64_t>& b,
const Point<int64_t>& c,
const Point<int64_t>& d);
template bool rayIntersect(const Point<int64_t>& p, const Point<int64_t>& p1, const Point<int64_t>& p2);
template bool pointOnBoundary(const Point<int64_t>& p, const Point<int64_t>& p1, const Point<int64_t>& p2);
template bool lineIntersectPolygon(const Point<int64_t>& p1, const Point<int64_t>& p2, const Polygon<int64_t>& polygon);
template bool pointWithinPolygon(const Point<int64_t>& point, const Polygon<int64_t>& polygon, bool trueOnBoundary);
const Point<int64_t>& d) noexcept;
template bool rayIntersect(const Point<int64_t>& p, const Point<int64_t>& p1, const Point<int64_t>& p2) noexcept;
template bool pointOnBoundary(const Point<int64_t>& p, const Point<int64_t>& p1, const Point<int64_t>& p2) noexcept;
template bool lineIntersectPolygon(const Point<int64_t>& p1,
const Point<int64_t>& p2,
const Polygon<int64_t>& polygon) noexcept;
template bool pointWithinPolygon(const Point<int64_t>& point,
const Polygon<int64_t>& polygon,
bool trueOnBoundary) noexcept;
template bool pointWithinPolygons(const Point<int64_t>& point,
const MultiPolygon<int64_t>& polygons,
bool trueOnBoundary);
template bool lineStringWithinPolygon(const LineString<int64_t>& line, const Polygon<int64_t>& polygon);
template bool lineStringWithinPolygons(const LineString<int64_t>& line, const MultiPolygon<int64_t>& polygons);
bool trueOnBoundary) noexcept;
template bool lineStringWithinPolygon(const LineString<int64_t>& line, const Polygon<int64_t>& polygon) noexcept;
template bool lineStringWithinPolygons(const LineString<int64_t>& line, const MultiPolygon<int64_t>& polygons) noexcept;
template void updateBBox(GeometryBBox<double>& bbox, const Point<double>& p);
template bool boxWithinBox(const GeometryBBox<double>& bbox1, const GeometryBBox<double>& bbox2);
template void updateBBox(GeometryBBox<double>& bbox, const Point<double>& p) noexcept;
template bool boxWithinBox(const GeometryBBox<double>& bbox1, const GeometryBBox<double>& bbox2) noexcept;
template bool segmentIntersectSegment(const Point<double>& a,
const Point<double>& b,
const Point<double>& c,
const Point<double>& d);
template bool pointWithinPolygon(const Point<double>& point, const Polygon<double>& polygon, bool trueOnBoundary);
const Point<double>& d) noexcept;
template bool pointWithinPolygon(const Point<double>& point,
const Polygon<double>& polygon,
bool trueOnBoundary) noexcept;
} // namespace mbgl