mirror of
https://github.com/zjs81/meshcore-open.git
synced 2026-07-22 16:51:05 +10:00
Enhance path hop resolution by adding distance checks to improve candidate selection accuracy
This commit is contained in:
@@ -840,7 +840,8 @@ List<_PathHop> _buildPathHops(
|
|||||||
: null;
|
: null;
|
||||||
var previousPosition = startPoint;
|
var previousPosition = startPoint;
|
||||||
final distance = Distance();
|
final distance = Distance();
|
||||||
|
var lastDistance = 0.0;
|
||||||
|
var bestDistance = 0.0;
|
||||||
final hops = <_PathHop>[];
|
final hops = <_PathHop>[];
|
||||||
for (var i = 0; i < pathBytes.length; i++) {
|
for (var i = 0; i < pathBytes.length; i++) {
|
||||||
final searchPoint = i == 0 ? startPoint : previousPosition;
|
final searchPoint = i == 0 ? startPoint : previousPosition;
|
||||||
@@ -849,7 +850,7 @@ List<_PathHop> _buildPathHops(
|
|||||||
if (candidates != null && candidates.isNotEmpty) {
|
if (candidates != null && candidates.isNotEmpty) {
|
||||||
var bestIndex = 0;
|
var bestIndex = 0;
|
||||||
if (searchPoint != null) {
|
if (searchPoint != null) {
|
||||||
var bestDistance = double.infinity;
|
bestDistance = double.infinity;
|
||||||
for (var j = 0; j < candidates.length; j++) {
|
for (var j = 0; j < candidates.length; j++) {
|
||||||
final candidate = candidates[j];
|
final candidate = candidates[j];
|
||||||
if (!candidate.hasLocation ||
|
if (!candidate.hasLocation ||
|
||||||
@@ -877,6 +878,16 @@ List<_PathHop> _buildPathHops(
|
|||||||
if (resolvedPosition != null) {
|
if (resolvedPosition != null) {
|
||||||
previousPosition = resolvedPosition;
|
previousPosition = resolvedPosition;
|
||||||
}
|
}
|
||||||
|
// If the best candidate is much farther than the previous hop, it's likely not the correct match.
|
||||||
|
if (lastDistance + bestDistance > 70000 &&
|
||||||
|
candidates != null &&
|
||||||
|
candidates.isNotEmpty) {
|
||||||
|
i--;
|
||||||
|
lastDistance = bestDistance;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
lastDistance = bestDistance;
|
||||||
|
|
||||||
hops.add(
|
hops.add(
|
||||||
_PathHop(
|
_PathHop(
|
||||||
index: i + 1,
|
index: i + 1,
|
||||||
|
|||||||
Reference in New Issue
Block a user