mirror of
https://github.com/tumic0/GPXSee.git
synced 2025-01-19 04:02:09 +01:00
Use a faster segment lookup (in case there are many segments)
+ remove the "overflow safe" index computations - we shall really not exceed 2^30 track points in a single track...
This commit is contained in:
parent
933ecffe93
commit
7ddadf9811
@ -78,11 +78,25 @@ void GraphItem::setWidth(int width)
|
|||||||
|
|
||||||
const GraphSegment *GraphItem::segment(qreal x, GraphType type) const
|
const GraphSegment *GraphItem::segment(qreal x, GraphType type) const
|
||||||
{
|
{
|
||||||
for (int i = 0; i < _graph.size(); i++)
|
int low = 0;
|
||||||
if (x <= _graph.at(i).last().x(type))
|
int high = _graph.size() - 1;
|
||||||
return &(_graph.at(i));
|
int mid = 0;
|
||||||
|
|
||||||
return 0;
|
while (low <= high) {
|
||||||
|
mid = (high + low) / 2;
|
||||||
|
const GraphPoint &p = _graph.at(mid).last();
|
||||||
|
if (p.x(_type) > x)
|
||||||
|
high = mid - 1;
|
||||||
|
else if (p.x(_type) < x)
|
||||||
|
low = mid + 1;
|
||||||
|
else
|
||||||
|
return &(_graph.at(mid));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_graph.at(mid).last().x(type) < x)
|
||||||
|
return (mid == _graph.size() - 1) ? 0 : &(_graph.at(mid+1));
|
||||||
|
else
|
||||||
|
return &(_graph.at(mid));
|
||||||
}
|
}
|
||||||
|
|
||||||
qreal GraphItem::yAtX(qreal x) const
|
qreal GraphItem::yAtX(qreal x) const
|
||||||
@ -99,7 +113,7 @@ qreal GraphItem::yAtX(qreal x) const
|
|||||||
return NAN;
|
return NAN;
|
||||||
|
|
||||||
while (low <= high) {
|
while (low <= high) {
|
||||||
mid = low + ((high - low) / 2);
|
mid = (high + low) / 2;
|
||||||
const GraphPoint &p = seg->at(mid);
|
const GraphPoint &p = seg->at(mid);
|
||||||
if (p.x(_type) > x)
|
if (p.x(_type) > x)
|
||||||
high = mid - 1;
|
high = mid - 1;
|
||||||
@ -137,7 +151,7 @@ qreal GraphItem::distanceAtTime(qreal time) const
|
|||||||
return NAN;
|
return NAN;
|
||||||
|
|
||||||
while (low <= high) {
|
while (low <= high) {
|
||||||
mid = low + ((high - low) / 2);
|
mid = (high + low) / 2;
|
||||||
const GraphPoint &p = seg->at(mid);
|
const GraphPoint &p = seg->at(mid);
|
||||||
if (p.t() > time)
|
if (p.t() > time)
|
||||||
high = mid - 1;
|
high = mid - 1;
|
||||||
@ -175,7 +189,7 @@ qreal GraphItem::timeAtDistance(qreal distance) const
|
|||||||
return NAN;
|
return NAN;
|
||||||
|
|
||||||
while (low <= high) {
|
while (low <= high) {
|
||||||
mid = low + ((high - low) / 2);
|
mid = (high + low) / 2;
|
||||||
const GraphPoint &p = seg->at(mid);
|
const GraphPoint &p = seg->at(mid);
|
||||||
if (p.s() > distance)
|
if (p.s() > distance)
|
||||||
high = mid - 1;
|
high = mid - 1;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user