Initial Vec2 impl ready for algo
This commit is contained in:
35
src/custom_types.cpp
Normal file
35
src/custom_types.cpp
Normal file
@@ -0,0 +1,35 @@
|
||||
// Copyright (C) 2026 Hector van der Aa <hector@h3cx.dev>
|
||||
// Copyright (C) 2026 Association Exergie <association.exergie@gmail.com>
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
#include "custom_types.h"
|
||||
#include "math.h"
|
||||
|
||||
Vec2 eqRectProjection(const LatLng target, const LatLng ref) {
|
||||
const float R = 6371000.0;
|
||||
float lat0_r = ref.lat_ * M_PI / 180;
|
||||
float lng0_r = ref.lng_ * M_PI / 180;
|
||||
float lat1_r = target.lat_ * M_PI / 180;
|
||||
float lng1_r = target.lng_ * M_PI / 180;
|
||||
float lat_avg = (lat0_r + lat1_r) * 0.5f;
|
||||
float lat0_cos = cos(lat_avg);
|
||||
|
||||
|
||||
Vec2 res;
|
||||
|
||||
res.x_ = (lng1_r - lng0_r) * lat0_cos * R;
|
||||
res.y_ = (lat1_r - lat0_r) * R;
|
||||
return res;
|
||||
}
|
||||
|
||||
Vec2 abMidpoint(const Vec2 A, const Vec2 B) {
|
||||
Vec2 res;
|
||||
res.x_ = (A.x_ + B.x_) * 0.5f;
|
||||
res.y_ = (A.y_ + B.y_) * 0.5f;
|
||||
return res;
|
||||
}
|
||||
|
||||
float abSqDist(const Vec2 A, const Vec2 B) {
|
||||
float deltaX = B.x_ - A.x_;
|
||||
float deltaY = B.y_ - A.y_;
|
||||
return deltaX * deltaX + deltaY * deltaY;
|
||||
}
|
||||
Reference in New Issue
Block a user