summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2016-03-16 17:45:00 -0700
committerJohn Firebaugh <john.firebaugh@gmail.com>2016-05-05 11:30:53 -0700
commit9330d674a983652d248d6a43fa4adbf5970c3d30 (patch)
treebd9292fcdb14f416922197f36c7707bb52e13591
parentf89cfacab2457602c5bd81ab9da35cede23584e2 (diff)
downloadqtlocation-mapboxgl-9330d674a983652d248d6a43fa4adbf5970c3d30.tar.gz
[core] Use geometry.hpp's point
m---------.mason0
-rw-r--r--include/mbgl/util/geo.hpp6
-rw-r--r--platform/android/scripts/configure.sh2
-rw-r--r--platform/ios/ios.xcodeproj/project.pbxproj8
-rw-r--r--platform/ios/scripts/configure.sh2
-rw-r--r--platform/linux/scripts/configure.sh2
-rw-r--r--platform/osx/osx.xcodeproj/project.pbxproj8
-rw-r--r--platform/osx/scripts/configure.sh2
-rw-r--r--platform/qt/scripts/configure.sh2
-rw-r--r--platform/qt/src/qmapboxgl.cpp3
-rw-r--r--src/mbgl/annotation/point_annotation_impl.cpp6
-rw-r--r--src/mbgl/geometry/anchor.hpp9
-rw-r--r--src/mbgl/layer/line_layer.cpp18
-rw-r--r--src/mbgl/map/map.cpp2
-rw-r--r--src/mbgl/map/transform.cpp20
-rw-r--r--src/mbgl/map/transform_state.cpp36
-rw-r--r--src/mbgl/map/transform_state.hpp1
-rw-r--r--src/mbgl/renderer/line_bucket.cpp104
-rw-r--r--src/mbgl/renderer/line_bucket.hpp5
-rw-r--r--src/mbgl/renderer/symbol_bucket.cpp29
-rw-r--r--src/mbgl/renderer/symbol_bucket.hpp3
-rw-r--r--src/mbgl/source/source.cpp2
-rw-r--r--src/mbgl/text/check_max_angle.cpp2
-rw-r--r--src/mbgl/text/collision_feature.cpp10
-rw-r--r--src/mbgl/text/collision_feature.hpp5
-rw-r--r--src/mbgl/text/collision_tile.cpp42
-rw-r--r--src/mbgl/text/collision_tile.hpp6
-rw-r--r--src/mbgl/text/glyph_set.cpp6
-rw-r--r--src/mbgl/text/glyph_set.hpp6
-rw-r--r--src/mbgl/text/quads.cpp64
-rw-r--r--src/mbgl/text/quads.hpp11
-rw-r--r--src/mbgl/text/shaping.hpp2
-rw-r--r--src/mbgl/tile/geometry_tile.hpp4
-rw-r--r--src/mbgl/util/geometry.hpp31
-rw-r--r--src/mbgl/util/intersection_tests.cpp2
-rw-r--r--src/mbgl/util/mat4.cpp11
-rw-r--r--src/mbgl/util/mat4.hpp5
-rw-r--r--src/mbgl/util/math.hpp20
-rw-r--r--src/mbgl/util/tile_cover.cpp1
-rw-r--r--src/mbgl/util/vec.hpp126
-rw-r--r--test/map/transform.cpp5
41 files changed, 263 insertions, 366 deletions
diff --git a/.mason b/.mason
-Subproject 2d75da369d1ebc7c5dd4139cde8941074366524
+Subproject 79234f915fa159f027c6c268ff2e5ececdb9c51
diff --git a/include/mbgl/util/geo.hpp b/include/mbgl/util/geo.hpp
index cb9cb71fc5..6aecea33fb 100644
--- a/include/mbgl/util/geo.hpp
+++ b/include/mbgl/util/geo.hpp
@@ -2,16 +2,18 @@
#define MBGL_UTIL_GEO
#include <mbgl/math/wrap.hpp>
-#include <mbgl/util/vec.hpp>
#include <mbgl/util/constants.hpp>
+#include <mapbox/geometry/point.hpp>
+#include <mapbox/geometry/point_arithmetic.hpp>
+
#include <cmath>
namespace mbgl {
class TileID;
-using ScreenCoordinate = vec2<double>;
+using ScreenCoordinate = mapbox::geometry::point<double>;
class LatLng {
public:
diff --git a/platform/android/scripts/configure.sh b/platform/android/scripts/configure.sh
index 30913aaf92..9470563517 100644
--- a/platform/android/scripts/configure.sh
+++ b/platform/android/scripts/configure.sh
@@ -8,7 +8,7 @@ SQLITE_VERSION=3.9.1
ZLIB_VERSION=system
NUNICODE_VERSION=1.6
LIBZIP_VERSION=0.11.2
-GEOMETRY_VERSION=0.1.0
+GEOMETRY_VERSION=0.2.0
GEOJSONVT_VERSION=4.1.2
VARIANT_VERSION=1.1.0
RAPIDJSON_VERSION=1.0.2
diff --git a/platform/ios/ios.xcodeproj/project.pbxproj b/platform/ios/ios.xcodeproj/project.pbxproj
index f97263f2cd..8265f1c2d8 100644
--- a/platform/ios/ios.xcodeproj/project.pbxproj
+++ b/platform/ios/ios.xcodeproj/project.pbxproj
@@ -1549,6 +1549,10 @@
INFOPLIST_FILE = test/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
+ OTHER_CPLUSPLUSFLAGS = (
+ "$(OTHER_CFLAGS)",
+ "$(geometry_cflags)",
+ );
PRODUCT_BUNDLE_IDENTIFIER = com.mapbox.test;
PRODUCT_NAME = "$(TARGET_NAME)";
};
@@ -1562,6 +1566,10 @@
INFOPLIST_FILE = test/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
+ OTHER_CPLUSPLUSFLAGS = (
+ "$(OTHER_CFLAGS)",
+ "$(geometry_cflags)",
+ );
PRODUCT_BUNDLE_IDENTIFIER = com.mapbox.test;
PRODUCT_NAME = "$(TARGET_NAME)";
};
diff --git a/platform/ios/scripts/configure.sh b/platform/ios/scripts/configure.sh
index c92e58c7d2..796564095d 100644
--- a/platform/ios/scripts/configure.sh
+++ b/platform/ios/scripts/configure.sh
@@ -4,7 +4,7 @@ PROTOZERO_VERSION=1.3.0
BOOST_VERSION=1.60.0
SQLITE_VERSION=system
ZLIB_VERSION=system
-GEOMETRY_VERSION=0.1.0
+GEOMETRY_VERSION=0.2.0
GEOJSONVT_VERSION=4.1.2
VARIANT_VERSION=1.1.0
RAPIDJSON_VERSION=1.0.2
diff --git a/platform/linux/scripts/configure.sh b/platform/linux/scripts/configure.sh
index 5f7edf7f8a..a55545434e 100644
--- a/platform/linux/scripts/configure.sh
+++ b/platform/linux/scripts/configure.sh
@@ -11,7 +11,7 @@ SQLITE_VERSION=3.9.1
LIBUV_VERSION=1.7.5
ZLIB_VERSION=system
NUNICODE_VERSION=1.6
-GEOMETRY_VERSION=0.1.0
+GEOMETRY_VERSION=0.2.0
GEOJSONVT_VERSION=4.1.2
VARIANT_VERSION=1.1.0
RAPIDJSON_VERSION=1.0.2
diff --git a/platform/osx/osx.xcodeproj/project.pbxproj b/platform/osx/osx.xcodeproj/project.pbxproj
index 61c028bf8f..0f462d498d 100644
--- a/platform/osx/osx.xcodeproj/project.pbxproj
+++ b/platform/osx/osx.xcodeproj/project.pbxproj
@@ -1005,6 +1005,10 @@
HEADER_SEARCH_PATHS = ../../include;
INFOPLIST_FILE = test/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
+ OTHER_CPLUSPLUSFLAGS = (
+ "$(OTHER_CFLAGS)",
+ "$(geometry_cflags)",
+ );
PRODUCT_BUNDLE_IDENTIFIER = com.mapbox.test;
PRODUCT_NAME = "$(TARGET_NAME)";
};
@@ -1018,6 +1022,10 @@
HEADER_SEARCH_PATHS = ../../include;
INFOPLIST_FILE = test/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
+ OTHER_CPLUSPLUSFLAGS = (
+ "$(OTHER_CFLAGS)",
+ "$(geometry_cflags)",
+ );
PRODUCT_BUNDLE_IDENTIFIER = com.mapbox.test;
PRODUCT_NAME = "$(TARGET_NAME)";
};
diff --git a/platform/osx/scripts/configure.sh b/platform/osx/scripts/configure.sh
index 44e0c618e9..8a5c457b73 100644
--- a/platform/osx/scripts/configure.sh
+++ b/platform/osx/scripts/configure.sh
@@ -7,7 +7,7 @@ GLFW_VERSION=3.1.2
SQLITE_VERSION=3.9.1
ZLIB_VERSION=system
NUNICODE_VERSION=1.6
-GEOMETRY_VERSION=0.1.0
+GEOMETRY_VERSION=0.2.0
GEOJSONVT_VERSION=4.1.2
VARIANT_VERSION=1.1.0
RAPIDJSON_VERSION=1.0.2
diff --git a/platform/qt/scripts/configure.sh b/platform/qt/scripts/configure.sh
index b1ff652f38..d956100d4e 100644
--- a/platform/qt/scripts/configure.sh
+++ b/platform/qt/scripts/configure.sh
@@ -2,7 +2,7 @@
PROTOZERO_VERSION=1.3.0
BOOST_VERSION=1.60.0
-GEOMETRY_VERSION=0.1.0
+GEOMETRY_VERSION=0.2.0
GEOJSONVT_VERSION=4.1.2
GTEST_VERSION=1.7.0
LIBJPEG_TURBO_VERSION=1.4.2
diff --git a/platform/qt/src/qmapboxgl.cpp b/platform/qt/src/qmapboxgl.cpp
index 990997bb60..633223488e 100644
--- a/platform/qt/src/qmapboxgl.cpp
+++ b/platform/qt/src/qmapboxgl.cpp
@@ -10,7 +10,6 @@
#include <mbgl/util/constants.hpp>
#include <mbgl/util/geo.hpp>
#include <mbgl/util/traits.hpp>
-#include <mbgl/util/vec.hpp>
#include <QCoreApplication>
#include <QImage>
@@ -497,7 +496,7 @@ void QMapboxGL::addAnnotationIcon(const QString &name, const QImage &sprite)
QPointF QMapboxGL::pixelForCoordinate(const Coordinate &coordinate_) const
{
- const mbgl::vec2<double> pixel =
+ const mbgl::ScreenCoordinate pixel =
d_ptr->mapObj->pixelForLatLng(mbgl::LatLng { coordinate_.first, coordinate_.second });
return QPointF(pixel.x, pixel.y);
diff --git a/src/mbgl/annotation/point_annotation_impl.cpp b/src/mbgl/annotation/point_annotation_impl.cpp
index d3f0bce0a2..888a806b5b 100644
--- a/src/mbgl/annotation/point_annotation_impl.cpp
+++ b/src/mbgl/annotation/point_annotation_impl.cpp
@@ -21,15 +21,15 @@ void PointAnnotationImpl::updateLayer(const TileID& tileID, AnnotationTileLayer&
const double x = point.position.longitude / util::DEGREES_MAX + 0.5;
const double y = 0.5 - 0.25 * std::log((1.0 + sine) / (1.0 - sine)) / M_PI;
- vec2<double> projected(x, y);
+ Point<double> projected(x, y);
projected *= std::pow(2, tileID.z);
projected.x = std::fmod(projected.x, 1);
projected.y = std::fmod(projected.y, 1);
- projected *= GeometryTileFeature::defaultExtent;
+ projected *= double(GeometryTileFeature::defaultExtent);
layer.features.emplace_back(
std::make_shared<const AnnotationTileFeature>(FeatureType::Point,
- GeometryCollection {{ {{ GeometryCoordinate { projected } }} }},
+ GeometryCollection {{ {{ convertPoint<int16_t>(projected) }} }},
featureProperties));
}
diff --git a/src/mbgl/geometry/anchor.hpp b/src/mbgl/geometry/anchor.hpp
index 49979cc15a..0dd252216a 100644
--- a/src/mbgl/geometry/anchor.hpp
+++ b/src/mbgl/geometry/anchor.hpp
@@ -1,21 +1,22 @@
#ifndef MBGL_GEOMETRY_ANCHOR
#define MBGL_GEOMETRY_ANCHOR
+#include <mbgl/util/geometry.hpp>
+
#include <vector>
namespace mbgl {
struct Anchor {
- float x = 0.0f;
- float y = 0.0f;
+ Point<float> point;
float angle = 0.0f;
float scale = 0.0f;
int segment = -1;
explicit Anchor(float x_, float y_, float angle_, float scale_)
- : x(x_), y(y_), angle(angle_), scale(scale_) {}
+ : point(x_, y_), angle(angle_), scale(scale_) {}
explicit Anchor(float x_, float y_, float angle_, float scale_, int segment_)
- : x(x_), y(y_), angle(angle_), scale(scale_), segment(segment_) {}
+ : point(x_, y_), angle(angle_), scale(scale_), segment(segment_) {}
};
diff --git a/src/mbgl/layer/line_layer.cpp b/src/mbgl/layer/line_layer.cpp
index e99a0d69f1..3671b207a0 100644
--- a/src/mbgl/layer/line_layer.cpp
+++ b/src/mbgl/layer/line_layer.cpp
@@ -102,30 +102,30 @@ float LineLayer::getLineWidth() const {
}
}
-optional<GeometryCollection> offsetLine(const GeometryCollection& rings, const float offset) {
+optional<GeometryCollection> offsetLine(const GeometryCollection& rings, const double offset) {
if (offset == 0) return {};
GeometryCollection newRings;
- vec2<double> zero(0, 0);
- for (auto& ring : rings) {
+ Point<double> zero(0, 0);
+ for (const auto& ring : rings) {
newRings.emplace_back();
auto& newRing = newRings.back();
for (auto i = ring.begin(); i != ring.end(); i++) {
auto& p = *i;
- auto aToB = i == ring.begin() ?
+ Point<double> aToB = i == ring.begin() ?
zero :
- util::perp(util::unit(vec2<double>(p - *(i - 1))));
- auto bToC = i + 1 == ring.end() ?
+ util::perp(util::unit(convertPoint<double>(p - *(i - 1))));
+ Point<double> bToC = i + 1 == ring.end() ?
zero :
- util::perp(util::unit(vec2<double>(*(i + 1) - p)));
- auto extrude = util::unit(aToB + bToC);
+ util::perp(util::unit(convertPoint<double>(*(i + 1) - p)));
+ Point<double> extrude = util::unit(aToB + bToC);
const double cosHalfAngle = extrude.x * bToC.x + extrude.y * bToC.y;
extrude *= (1.0 / cosHalfAngle);
- newRing.push_back((extrude * offset) + p);
+ newRing.push_back(convertPoint<int16_t>(extrude * offset) + p);
}
}
diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp
index a1dd9b6a77..0747606fc6 100644
--- a/src/mbgl/map/map.cpp
+++ b/src/mbgl/map/map.cpp
@@ -525,7 +525,7 @@ CameraOptions Map::cameraForLatLngs(const std::vector<LatLng>& latLngs, optional
};
centerPixel = centerPixel + paddedNEPixel - paddedSWPixel;
}
- centerPixel /= 2;
+ centerPixel /= 2.0;
// CameraOptions origin is at the top-left corner.
centerPixel.y = viewportHeight - centerPixel.y;
diff --git a/src/mbgl/map/transform.cpp b/src/mbgl/map/transform.cpp
index 06cde18c6e..69a644c7d9 100644
--- a/src/mbgl/map/transform.cpp
+++ b/src/mbgl/map/transform.cpp
@@ -343,8 +343,6 @@ void Transform::flyTo(const CameraOptions &camera, const AnimationOptions &anima
#pragma mark - Position
void Transform::moveBy(const ScreenCoordinate& offset, const Duration& duration) {
- if (!offset) return;
-
ScreenCoordinate centerOffset = {
offset.x,
-offset.y,
@@ -477,10 +475,6 @@ void Transform::setMaxZoom(const double maxZoom) {
#pragma mark - Angle
void Transform::rotateBy(const ScreenCoordinate& first, const ScreenCoordinate& second, const Duration& duration) {
- if (!first || !second) {
- return;
- }
-
ScreenCoordinate center = getScreenCoordinate();
const ScreenCoordinate offset = first - center;
const double distance = std::sqrt(std::pow(2, offset.x) + std::pow(2, offset.y));
@@ -493,13 +487,9 @@ void Transform::rotateBy(const ScreenCoordinate& first, const ScreenCoordinate&
center.x = first.x + std::cos(rotateAngle) * heightOffset;
center.y = first.y + std::sin(rotateAngle) * heightOffset;
}
-
- const ScreenCoordinate newFirst = first - center;
- const ScreenCoordinate newSecond = second - center;
- const double ang = state.angle + util::angle_between(newFirst.x, newFirst.y, newSecond.x, newSecond.y);
CameraOptions camera;
- camera.angle = ang;
+ camera.angle = state.angle + util::angle_between(first - center, second - center);
easeTo(camera, duration);
}
@@ -581,7 +571,7 @@ void Transform::startTransition(const CameraOptions& camera,
// Associate the anchor, if given, with a coordinate.
optional<ScreenCoordinate> anchor = camera.anchor;
LatLng anchorLatLng;
- if (anchor && *anchor) {
+ if (anchor) {
anchor->y = state.getHeight() - anchor->y;
anchorLatLng = state.screenCoordinateToLatLng(*anchor);
}
@@ -599,7 +589,7 @@ void Transform::startTransition(const CameraOptions& camera,
result = frame(ease.solve(t, 0.001));
}
- if (anchor && *anchor) state.moveLatLng(anchorLatLng, *anchor);
+ if (anchor) state.moveLatLng(anchorLatLng, *anchor);
// At t = 1.0, a DidChangeAnimated notification should be sent from finish().
if (t < 1.0) {
@@ -657,8 +647,6 @@ void Transform::setGestureInProgress(bool inProgress) {
#pragma mark Conversion and projection
ScreenCoordinate Transform::latLngToScreenCoordinate(const LatLng& latLng) const {
- if (!latLng) return ScreenCoordinate::null();
-
// If the center and point longitudes are not in the same side of the
// antimeridian, we unwrap the point longitude so it would be seen if
// e.g. the next antimeridian side is visible.
@@ -670,8 +658,6 @@ ScreenCoordinate Transform::latLngToScreenCoordinate(const LatLng& latLng) const
}
LatLng Transform::screenCoordinateToLatLng(const ScreenCoordinate& point) const {
- if (!point) return LatLng::null();
-
ScreenCoordinate flippedPoint = point;
flippedPoint.y = state.height - flippedPoint.y;
return state.screenCoordinateToLatLng(flippedPoint).wrapped();
diff --git a/src/mbgl/map/transform_state.cpp b/src/mbgl/map/transform_state.cpp
index cac80ff0bc..4c96abcd13 100644
--- a/src/mbgl/map/transform_state.cpp
+++ b/src/mbgl/map/transform_state.cpp
@@ -223,10 +223,10 @@ double TransformState::worldSize() const {
ScreenCoordinate TransformState::latLngToScreenCoordinate(const LatLng& latLng) const {
mat4 mat = coordinatePointMatrix(getZoom());
- vec4<double> p;
- vec4<double> c = { lngX(latLng.longitude) / util::tileSize, latY(latLng.latitude) / util::tileSize, 0, 1 };
+ vec4 p;
+ vec4 c = {{ lngX(latLng.longitude) / util::tileSize, latY(latLng.latitude) / util::tileSize, 0, 1 }};
matrix::transformMat4(p, c, mat);
- return { p.x / p.w, height - p.y / p.w };
+ return { p[0] / p[3], height - p[1] / p[3] };
}
LatLng TransformState::screenCoordinateToLatLng(const ScreenCoordinate& point, LatLng::WrapMode wrapMode) const {
@@ -244,21 +244,21 @@ LatLng TransformState::screenCoordinateToLatLng(const ScreenCoordinate& point, L
// unproject two points to get a line and then find the point on that
// line with z=0
- vec4<double> coord0;
- vec4<double> coord1;
- vec4<double> point0 = { point.x, flippedY, 0, 1 };
- vec4<double> point1 = { point.x, flippedY, 1, 1 };
+ vec4 coord0;
+ vec4 coord1;
+ vec4 point0 = {{ point.x, flippedY, 0, 1 }};
+ vec4 point1 = {{ point.x, flippedY, 1, 1 }};
matrix::transformMat4(coord0, point0, inverted);
matrix::transformMat4(coord1, point1, inverted);
- double w0 = coord0.w;
- double w1 = coord1.w;
- double x0 = coord0.x / w0;
- double x1 = coord1.x / w1;
- double y0 = coord0.y / w0;
- double y1 = coord1.y / w1;
- double z0 = coord0.z / w0;
- double z1 = coord1.z / w1;
+ double w0 = coord0[3];
+ double w1 = coord1[3];
+ double x0 = coord0[0] / w0;
+ double x1 = coord1[0] / w1;
+ double y0 = coord0[1] / w0;
+ double y1 = coord1[1] / w1;
+ double z0 = coord0[2] / w0;
+ double z1 = coord1[2] / w1;
double t = z0 == z1 ? 0 : (targetZ - z0) / (z1 - z0);
return {
@@ -312,13 +312,11 @@ void TransformState::constrain(double& scale_, double& x_, double& y_) const {
}
void TransformState::moveLatLng(const LatLng& latLng, const ScreenCoordinate& anchor) {
- if (!latLng || !anchor) return;
-
- auto latLngToTileCoord = [&](const LatLng& ll) -> vec2<double> {
+ auto latLngToTileCoord = [&](const LatLng& ll) -> Point<double> {
return { lngX(ll.longitude), latY(ll.latitude) };
};
- auto tileCoordToLatLng = [&](const vec2<double> coord) -> LatLng {
+ auto tileCoordToLatLng = [&](const Point<double> coord) -> LatLng {
return { yLat(coord.y, worldSize()), xLng(coord.x, worldSize()) };
};
diff --git a/src/mbgl/map/transform_state.hpp b/src/mbgl/map/transform_state.hpp
index ef3a5dfefd..37b52f9606 100644
--- a/src/mbgl/map/transform_state.hpp
+++ b/src/mbgl/map/transform_state.hpp
@@ -4,7 +4,6 @@
#include <mbgl/map/mode.hpp>
#include <mbgl/util/geo.hpp>
#include <mbgl/util/constants.hpp>
-#include <mbgl/util/vec.hpp>
#include <mbgl/util/mat4.hpp>
#include <cstdint>
diff --git a/src/mbgl/renderer/line_bucket.cpp b/src/mbgl/renderer/line_bucket.cpp
index 0819524b96..fdbb291457 100644
--- a/src/mbgl/renderer/line_bucket.cpp
+++ b/src/mbgl/renderer/line_bucket.cpp
@@ -85,16 +85,18 @@ void LineBucket::addGeometry(const GeometryCoordinates& vertices) {
double distance = 0;
bool startOfLine = true;
- GeometryCoordinate currentVertex = GeometryCoordinate::null(), prevVertex = GeometryCoordinate::null(),
- nextVertex = GeometryCoordinate::null();
- vec2<double> prevNormal = vec2<double>::null(), nextNormal = vec2<double>::null();
+ optional<GeometryCoordinate> currentVertex;
+ optional<GeometryCoordinate> prevVertex;
+ optional<GeometryCoordinate> nextVertex;
+ optional<Point<double>> prevNormal;
+ optional<Point<double>> nextNormal;
// the last three vertices added
e1 = e2 = e3 = -1;
if (closed) {
currentVertex = vertices[len - 2];
- nextNormal = util::perp(util::unit(vec2<double>(firstVertex - currentVertex)));
+ nextNormal = util::perp(util::unit(convertPoint<double>(firstVertex - *currentVertex)));
}
const GLint startVertex = vertexBuffer.index();
@@ -109,19 +111,19 @@ void LineBucket::addGeometry(const GeometryCoordinates& vertices) {
nextVertex = vertices[i + 1];
} else {
// there is no next vertex
- nextVertex = GeometryCoordinate::null();
+ nextVertex = {};
}
// if two consecutive vertices exist, skip the current one
- if (nextVertex && vertices[i] == nextVertex) {
+ if (nextVertex && vertices[i] == *nextVertex) {
continue;
}
if (nextNormal) {
- prevNormal = nextNormal;
+ prevNormal = *nextNormal;
}
if (currentVertex) {
- prevVertex = currentVertex;
+ prevVertex = *currentVertex;
}
currentVertex = vertices[i];
@@ -129,18 +131,18 @@ void LineBucket::addGeometry(const GeometryCoordinates& vertices) {
// Calculate the normal towards the next vertex in this line. In case
// there is no next vertex, pretend that the line is continuing straight,
// meaning that we are just using the previous normal.
- nextNormal = nextVertex ? util::perp(util::unit(vec2<double>(nextVertex - currentVertex)))
+ nextNormal = nextVertex ? util::perp(util::unit(convertPoint<double>(*nextVertex - *currentVertex)))
: prevNormal;
// If we still don't have a previous normal, this is the beginning of a
// non-closed line, so we're doing a straight "join".
if (!prevNormal) {
- prevNormal = nextNormal;
+ prevNormal = *nextNormal;
}
// Determine the normal of the join extrusion. It is the angle bisector
// of the segments between the previous line and the next line.
- vec2<double> joinNormal = util::unit(prevNormal + nextNormal);
+ Point<double> joinNormal = util::unit(*prevNormal + *nextNormal);
/* joinNormal prevNormal
* ↖ ↑
@@ -155,17 +157,17 @@ void LineBucket::addGeometry(const GeometryCoordinates& vertices) {
// Calculate the length of the miter (the ratio of the miter to the width).
// Find the cosine of the angle between the next and join normals
// using dot product. The inverse of that is the miter length.
- const float cosHalfAngle = joinNormal.x * nextNormal.x + joinNormal.y * nextNormal.y;
- const float miterLength = cosHalfAngle != 0 ? 1 / cosHalfAngle: 1;
+ const double cosHalfAngle = joinNormal.x * nextNormal->x + joinNormal.y * nextNormal->y;
+ const double miterLength = cosHalfAngle != 0 ? 1 / cosHalfAngle: 1;
const bool isSharpCorner = cosHalfAngle < COS_HALF_SHARP_CORNER && prevVertex && nextVertex;
if (isSharpCorner && i > 0) {
- const double prevSegmentLength = util::dist<double>(currentVertex, prevVertex);
+ const double prevSegmentLength = util::dist<double>(*currentVertex, *prevVertex);
if (prevSegmentLength > 2.0 * sharpCornerOffset) {
- GeometryCoordinate newPrevVertex = currentVertex - (util::round(vec2<double>(currentVertex - prevVertex) * (sharpCornerOffset / prevSegmentLength)));
- distance += util::dist<double>(newPrevVertex, prevVertex);
- addCurrentVertex(newPrevVertex, distance, prevNormal, 0, 0, false, startVertex, triangleStore);
+ GeometryCoordinate newPrevVertex = *currentVertex - convertPoint<int16_t>(util::round(convertPoint<double>(*currentVertex - *prevVertex) * (sharpCornerOffset / prevSegmentLength)));
+ distance += util::dist<double>(newPrevVertex, *prevVertex);
+ addCurrentVertex(newPrevVertex, distance, *prevNormal, 0, 0, false, startVertex, triangleStore);
prevVertex = newPrevVertex;
}
}
@@ -205,11 +207,11 @@ void LineBucket::addGeometry(const GeometryCoordinates& vertices) {
// Calculate how far along the line the currentVertex is
if (prevVertex)
- distance += util::dist<double>(currentVertex, prevVertex);
+ distance += util::dist<double>(*currentVertex, *prevVertex);
if (middleVertex && currentJoin == LineJoinType::Miter) {
joinNormal = joinNormal * miterLength;
- addCurrentVertex(currentVertex, distance, joinNormal, 0, 0, false, startVertex,
+ addCurrentVertex(*currentVertex, distance, joinNormal, 0, 0, false, startVertex,
triangleStore);
} else if (middleVertex && currentJoin == LineJoinType::FlipBevel) {
@@ -217,21 +219,21 @@ void LineBucket::addGeometry(const GeometryCoordinates& vertices) {
if (miterLength > 100) {
// Almost parallel lines
- joinNormal = nextNormal;
+ joinNormal = *nextNormal;
} else {
- const float direction = prevNormal.x * nextNormal.y - prevNormal.y * nextNormal.x > 0 ? -1 : 1;
- const float bevelLength = miterLength * util::mag(prevNormal + nextNormal) /
- util::mag(prevNormal - nextNormal);
+ const double direction = prevNormal->x * nextNormal->y - prevNormal->y * nextNormal->x > 0 ? -1 : 1;
+ const double bevelLength = miterLength * util::mag(*prevNormal + *nextNormal) /
+ util::mag(*prevNormal - *nextNormal);
joinNormal = util::perp(joinNormal) * bevelLength * direction;
}
- addCurrentVertex(currentVertex, distance, joinNormal, 0, 0, false, startVertex,
+ addCurrentVertex(*currentVertex, distance, joinNormal, 0, 0, false, startVertex,
triangleStore);
- addCurrentVertex(currentVertex, distance, joinNormal * -1.0, 0, 0, false, startVertex,
+ addCurrentVertex(*currentVertex, distance, joinNormal * -1.0, 0, 0, false, startVertex,
triangleStore);
} else if (middleVertex && (currentJoin == LineJoinType::Bevel || currentJoin == LineJoinType::FakeRound)) {
- const bool lineTurnsLeft = (prevNormal.x * nextNormal.y - prevNormal.y * nextNormal.x) > 0;
+ const bool lineTurnsLeft = (prevNormal->x * nextNormal->y - prevNormal->y * nextNormal->x) > 0;
const float offset = -std::sqrt(miterLength * miterLength - 1);
float offsetA;
float offsetB;
@@ -246,7 +248,7 @@ void LineBucket::addGeometry(const GeometryCoordinates& vertices) {
// Close previous segement with bevel
if (!startOfLine) {
- addCurrentVertex(currentVertex, distance, prevNormal, offsetA, offsetB, false,
+ addCurrentVertex(*currentVertex, distance, *prevNormal, offsetA, offsetB, false,
startVertex, triangleStore);
}
@@ -261,41 +263,41 @@ void LineBucket::addGeometry(const GeometryCoordinates& vertices) {
const int n = std::floor((0.5 - (cosHalfAngle - 0.5)) * 8);
for (int m = 0; m < n; m++) {
- auto approxFractionalJoinNormal = util::unit(nextNormal * ((m + 1.0f) / (n + 1.0f)) + prevNormal);
- addPieSliceVertex(currentVertex, distance, approxFractionalJoinNormal, lineTurnsLeft, startVertex, triangleStore);
+ auto approxFractionalJoinNormal = util::unit(*nextNormal * ((m + 1.0) / (n + 1.0)) + *prevNormal);
+ addPieSliceVertex(*currentVertex, distance, approxFractionalJoinNormal, lineTurnsLeft, startVertex, triangleStore);
}
- addPieSliceVertex(currentVertex, distance, joinNormal, lineTurnsLeft, startVertex, triangleStore);
+ addPieSliceVertex(*currentVertex, distance, joinNormal, lineTurnsLeft, startVertex, triangleStore);
for (int k = n - 1; k >= 0; k--) {
- auto approxFractionalJoinNormal = util::unit(prevNormal * ((k + 1.0f) / (n + 1.0f)) + nextNormal);
- addPieSliceVertex(currentVertex, distance, approxFractionalJoinNormal, lineTurnsLeft, startVertex, triangleStore);
+ auto approxFractionalJoinNormal = util::unit(*prevNormal * ((k + 1.0) / (n + 1.0)) + *nextNormal);
+ addPieSliceVertex(*currentVertex, distance, approxFractionalJoinNormal, lineTurnsLeft, startVertex, triangleStore);
}
}
// Start next segment
if (nextVertex) {
- addCurrentVertex(currentVertex, distance, nextNormal, -offsetA, -offsetB,
+ addCurrentVertex(*currentVertex, distance, *nextNormal, -offsetA, -offsetB,
false, startVertex, triangleStore);
}
} else if (!middleVertex && currentCap == LineCapType::Butt) {
if (!startOfLine) {
// Close previous segment with a butt
- addCurrentVertex(currentVertex, distance, prevNormal, 0, 0, false,
+ addCurrentVertex(*currentVertex, distance, *prevNormal, 0, 0, false,
startVertex, triangleStore);
}
// Start next segment with a butt
if (nextVertex) {
- addCurrentVertex(currentVertex, distance, nextNormal, 0, 0, false,
+ addCurrentVertex(*currentVertex, distance, *nextNormal, 0, 0, false,
startVertex, triangleStore);
}
} else if (!middleVertex && currentCap == LineCapType::Square) {
if (!startOfLine) {
// Close previous segment with a square cap
- addCurrentVertex(currentVertex, distance, prevNormal, 1, 1, false,
+ addCurrentVertex(*currentVertex, distance, *prevNormal, 1, 1, false,
startVertex, triangleStore);
// The segment is done. Unset vertices to disconnect segments.
@@ -304,18 +306,18 @@ void LineBucket::addGeometry(const GeometryCoordinates& vertices) {
// Start next segment
if (nextVertex) {
- addCurrentVertex(currentVertex, distance, nextNormal, -1, -1, false,
+ addCurrentVertex(*currentVertex, distance, *nextNormal, -1, -1, false,
startVertex, triangleStore);
}
} else if (middleVertex ? currentJoin == LineJoinType::Round : currentCap == LineCapType::Round) {
if (!startOfLine) {
// Close previous segment with a butt
- addCurrentVertex(currentVertex, distance, prevNormal, 0, 0, false,
+ addCurrentVertex(*currentVertex, distance, *prevNormal, 0, 0, false,
startVertex, triangleStore);
// Add round cap or linejoin at end of segment
- addCurrentVertex(currentVertex, distance, prevNormal, 1, 1, true, startVertex,
+ addCurrentVertex(*currentVertex, distance, *prevNormal, 1, 1, true, startVertex,
triangleStore);
// The segment is done. Unset vertices to disconnect segments.
@@ -325,20 +327,20 @@ void LineBucket::addGeometry(const GeometryCoordinates& vertices) {
// Start next segment with a butt
if (nextVertex) {
// Add round cap before first segment
- addCurrentVertex(currentVertex, distance, nextNormal, -1, -1, true,
+ addCurrentVertex(*currentVertex, distance, *nextNormal, -1, -1, true,
startVertex, triangleStore);
- addCurrentVertex(currentVertex, distance, nextNormal, 0, 0, false,
+ addCurrentVertex(*currentVertex, distance, *nextNormal, 0, 0, false,
startVertex, triangleStore);
}
}
if (isSharpCorner && i < len - 1) {
- const double nextSegmentLength = util::dist<double>(currentVertex, nextVertex);
+ const double nextSegmentLength = util::dist<double>(*currentVertex, *nextVertex);
if (nextSegmentLength > 2 * sharpCornerOffset) {
- GeometryCoordinate newCurrentVertex = currentVertex + util::round(vec2<double>(nextVertex - currentVertex) * (sharpCornerOffset / nextSegmentLength));
- distance += util::dist<double>(newCurrentVertex, currentVertex);
- addCurrentVertex(newCurrentVertex, distance, nextNormal, 0, 0, false, startVertex, triangleStore);
+ GeometryCoordinate newCurrentVertex = *currentVertex + convertPoint<int16_t>(util::round(convertPoint<double>(*nextVertex - *currentVertex) * (sharpCornerOffset / nextSegmentLength)));
+ distance += util::dist<double>(newCurrentVertex, *currentVertex);
+ addCurrentVertex(newCurrentVertex, distance, *nextNormal, 0, 0, false, startVertex, triangleStore);
currentVertex = newCurrentVertex;
}
}
@@ -371,15 +373,15 @@ void LineBucket::addGeometry(const GeometryCoordinates& vertices) {
void LineBucket::addCurrentVertex(const GeometryCoordinate& currentVertex,
double &distance,
- const vec2<double>& normal,
- float endLeft,
- float endRight,
+ const Point<double>& normal,
+ double endLeft,
+ double endRight,
bool round,
GLint startVertex,
std::vector<TriangleElement>& triangleStore) {
int8_t tx = round ? 1 : 0;
- vec2<double> extrude = normal;
+ Point<double> extrude = normal;
if (endLeft)
extrude = extrude - (util::perp(normal) * endLeft);
e3 = vertexBuffer.add(currentVertex.x, currentVertex.y, extrude.x, extrude.y, tx, 0, endLeft, distance * LINE_DISTANCE_SCALE)
@@ -413,13 +415,13 @@ void LineBucket::addCurrentVertex(const GeometryCoordinate& currentVertex,
void LineBucket::addPieSliceVertex(const GeometryCoordinate& currentVertex,
double distance,
- const vec2<double>& extrude,
+ const Point<double>& extrude,
bool lineTurnsLeft,
GLint startVertex,
std::vector<TriangleElement>& triangleStore) {
int8_t ty = lineTurnsLeft;
- auto flippedExtrude = extrude * (lineTurnsLeft ? -1 : 1);
+ Point<double> flippedExtrude = extrude * (lineTurnsLeft ? -1.0 : 1.0);
e3 = vertexBuffer.add(currentVertex.x, currentVertex.y, flippedExtrude.x, flippedExtrude.y, 0, ty, 0, distance * LINE_DISTANCE_SCALE)
- startVertex;
if (e1 >= 0 && e2 >= 0) {
diff --git a/src/mbgl/renderer/line_bucket.hpp b/src/mbgl/renderer/line_bucket.hpp
index d6dd1b5567..9c7ec3d93e 100644
--- a/src/mbgl/renderer/line_bucket.hpp
+++ b/src/mbgl/renderer/line_bucket.hpp
@@ -6,7 +6,6 @@
#include <mbgl/geometry/vao.hpp>
#include <mbgl/geometry/elements_buffer.hpp>
#include <mbgl/geometry/line_buffer.hpp>
-#include <mbgl/util/vec.hpp>
#include <mbgl/layer/line_layer.hpp>
#include <vector>
@@ -45,10 +44,10 @@ private:
uint16_t a, b, c;
};
void addCurrentVertex(const GeometryCoordinate& currentVertex, double& distance,
- const vec2<double>& normal, float endLeft, float endRight, bool round,
+ const Point<double>& normal, double endLeft, double endRight, bool round,
GLint startVertex, std::vector<LineBucket::TriangleElement>& triangleStore);
void addPieSliceVertex(const GeometryCoordinate& currentVertex, double distance,
- const vec2<double>& extrude, bool lineTurnsLeft, GLint startVertex,
+ const Point<double>& extrude, bool lineTurnsLeft, GLint startVertex,
std::vector<TriangleElement>& triangleStore);
public:
diff --git a/src/mbgl/renderer/symbol_bucket.cpp b/src/mbgl/renderer/symbol_bucket.cpp
index 55138363fe..b0930890d4 100644
--- a/src/mbgl/renderer/symbol_bucket.cpp
+++ b/src/mbgl/renderer/symbol_bucket.cpp
@@ -38,8 +38,7 @@ SymbolInstance::SymbolInstance(Anchor& anchor, const GeometryCoordinates& line,
const float textBoxScale, const float textPadding, const float textAlongLine,
const float iconBoxScale, const float iconPadding, const float iconAlongLine,
const GlyphPositions& face, const IndexedSubfeature& indexedFeature) :
- x(anchor.x),
- y(anchor.y),
+ point(anchor.point),
index(index_),
hasText(shapedText),
hasIcon(shapedIcon),
@@ -265,7 +264,7 @@ void SymbolBucket::addFeatures(uintptr_t tileUID,
/* verticalAlign */ verticalAlign,
/* justify */ justify,
/* spacing: ems */ layout.textLetterSpacing * 24,
- /* translate */ vec2<float>(layout.textOffset.value[0], layout.textOffset.value[1]));
+ /* translate */ Point<float>(layout.textOffset.value[0], layout.textOffset.value[1]));
// Add the glyphs we need for this label to the glyph atlas.
if (shapedText) {
@@ -346,7 +345,7 @@ void SymbolBucket::addFeature(const GeometryCollection &lines,
}
}
- const bool inside = !(anchor.x < 0 || anchor.x > util::EXTENT || anchor.y < 0 || anchor.y > util::EXTENT);
+ const bool inside = !(anchor.point.x < 0 || anchor.point.x > util::EXTENT || anchor.point.y < 0 || anchor.point.y > util::EXTENT);
if (avoidEdges && !inside) continue;
@@ -377,7 +376,7 @@ bool SymbolBucket::anchorIsTooClose(const std::u32string &text, const float repe
} else {
auto otherAnchors = compareText.find(text)->second;
for (Anchor &otherAnchor : otherAnchors) {
- if (util::dist<float>(anchor, otherAnchor) < repeatDistance) {
+ if (util::dist<float>(anchor.point, otherAnchor.point) < repeatDistance) {
return true;
}
}
@@ -412,8 +411,8 @@ void SymbolBucket::placeFeatures(CollisionTile& collisionTile) {
const float cos = std::cos(collisionTile.config.angle);
std::sort(symbolInstances.begin(), symbolInstances.end(), [sin, cos](SymbolInstance &a, SymbolInstance &b) {
- const int32_t aRotated = sin * a.x + cos * a.y;
- const int32_t bRotated = sin * b.x + cos * b.y;
+ const int32_t aRotated = sin * a.point.x + cos * a.point.y;
+ const int32_t bRotated = sin * b.point.x + cos * b.point.y;
return aRotated != bRotated ?
aRotated < bRotated :
a.index > b.index;
@@ -557,14 +556,14 @@ void SymbolBucket::addToDebugBuffers(CollisionTile &collisionTile) {
for (const CollisionBox &box : feature.boxes) {
auto& anchor = box.anchor;
- vec2<float> tl{box.x1, box.y1 * yStretch};
- vec2<float> tr{box.x2, box.y1 * yStretch};
- vec2<float> bl{box.x1, box.y2 * yStretch};
- vec2<float> br{box.x2, box.y2 * yStretch};
- tl = tl.matMul(matrix);
- tr = tr.matMul(matrix);
- bl = bl.matMul(matrix);
- br = br.matMul(matrix);
+ Point<float> tl{box.x1, box.y1 * yStretch};
+ Point<float> tr{box.x2, box.y1 * yStretch};
+ Point<float> bl{box.x1, box.y2 * yStretch};
+ Point<float> br{box.x2, box.y2 * yStretch};
+ tl = util::matrixMultiply(matrix, tl);
+ tr = util::matrixMultiply(matrix, tr);
+ bl = util::matrixMultiply(matrix, bl);
+ br = util::matrixMultiply(matrix, br);
const float maxZoom = util::max(0.0f, util::min(25.0f, static_cast<float>(zoom + log(box.maxScale) / log(2))));
const float placementZoom= util::max(0.0f, util::min(25.0f, static_cast<float>(zoom + log(box.placementScale) / log(2))));
diff --git a/src/mbgl/renderer/symbol_bucket.hpp b/src/mbgl/renderer/symbol_bucket.hpp
index 709f9fc65a..e212f56162 100644
--- a/src/mbgl/renderer/symbol_bucket.hpp
+++ b/src/mbgl/renderer/symbol_bucket.hpp
@@ -52,8 +52,7 @@ class SymbolInstance {
const float textBoxScale, const float textPadding, const float textAlongLine,
const float iconBoxScale, const float iconPadding, const float iconAlongLine,
const GlyphPositions& face, const IndexedSubfeature& indexedfeature);
- float x;
- float y;
+ Point<float> point;
uint32_t index;
bool hasText;
bool hasIcon;
diff --git a/src/mbgl/source/source.cpp b/src/mbgl/source/source.cpp
index 4841767751..b2729593c6 100644
--- a/src/mbgl/source/source.cpp
+++ b/src/mbgl/source/source.cpp
@@ -479,7 +479,7 @@ void Source::updateTilePtrs() {
}
}
-vec2<int16_t> coordinateToTilePoint(const TileID& tileID, const TileCoordinate& coord) {
+static Point<int16_t> coordinateToTilePoint(const TileID& tileID, const TileCoordinate& coord) {
auto zoomedCoord = coord.zoomTo(tileID.sourceZ);
return {
int16_t(util::clamp<int64_t>((zoomedCoord.x - (tileID.x + tileID.w * std::pow(2, tileID.sourceZ))) * util::EXTENT,
diff --git a/src/mbgl/text/check_max_angle.cpp b/src/mbgl/text/check_max_angle.cpp
index 4777f66a23..3ef13a0dd7 100644
--- a/src/mbgl/text/check_max_angle.cpp
+++ b/src/mbgl/text/check_max_angle.cpp
@@ -19,7 +19,7 @@ bool checkMaxAngle(const GeometryCoordinates &line, Anchor &anchor, const float
// horizontal labels always pass
if (anchor.segment < 0) return true;
- GeometryCoordinate anchorPoint = { (int16_t)anchor.x, (int16_t)anchor.y };
+ GeometryCoordinate anchorPoint = convertPoint<int16_t>(anchor.point);
GeometryCoordinate &p = anchorPoint;
int index = anchor.segment + 1;
float anchorDistance = 0;
diff --git a/src/mbgl/text/collision_feature.cpp b/src/mbgl/text/collision_feature.cpp
index 09c04ede78..8f0f099670 100644
--- a/src/mbgl/text/collision_feature.cpp
+++ b/src/mbgl/text/collision_feature.cpp
@@ -17,17 +17,17 @@ CollisionFeature::CollisionFeature(const GeometryCoordinates &line, const Anchor
if (alongLine) {
float height = y2 - y1;
- const float length = x2 - x1;
+ const double length = x2 - x1;
if (height <= 0.0f) return;
height = std::max(10.0f * boxScale, height);
- GeometryCoordinate anchorPoint(int16_t(anchor.x), int16_t(anchor.y));
+ GeometryCoordinate anchorPoint = convertPoint<int16_t>(anchor.point);
if (straight) {
// used for icon labels that are aligned with the line, but don't curve along it
- const vec2<double> vector = util::unit(vec2<double>(line[anchor.segment + 1] - line[anchor.segment])) * length;
+ const GeometryCoordinate vector = convertPoint<int16_t>(util::unit(convertPoint<double>(line[anchor.segment + 1] - line[anchor.segment])) * length);
const GeometryCoordinates newLine({ anchorPoint - vector, anchorPoint + vector });
bboxifyLabel(newLine, anchorPoint, 0, length, height, indexedFeature);
} else {
@@ -35,7 +35,7 @@ CollisionFeature::CollisionFeature(const GeometryCoordinates &line, const Anchor
bboxifyLabel(line, anchorPoint, anchor.segment, length, height, indexedFeature);
}
} else {
- boxes.emplace_back(anchor, x1, y1, x2, y2, std::numeric_limits<float>::infinity(), indexedFeature);
+ boxes.emplace_back(anchor.point, x1, y1, x2, y2, std::numeric_limits<float>::infinity(), indexedFeature);
}
}
@@ -89,7 +89,7 @@ void CollisionFeature::bboxifyLabel(const GeometryCoordinates &line,
const auto& p0 = line[index];
const auto& p1 = line[index + 1];
- vec2<float> boxAnchor = {
+ Point<float> boxAnchor = {
p0.x + segmentBoxDistance / segmentLength * (p1.x - p0.x),
p0.y + segmentBoxDistance / segmentLength * (p1.y - p0.y)
};
diff --git a/src/mbgl/text/collision_feature.hpp b/src/mbgl/text/collision_feature.hpp
index 0cd0b5554c..0fe248a3de 100644
--- a/src/mbgl/text/collision_feature.hpp
+++ b/src/mbgl/text/collision_feature.hpp
@@ -1,7 +1,6 @@
#ifndef MBGL_TEXT_COLLISION_FEATURE
#define MBGL_TEXT_COLLISION_FEATURE
-#include <mbgl/util/vec.hpp>
#include <mbgl/geometry/anchor.hpp>
#include <mbgl/text/shaping.hpp>
#include <mbgl/tile/geometry_tile.hpp>
@@ -12,12 +11,12 @@
namespace mbgl {
class CollisionBox {
public:
- explicit CollisionBox(const vec2<float> &_anchor, float _x1, float _y1, float _x2, float _y2, float _maxScale,
+ explicit CollisionBox(const Point<float> &_anchor, float _x1, float _y1, float _x2, float _y2, float _maxScale,
const IndexedSubfeature& indexedFeature_ = { 0, "", "", 0 }) :
anchor(_anchor), x1(_x1), y1(_y1), x2(_x2), y2(_y2), maxScale(_maxScale), indexedFeature(indexedFeature_) {}
// the box is centered around the anchor point
- vec2<float> anchor;
+ Point<float> anchor;
// distances to the edges from the anchor
float x1;
diff --git a/src/mbgl/text/collision_tile.cpp b/src/mbgl/text/collision_tile.cpp
index 6b9240df1f..ef7e9ab850 100644
--- a/src/mbgl/text/collision_tile.cpp
+++ b/src/mbgl/text/collision_tile.cpp
@@ -1,6 +1,8 @@
#include <mbgl/text/collision_tile.hpp>
#include <mbgl/geometry/feature_index.hpp>
#include <mbgl/util/constants.hpp>
+#include <mbgl/util/math.hpp>
+
#include <cmath>
namespace mbgl {
@@ -10,13 +12,13 @@ auto infinity = std::numeric_limits<float>::infinity();
CollisionTile::CollisionTile(PlacementConfig config_) : config(config_),
edges({{
// left
- CollisionBox(vec2<float>(0, 0), 0, -infinity, 0, infinity, infinity),
+ CollisionBox(Point<float>(0, 0), 0, -infinity, 0, infinity, infinity),
// right
- CollisionBox(vec2<float>(util::EXTENT, 0), 0, -infinity, 0, infinity, infinity),
+ CollisionBox(Point<float>(util::EXTENT, 0), 0, -infinity, 0, infinity, infinity),
// top
- CollisionBox(vec2<float>(0, 0), -infinity, 0, infinity, 0, infinity),
+ CollisionBox(Point<float>(0, 0), -infinity, 0, infinity, 0, infinity),
// bottom
- CollisionBox(vec2<float>(0, util::EXTENT), -infinity, 0, infinity, 0, infinity),
+ CollisionBox(Point<float>(0, util::EXTENT), -infinity, 0, infinity, 0, infinity),
}}) {
tree.clear();
@@ -35,8 +37,8 @@ CollisionTile::CollisionTile(PlacementConfig config_) : config(config_),
}
-float CollisionTile::findPlacementScale(float minPlacementScale, const vec2<float>& anchor,
- const CollisionBox& box, const vec2<float>& blockingAnchor, const CollisionBox& blocking) {
+float CollisionTile::findPlacementScale(float minPlacementScale, const Point<float>& anchor,
+ const CollisionBox& box, const Point<float>& blockingAnchor, const CollisionBox& blocking) {
// Find the lowest scale at which the two boxes can fit side by side without overlapping.
@@ -80,7 +82,7 @@ float CollisionTile::placeFeature(const CollisionFeature &feature, const bool al
float minPlacementScale = minScale;
for (auto& box : feature.boxes) {
- const auto anchor = box.anchor.matMul(rotationMatrix);
+ const auto anchor = util::matrixMultiply(rotationMatrix, box.anchor);
if (!allowOverlap) {
std::vector<CollisionTreeBox> blockingBoxes;
@@ -88,7 +90,7 @@ float CollisionTile::placeFeature(const CollisionFeature &feature, const bool al
for (auto& blockingTreeBox : blockingBoxes) {
const auto& blocking = std::get<1>(blockingTreeBox);
- auto blockingAnchor = blocking.anchor.matMul(rotationMatrix);
+ auto blockingAnchor = util::matrixMultiply(rotationMatrix, blocking.anchor);
minPlacementScale = findPlacementScale(minPlacementScale, anchor, box, blockingAnchor, blocking);
if (minPlacementScale >= maxScale) return minPlacementScale;
@@ -96,14 +98,14 @@ float CollisionTile::placeFeature(const CollisionFeature &feature, const bool al
}
if (avoidEdges) {
- const vec2<float> tl = { box.x1, box.y1 };
- const vec2<float> tr = { box.x2, box.y1 };
- const vec2<float> bl = { box.x1, box.y2 };
- const vec2<float> br = { box.x2, box.y2 };
- const vec2<float> rtl = tl.matMul(reverseRotationMatrix);
- const vec2<float> rtr = tr.matMul(reverseRotationMatrix);
- const vec2<float> rbl = bl.matMul(reverseRotationMatrix);
- const vec2<float> rbr = br.matMul(reverseRotationMatrix);
+ const Point<float> tl = { box.x1, box.y1 };
+ const Point<float> tr = { box.x2, box.y1 };
+ const Point<float> bl = { box.x1, box.y2 };
+ const Point<float> br = { box.x2, box.y2 };
+ const Point<float> rtl = util::matrixMultiply(reverseRotationMatrix, tl);
+ const Point<float> rtr = util::matrixMultiply(reverseRotationMatrix, tr);
+ const Point<float> rbl = util::matrixMultiply(reverseRotationMatrix, bl);
+ const Point<float> rbr = util::matrixMultiply(reverseRotationMatrix, br);
CollisionBox rotatedBox(box.anchor,
::fmin(::fmin(rtl.x, rtr.x), ::fmin(rbl.x, rbr.x)),
::fmin(::fmin(rtl.y, rtr.y), ::fmin(rbl.y, rbr.y)),
@@ -130,7 +132,7 @@ void CollisionTile::insertFeature(CollisionFeature &feature, const float minPlac
if (minPlacementScale < maxScale) {
std::vector<CollisionTreeBox> treeBoxes;
for (auto& box : feature.boxes) {
- treeBoxes.emplace_back(getTreeBox(box.anchor.matMul(rotationMatrix), box), box);
+ treeBoxes.emplace_back(getTreeBox(util::matrixMultiply(rotationMatrix, box.anchor), box), box);
}
if (ignorePlacement) {
ignoredTree.insert(treeBoxes.begin(), treeBoxes.end());
@@ -141,7 +143,7 @@ void CollisionTile::insertFeature(CollisionFeature &feature, const float minPlac
}
-Box CollisionTile::getTreeBox(const vec2<float> &anchor, const CollisionBox &box, const float scale) {
+Box CollisionTile::getTreeBox(const Point<float> &anchor, const CollisionBox &box, const float scale) {
return Box{
CollisionPoint{
anchor.x + box.x1 / scale,
@@ -158,7 +160,7 @@ std::vector<IndexedSubfeature> CollisionTile::queryRenderedSymbols(const float m
std::vector<IndexedSubfeature> result;
- auto anchor = vec2<float>(minX, minY).matMul(rotationMatrix);
+ auto anchor = util::matrixMultiply(rotationMatrix, Point<float>(minX, minY));
CollisionBox queryBox(anchor, 0, 0, maxX - minX, maxY - minY, scale);
std::vector<CollisionTreeBox> blockingBoxes;
@@ -174,7 +176,7 @@ std::vector<IndexedSubfeature> CollisionTile::queryRenderedSymbols(const float m
auto& seenFeatures = sourceLayerFeatures[indexedFeature.sourceLayerName];
if (seenFeatures.find(indexedFeature.index) == seenFeatures.end()) {
- auto blockingAnchor = blocking.anchor.matMul(rotationMatrix);
+ auto blockingAnchor = util::matrixMultiply(rotationMatrix, blocking.anchor);
float minPlacementScale = findPlacementScale(minScale, anchor, queryBox, blockingAnchor, blocking);
if (minPlacementScale >= scale) {
seenFeatures.insert(indexedFeature.index);
diff --git a/src/mbgl/text/collision_tile.hpp b/src/mbgl/text/collision_tile.hpp
index 4bc25ddcb7..df769ac203 100644
--- a/src/mbgl/text/collision_tile.hpp
+++ b/src/mbgl/text/collision_tile.hpp
@@ -52,9 +52,9 @@ public:
private:
float findPlacementScale(float minPlacementScale,
- const vec2<float>& anchor, const CollisionBox& box,
- const vec2<float>& blockingAnchor, const CollisionBox& blocking);
- Box getTreeBox(const vec2<float>& anchor, const CollisionBox& box, const float scale = 1.0);
+ const Point<float>& anchor, const CollisionBox& box,
+ const Point<float>& blockingAnchor, const CollisionBox& blocking);
+ Box getTreeBox(const Point<float>& anchor, const CollisionBox& box, const float scale = 1.0);
Tree tree;
Tree ignoredTree;
diff --git a/src/mbgl/text/glyph_set.cpp b/src/mbgl/text/glyph_set.cpp
index f63c1eae7f..8bd7e4ae03 100644
--- a/src/mbgl/text/glyph_set.cpp
+++ b/src/mbgl/text/glyph_set.cpp
@@ -33,7 +33,7 @@ const std::map<uint32_t, SDFGlyph> &GlyphSet::getSDFs() const {
const Shaping GlyphSet::getShaping(const std::u32string &string, const float maxWidth,
const float lineHeight, const float horizontalAlign,
const float verticalAlign, const float justify,
- const float spacing, const vec2<float> &translate) const {
+ const float spacing, const Point<float> &translate) const {
Shaping shaping(translate.x * 24, translate.y * 24, string);
// the y offset *should* be part of the font metadata
@@ -61,7 +61,7 @@ const Shaping GlyphSet::getShaping(const std::u32string &string, const float max
void align(Shaping &shaping, const float justify, const float horizontalAlign,
const float verticalAlign, const uint32_t maxLineLength, const float lineHeight,
- const uint32_t line, const vec2<float> &translate) {
+ const uint32_t line, const Point<float> &translate) {
const float shiftX = (justify - horizontalAlign) * maxLineLength + ::round(translate.x * 24/* one em */);
const float shiftY = (-verticalAlign * (line + 1) + 0.5) * lineHeight + ::round(translate.y * 24/* one em */);
@@ -87,7 +87,7 @@ void justifyLine(std::vector<PositionedGlyph> &positionedGlyphs, const std::map<
void GlyphSet::lineWrap(Shaping &shaping, const float lineHeight, const float maxWidth,
const float horizontalAlign, const float verticalAlign,
- const float justify, const vec2<float> &translate) const {
+ const float justify, const Point<float> &translate) const {
uint32_t lastSafeBreak = 0;
uint32_t lengthBeforeCurrentLine = 0;
diff --git a/src/mbgl/text/glyph_set.hpp b/src/mbgl/text/glyph_set.hpp
index 5714071650..40f87835fd 100644
--- a/src/mbgl/text/glyph_set.hpp
+++ b/src/mbgl/text/glyph_set.hpp
@@ -2,7 +2,7 @@
#define MBGL_TEXT_GLYPH_SET
#include <mbgl/text/glyph.hpp>
-#include <mbgl/util/vec.hpp>
+#include <mbgl/util/geometry.hpp>
namespace mbgl {
@@ -12,9 +12,9 @@ public:
const std::map<uint32_t, SDFGlyph> &getSDFs() const;
const Shaping getShaping(const std::u32string &string, float maxWidth, float lineHeight,
float horizontalAlign, float verticalAlign, float justify,
- float spacing, const vec2<float> &translate) const;
+ float spacing, const Point<float> &translate) const;
void lineWrap(Shaping &shaping, float lineHeight, float maxWidth, float horizontalAlign,
- float verticalAlign, float justify, const vec2<float> &translate) const;
+ float verticalAlign, float justify, const Point<float> &translate) const;
private:
std::map<uint32_t, SDFGlyph> sdfs;
diff --git a/src/mbgl/text/quads.cpp b/src/mbgl/text/quads.cpp
index 2b5db023c0..f78d913e74 100644
--- a/src/mbgl/text/quads.cpp
+++ b/src/mbgl/text/quads.cpp
@@ -22,22 +22,22 @@ SymbolQuads getIconQuads(Anchor& anchor, const PositionedIcon& shapedIcon,
auto right = left + image.pos.w / image.relativePixelRatio;
auto top = shapedIcon.top - border;
auto bottom = top + image.pos.h / image.relativePixelRatio;
- vec2<float> tl{left, top};
- vec2<float> tr{right, top};
- vec2<float> br{right, bottom};
- vec2<float> bl{left, bottom};
+ Point<float> tl{left, top};
+ Point<float> tr{right, top};
+ Point<float> br{right, bottom};
+ Point<float> bl{left, bottom};
float angle = layout.iconRotate * util::DEG2RAD;
if (alongLine) {
assert(static_cast<unsigned int>(anchor.segment) < line.size());
const GeometryCoordinate &prev= line[anchor.segment];
- if (anchor.y == prev.y && anchor.x == prev.x &&
+ if (anchor.point.y == prev.y && anchor.point.x == prev.x &&
static_cast<unsigned int>(anchor.segment + 1) < line.size()) {
const GeometryCoordinate &next= line[anchor.segment + 1];
- angle += std::atan2(anchor.y - next.y, anchor.x - next.x) + M_PI;
+ angle += std::atan2(anchor.point.y - next.y, anchor.point.x - next.x) + M_PI;
} else {
- angle += std::atan2(anchor.y - prev.y, anchor.x - prev.x);
+ angle += std::atan2(anchor.point.y - prev.y, anchor.point.x - prev.x);
}
}
@@ -48,24 +48,24 @@ SymbolQuads getIconQuads(Anchor& anchor, const PositionedIcon& shapedIcon,
float angle_cos = std::cos(angle);
std::array<float, 4> matrix = {{angle_cos, -angle_sin, angle_sin, angle_cos}};
- tl = tl.matMul(matrix);
- tr = tr.matMul(matrix);
- bl = bl.matMul(matrix);
- br = br.matMul(matrix);
+ tl = util::matrixMultiply(matrix, tl);
+ tr = util::matrixMultiply(matrix, tr);
+ bl = util::matrixMultiply(matrix, bl);
+ br = util::matrixMultiply(matrix, br);
}
SymbolQuads quads;
- quads.emplace_back(tl, tr, bl, br, image.pos, 0, anchor, globalMinScale, std::numeric_limits<float>::infinity());
+ quads.emplace_back(tl, tr, bl, br, image.pos, 0, anchor.point, globalMinScale, std::numeric_limits<float>::infinity());
return quads;
}
struct GlyphInstance {
- explicit GlyphInstance(const vec2<float> &anchorPoint_) : anchorPoint(anchorPoint_) {}
- explicit GlyphInstance(const vec2<float> &anchorPoint_, float offset_, float minScale_, float maxScale_,
+ explicit GlyphInstance(const Point<float> &anchorPoint_) : anchorPoint(anchorPoint_) {}
+ explicit GlyphInstance(const Point<float> &anchorPoint_, float offset_, float minScale_, float maxScale_,
float angle_)
: anchorPoint(anchorPoint_), offset(offset_), minScale(minScale_), maxScale(maxScale_), angle(angle_) {}
- const vec2<float> anchorPoint;
+ const Point<float> anchorPoint;
const float offset = 0.0f;
const float minScale = globalMinScale;
const float maxScale = std::numeric_limits<float>::infinity();
@@ -86,8 +86,8 @@ void getSegmentGlyphs(std::back_insert_iterator<GlyphInstances> glyphs, Anchor &
segment++;
assert((int)line.size() > segment);
- vec2<float> end = line[segment];
- vec2<float> newAnchorPoint = anchor;
+ Point<float> end = convertPoint<float>(line[segment]);
+ Point<float> newAnchorPoint = anchor.point;
float prevscale = std::numeric_limits<float>::infinity();
offset = std::fabs(offset);
@@ -122,10 +122,10 @@ void getSegmentGlyphs(std::back_insert_iterator<GlyphInstances> glyphs, Anchor &
anchor.scale = scale;
return;
}
- end = line[segment];
+ end = convertPoint<float>(line[segment]);
}
- vec2<float> normal = util::normal<float>(newAnchorPoint, end) * dist;
+ Point<float> normal = util::normal<float>(newAnchorPoint, end) * dist;
newAnchorPoint = newAnchorPoint - normal;
prevscale = scale;
@@ -163,7 +163,7 @@ SymbolQuads getGlyphQuads(Anchor& anchor, const Shaping& shapedText,
getSegmentGlyphs(std::back_inserter(glyphInstances), anchor, centerX, line, anchor.segment, false);
} else {
- glyphInstances.emplace_back(GlyphInstance{anchor});
+ glyphInstances.emplace_back(GlyphInstance{anchor.point});
}
// The rects have an addditional buffer that is not included in their size;
@@ -175,17 +175,17 @@ SymbolQuads getGlyphQuads(Anchor& anchor, const Shaping& shapedText,
const float x2 = x1 + rect.w;
const float y2 = y1 + rect.h;
- const vec2<float> otl{x1, y1};
- const vec2<float> otr{x2, y1};
- const vec2<float> obl{x1, y2};
- const vec2<float> obr{x2, y2};
+ const Point<float> otl{x1, y1};
+ const Point<float> otr{x2, y1};
+ const Point<float> obl{x1, y2};
+ const Point<float> obr{x2, y2};
for (const GlyphInstance &instance : glyphInstances) {
- vec2<float> tl = otl;
- vec2<float> tr = otr;
- vec2<float> bl = obl;
- vec2<float> br = obr;
+ Point<float> tl = otl;
+ Point<float> tr = otr;
+ Point<float> bl = obl;
+ Point<float> br = obr;
const float angle = instance.angle + textRotate;
if (angle) {
@@ -194,10 +194,10 @@ SymbolQuads getGlyphQuads(Anchor& anchor, const Shaping& shapedText,
float angle_cos = std::cos(angle);
std::array<float, 4> matrix = {{angle_cos, -angle_sin, angle_sin, angle_cos}};
- tl = tl.matMul(matrix);
- tr = tr.matMul(matrix);
- bl = bl.matMul(matrix);
- br = br.matMul(matrix);
+ tl = util::matrixMultiply(matrix, tl);
+ tr = util::matrixMultiply(matrix, tr);
+ bl = util::matrixMultiply(matrix, bl);
+ br = util::matrixMultiply(matrix, br);
}
// Prevent label from extending past the end of the line
diff --git a/src/mbgl/text/quads.hpp b/src/mbgl/text/quads.hpp
index 12b8893503..03f86e1df9 100644
--- a/src/mbgl/text/quads.hpp
+++ b/src/mbgl/text/quads.hpp
@@ -3,16 +3,15 @@
#include <mbgl/text/glyph.hpp>
#include <mbgl/tile/geometry_tile.hpp>
-#include <mbgl/util/vec.hpp>
#include <vector>
namespace mbgl {
struct SymbolQuad {
- explicit SymbolQuad(const vec2<float> &tl_, const vec2<float> &tr_,
- const vec2<float> &bl_, const vec2<float> &br_,
- const Rect<uint16_t> &tex_, float angle_, const vec2<float> &anchorPoint_,
+ explicit SymbolQuad(const Point<float> &tl_, const Point<float> &tr_,
+ const Point<float> &bl_, const Point<float> &br_,
+ const Rect<uint16_t> &tex_, float angle_, const Point<float> &anchorPoint_,
float minScale_, float maxScale_)
: tl(tl_),
tr(tr_),
@@ -24,10 +23,10 @@ namespace mbgl {
minScale(minScale_),
maxScale(maxScale_) {}
- vec2<float> tl, tr, bl, br;
+ Point<float> tl, tr, bl, br;
Rect<uint16_t> tex;
float angle;
- vec2<float> anchorPoint;
+ Point<float> anchorPoint;
float minScale, maxScale;
};
diff --git a/src/mbgl/text/shaping.hpp b/src/mbgl/text/shaping.hpp
index 5fbb433035..89249ee605 100644
--- a/src/mbgl/text/shaping.hpp
+++ b/src/mbgl/text/shaping.hpp
@@ -4,8 +4,6 @@
#include <mbgl/text/glyph.hpp>
#include <mbgl/sprite/sprite_atlas.hpp>
#include <mbgl/sprite/sprite_image.hpp>
-
-#include <mbgl/util/vec.hpp>
#include <mbgl/util/optional.hpp>
namespace mbgl {
diff --git a/src/mbgl/tile/geometry_tile.hpp b/src/mbgl/tile/geometry_tile.hpp
index 0b01a230c5..923585028c 100644
--- a/src/mbgl/tile/geometry_tile.hpp
+++ b/src/mbgl/tile/geometry_tile.hpp
@@ -1,10 +1,10 @@
#ifndef MBGL_MAP_GEOMETRY_TILE
#define MBGL_MAP_GEOMETRY_TILE
+#include <mbgl/util/geometry.hpp>
#include <mbgl/util/feature.hpp>
#include <mbgl/util/chrono.hpp>
#include <mbgl/util/ptr.hpp>
-#include <mbgl/util/vec.hpp>
#include <mbgl/util/noncopyable.hpp>
#include <mbgl/util/optional.hpp>
#include <mbgl/util/variant.hpp>
@@ -28,7 +28,7 @@ enum class FeatureType : uint8_t {
// Normalized vector tile coordinates.
// Each geometry coordinate represents a point in a bidimensional space,
// varying from -V...0...+V, where V is the maximum extent applicable.
-using GeometryCoordinate = vec2<int16_t>;
+using GeometryCoordinate = Point<int16_t>;
using GeometryCoordinates = std::vector<GeometryCoordinate>;
using GeometryCollection = std::vector<GeometryCoordinates>;
diff --git a/src/mbgl/util/geometry.hpp b/src/mbgl/util/geometry.hpp
new file mode 100644
index 0000000000..bf44d5ce93
--- /dev/null
+++ b/src/mbgl/util/geometry.hpp
@@ -0,0 +1,31 @@
+#pragma once
+
+#include <mapbox/geometry/geometry.hpp>
+#include <mapbox/geometry/point_arithmetic.hpp>
+
+namespace mbgl {
+
+template <class T>
+using Point = mapbox::geometry::point<T>;
+
+template <class T>
+using LineString = mapbox::geometry::line_string<T>;
+
+template <class T>
+using Polygon = mapbox::geometry::polygon<T>;
+
+template <class T>
+using MultiPoint = mapbox::geometry::multi_point<T>;
+
+template <class T>
+using MultiLineString = mapbox::geometry::multi_line_string<T>;
+
+template <class T>
+using MultiPolygon = mapbox::geometry::multi_polygon<T>;
+
+template <class S, class T>
+Point<S> convertPoint(const Point<T>& p) {
+ return Point<S>(p.x, p.y);
+}
+
+} // namespace mbgl
diff --git a/src/mbgl/util/intersection_tests.cpp b/src/mbgl/util/intersection_tests.cpp
index 44ec24db12..3e4ae27cd8 100644
--- a/src/mbgl/util/intersection_tests.cpp
+++ b/src/mbgl/util/intersection_tests.cpp
@@ -31,7 +31,7 @@ float distToSegmentSquared(const GeometryCoordinate& p, const GeometryCoordinate
const float t = float((p.x - v.x) * (w.x - v.x) + (p.y - v.y) * (w.y - v.y)) / l2;
if (t < 0) return util::distSqr<float>(p, v);
if (t > 1) return util::distSqr<float>(p, w);
- return util::distSqr<float>(p, vec2<float>(w - v) * t + v);
+ return util::distSqr<float>(p, convertPoint<float>(w - v) * t + convertPoint<float>(v));
}
bool pointIntersectsBufferedLine(const GeometryCoordinate& p, const GeometryCoordinates& line, const float radius) {
diff --git a/src/mbgl/util/mat4.cpp b/src/mbgl/util/mat4.cpp
index bf8252595d..d3d3617b7b 100644
--- a/src/mbgl/util/mat4.cpp
+++ b/src/mbgl/util/mat4.cpp
@@ -21,7 +21,6 @@
// 3. This notice may not be removed or altered from any source distribution.
#include <mbgl/util/mat4.hpp>
-#include <mbgl/util/vec.hpp>
#include <cmath>
@@ -336,11 +335,11 @@ void multiply(mat4& out, const mat4& a, const mat4& b) {
out[15] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;
}
-void transformMat4(vec4<double>& out, vec4<double>& a, mat4& m) {
- out.x = m[0] * a.x + m[4] * a.y + m[8] * a.z + m[12] * a.w;
- out.y = m[1] * a.x + m[5] * a.y + m[9] * a.z + m[13] * a.w;
- out.z = m[2] * a.x + m[6] * a.y + m[10] * a.z + m[14] * a.w;
- out.w = m[3] * a.x + m[7] * a.y + m[11] * a.z + m[15] * a.w;
+void transformMat4(vec4& out, const vec4& a, const mat4& m) {
+ out[0] = m[0] * a[0] + m[4] * a[1] + m[8] * a[2] + m[12] * a[3];
+ out[1] = m[1] * a[0] + m[5] * a[1] + m[9] * a[2] + m[13] * a[3];
+ out[2] = m[2] * a[0] + m[6] * a[1] + m[10] * a[2] + m[14] * a[3];
+ out[3] = m[3] * a[0] + m[7] * a[1] + m[11] * a[2] + m[15] * a[3];
}
} // namespace matrix
diff --git a/src/mbgl/util/mat4.hpp b/src/mbgl/util/mat4.hpp
index ff8e65224c..80bd912554 100644
--- a/src/mbgl/util/mat4.hpp
+++ b/src/mbgl/util/mat4.hpp
@@ -23,12 +23,11 @@
#ifndef MBGL_UTIL_MAT4
#define MBGL_UTIL_MAT4
-#include <mbgl/util/vec.hpp>
-
#include <array>
namespace mbgl {
+using vec4 = std::array<double, 4>;
using mat4 = std::array<double, 16>;
namespace matrix {
@@ -45,7 +44,7 @@ void rotate_z(mat4& out, const mat4& a, double rad);
void scale(mat4& out, const mat4& a, double x, double y, double z);
void multiply(mat4& out, const mat4& a, const mat4& b);
-void transformMat4(vec4<double>& out, vec4<double>& a, mat4& m);
+void transformMat4(vec4& out, const vec4& a, const mat4& m);
} // namespace matrix
} // namespace mbgl
diff --git a/src/mbgl/util/math.hpp b/src/mbgl/util/math.hpp
index 6c6b02d126..f93743f211 100644
--- a/src/mbgl/util/math.hpp
+++ b/src/mbgl/util/math.hpp
@@ -5,7 +5,7 @@
#include <array>
#include <limits>
-#include <mbgl/util/vec.hpp>
+#include <mbgl/util/geometry.hpp>
namespace mbgl {
namespace util {
@@ -15,17 +15,12 @@ namespace util {
// Find the angle of the two vectors, solving the formula for the cross product
// a x b = |a||b|sin(θ) for θ.
template <typename T = double, typename S>
-inline T angle_between(S ax, S ay, S bx, S by) {
- return std::atan2((ax * by - ay * bx), ax * bx + ay * by);
+inline T angle_between(const Point<S>& a, const Point<S>& b) {
+ return std::atan2((a.x * b.y - a.y * b.x), a.x * b.x + a.y * b.y);
}
template <typename T = double, typename S>
-inline T angle_between(const vec2<S>& a, const vec2<S>& b) {
- return angle_between(a.x, a.y, b.x, b.y);
-}
-
-template <typename T = double, typename S>
-inline T angle_to(const vec2<S>& a, const vec2<S>& b) {
+inline T angle_to(const Point<S>& a, const Point<S>& b) {
return std::atan2(a.y - b.y, a.x - b.x);
}
@@ -39,7 +34,7 @@ inline std::array<T, 2> flip(const std::array<T, 2>& c) {
}
template <typename T, typename S1, typename S2>
-inline vec2<T> normal(const S1& a, const S2& b) {
+inline Point<T> normal(const S1& a, const S2& b) {
T dx = b.x - a.x;
T dy = b.y - a.y;
T c = std::sqrt(dx * dx + dy * dy);
@@ -102,6 +97,11 @@ inline T rotate(const T& a, S angle) {
}
template <typename T>
+inline Point<T> matrixMultiply(const std::array<T, 4>& m, const Point<T>& p) {
+ return Point<T>(m[0] * p.x + m[1] * p.y, m[2] * p.x + m[3] * p.y);
+}
+
+template <typename T>
T smoothstep(T edge0, T edge1, T x) {
T t = clamp((x - edge0) / (edge1 - edge0), T(0), T(1));
return t * t * (T(3) - T(2) * t);
diff --git a/src/mbgl/util/tile_cover.cpp b/src/mbgl/util/tile_cover.cpp
index f2bda3f45b..6cd5d4b4ab 100644
--- a/src/mbgl/util/tile_cover.cpp
+++ b/src/mbgl/util/tile_cover.cpp
@@ -1,5 +1,4 @@
#include <mbgl/util/tile_cover.hpp>
-#include <mbgl/util/vec.hpp>
#include <mbgl/util/constants.hpp>
#include <mbgl/util/interpolate.hpp>
#include <mbgl/map/transform_state.hpp>
diff --git a/src/mbgl/util/vec.hpp b/src/mbgl/util/vec.hpp
deleted file mode 100644
index 40d540fca4..0000000000
--- a/src/mbgl/util/vec.hpp
+++ /dev/null
@@ -1,126 +0,0 @@
-#ifndef MBGL_UTIL_VEC
-#define MBGL_UTIL_VEC
-
-#include <limits>
-#include <type_traits>
-#include <cmath>
-#include <cstdint>
-#include <array>
-
-namespace mbgl {
-
-template <typename T = double>
-struct vec2 {
- struct null {};
- typedef T Type;
-
- T x, y;
-
- inline vec2() = default;
-
- template<typename U = T, typename std::enable_if<std::numeric_limits<U>::has_quiet_NaN, int>::type = 0>
- inline vec2(null) : x(std::numeric_limits<T>::quiet_NaN()), y(std::numeric_limits<T>::quiet_NaN()) {}
-
- template<typename U = T, typename std::enable_if<!std::numeric_limits<U>::has_quiet_NaN, int>::type = 0>
- inline vec2(null) : x(std::numeric_limits<T>::min()), y(std::numeric_limits<T>::min()) {}
-
- inline vec2(const vec2& o) = default;
-
- template<typename U>
- inline vec2(const U& u) : x(u.x), y(u.y) {}
-
- inline vec2(T x_, T y_) : x(x_), y(y_) {}
-
- inline bool operator==(const vec2& rhs) const {
- return x == rhs.x && y == rhs.y;
- }
-
- template <typename O>
- inline typename std::enable_if<std::is_arithmetic<O>::value, vec2>::type
- operator*(O o) const {
- return {x * o, y * o};
- }
-
- inline void operator*=(T o) {
- x *= o;
- y *= o;
- }
-
- template <typename O>
- inline typename std::enable_if<std::is_arithmetic<O>::value, vec2>::type
- operator/(O o) const {
- return {x / o, y / o};
- }
-
- inline void operator/=(T o) {
- x /= o;
- y /= o;
- }
-
- inline vec2<T> operator *(const std::array<float, 16>& matrix) {
- return { x * matrix[0] + y * matrix[4] + matrix[12], x * matrix[1] + y * matrix[5] + matrix[13] };
- }
-
- template <typename O>
- inline typename std::enable_if<std::is_arithmetic<O>::value, vec2>::type
- operator-(O o) const {
- return {x - o, y - o};
- }
-
- template <typename O>
- inline typename std::enable_if<!std::is_arithmetic<O>::value, vec2>::type
- operator-(const O &o) const {
- return vec2<T>(x - o.x, y - o.y);
- }
-
- template <typename O>
- inline typename std::enable_if<!std::is_arithmetic<O>::value, vec2>::type
- operator+(const O &o) const {
- return vec2<T>(x + o.x, y + o.y);
- }
-
- template <typename M>
- inline vec2 matMul(const M &m) const {
- return {m[0] * x + m[1] * y, m[2] * x + m[3] * y};
- }
-
- template<typename U = T, typename std::enable_if<std::numeric_limits<U>::has_quiet_NaN, int>::type = 0>
- explicit operator bool() const {
- return !std::isnan(x) && !std::isnan(y);
- }
-
- template<typename U = T, typename std::enable_if<!std::numeric_limits<U>::has_quiet_NaN, int>::type = 0>
- explicit operator bool() const {
- return x != std::numeric_limits<T>::min() && y != std::numeric_limits<T>::min();
- }
-};
-
-template <typename T = double>
-struct vec4 {
- T x, y, z, w;
-
- inline vec4() = default;
- inline vec4(const vec4& o) : x(o.x), y(o.y), z(o.z), w(o.w) {}
- inline vec4(T x_, T y_, T z_, T w_) : x(x_), y(y_), z(z_), w(w_) {}
- inline bool operator==(const vec4& rhs) const {
- return x == rhs.x && y == rhs.y && z == rhs.z && w == rhs.w;
- }
-
- template<typename U = T, typename std::enable_if<std::numeric_limits<U>::has_quiet_NaN, int>::type = 0>
- explicit operator bool() const {
- return !std::isnan(x) && !std::isnan(y) && !std::isnan(z) && !std::isnan(w);
- }
-
- template<typename U = T, typename std::enable_if<!std::numeric_limits<U>::has_quiet_NaN, int>::type = 0>
- explicit operator bool() const {
- return x != std::numeric_limits<T>::min()
- && y != std::numeric_limits<T>::min()
- && z != std::numeric_limits<T>::min()
- && w != std::numeric_limits<T>::min();
- }
-};
-
-
-} // namespace mbgl
-
-#endif // MBGL_UTIL_VEC
diff --git a/test/map/transform.cpp b/test/map/transform.cpp
index 104ad7085f..a3a62e7ad8 100644
--- a/test/map/transform.cpp
+++ b/test/map/transform.cpp
@@ -79,9 +79,6 @@ TEST(Transform, InvalidLatLng) {
ASSERT_DOUBLE_EQ(10, transform.getLatLng().latitude);
ASSERT_DOUBLE_EQ(8, transform.getLatLng().longitude);
ASSERT_DOUBLE_EQ(4, transform.getScale());
-
- ASSERT_FALSE(transform.latLngToScreenCoordinate(LatLng::null()));
- ASSERT_FALSE(transform.screenCoordinateToLatLng(ScreenCoordinate::null()));
}
@@ -225,7 +222,7 @@ TEST(Transform, Anchor) {
ASSERT_DOUBLE_EQ(10, transform.getZoom());
ASSERT_DOUBLE_EQ(0, transform.getAngle());
- const ScreenCoordinate invalidAnchorPoint = ScreenCoordinate::null();
+ const optional<ScreenCoordinate> invalidAnchorPoint {};
const ScreenCoordinate anchorPoint = { 150, 150 };
const LatLng anchorLatLng = transform.getState().screenCoordinateToLatLng(anchorPoint);