adapters: nearest-cell distance in double
This commit is contained in:
1 parent
e5b7faadec
commit
73f610b136
2 files changed
+12
-10
No files matched your search
@@ -556,16 +556,17 @@ u32 Host::row_in(const std::vector<Rect>& rows, f32 x, f32 y) noexcept {
|
|||||||
// visible gap must not be routed to plot 0 by default. For a figure with one cell per
|
// visible gap must not be routed to plot 0 by default. For a figure with one cell per
|
||||||
// row every cell spans the figure's width, so this reduces to the nearest row by y.
|
// row every cell spans the figure's width, so this reduces to the nearest row by y.
|
||||||
u32 row = 0u;
|
u32 row = 0u;
|
||||||
f32 best = std::numeric_limits<f32>::infinity();
|
double best = std::numeric_limits<double>::infinity();
|
||||||
for (u32 i = 0; i < rows.size(); ++i) {
|
for (u32 i = 0; i < rows.size(); ++i) {
|
||||||
const Rect& r = rows[i];
|
const Rect& r = rows[i];
|
||||||
const f32 dx = x < r.x ? r.x - x : (x >= r.right() ? x - r.right() : 0.0f);
|
// In double: in f32 the dy^2 term can be swallowed by a large dx^2 (pointer far outside).
|
||||||
const f32 dy = y < r.y ? r.y - y : (y >= r.bottom() ? y - r.bottom() : 0.0f);
|
const double dx = x < r.x ? double(r.x) - x : (x >= r.right() ? double(x) - r.right() : 0.0);
|
||||||
const f32 distance = dx * dx + dy * dy;
|
const double dy = y < r.y ? double(r.y) - y : (y >= r.bottom() ? double(y) - r.bottom() : 0.0);
|
||||||
|
const double distance = dx * dx + dy * dy;
|
||||||
if (distance < best) {
|
if (distance < best) {
|
||||||
best = distance;
|
best = distance;
|
||||||
row = i;
|
row = i;
|
||||||
if (distance == 0.0f) break; // inside this cell: nothing can be nearer
|
if (distance == 0.0) break; // inside this cell: nothing can be nearer
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return row;
|
return row;
|
||||||
|
|||||||
@@ -326,16 +326,17 @@ u32 PlotArea::row_in(const std::vector<Rect>& rows, f32 x, f32 y) noexcept {
|
|||||||
// in a visible gap must not default to plot 0. For a figure with one cell per row
|
// in a visible gap must not default to plot 0. For a figure with one cell per row
|
||||||
// every cell spans the figure's width, so this reduces to the nearest row by y.
|
// every cell spans the figure's width, so this reduces to the nearest row by y.
|
||||||
u32 row = 0;
|
u32 row = 0;
|
||||||
f32 best = std::numeric_limits<f32>::infinity();
|
double best = std::numeric_limits<double>::infinity();
|
||||||
for (u32 i = 0; i < rows.size(); ++i) {
|
for (u32 i = 0; i < rows.size(); ++i) {
|
||||||
const Rect& r = rows[i];
|
const Rect& r = rows[i];
|
||||||
const f32 dx = x < r.x ? r.x - x : (x >= r.right() ? x - r.right() : 0.0f);
|
// In double: in f32 the dy^2 term can be swallowed by a large dx^2 (pointer far outside).
|
||||||
const f32 dy = y < r.y ? r.y - y : (y >= r.bottom() ? y - r.bottom() : 0.0f);
|
const double dx = x < r.x ? double(r.x) - x : (x >= r.right() ? double(x) - r.right() : 0.0);
|
||||||
const f32 distance = dx * dx + dy * dy;
|
const double dy = y < r.y ? double(r.y) - y : (y >= r.bottom() ? double(y) - r.bottom() : 0.0);
|
||||||
|
const double distance = dx * dx + dy * dy;
|
||||||
if (distance < best) {
|
if (distance < best) {
|
||||||
best = distance;
|
best = distance;
|
||||||
row = i;
|
row = i;
|
||||||
if (distance == 0.0f) break; // inside this cell: nothing can be nearer
|
if (distance == 0.0) break; // inside this cell: nothing can be nearer
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return row;
|
return row;
|
||||||
|
|||||||
Reference in new issue
Block a user