Skip to content

Commit 917a012

Browse files
author
Dennis Rohde
committed
bugfix 2 approximate simplification
1 parent c7151a7 commit 917a012

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def build_extension(self, ext):
8080

8181
setup(
8282
name='Fred-Frechet',
83-
version='1.10.5',
83+
version='1.10.6',
8484
author='Dennis Rohde',
8585
author_email='[email protected]',
8686
description='A fast, scalable and light-weight C++ Fréchet distance library, exposed to python and focused on (k,l)-clustering of polygonal curves.',

src/simplification.cpp

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
1111
#include "simplification.hpp"
1212

1313
Curve Simplification::approximate_minimum_link_simplification(const Curve &pcurve, const distance_t epsilon) {
14-
if (Config::verbosity > 1) py::print("ASIMPL: computing approximate minimum link simplification");
14+
if (Config::verbosity > 1) py::print("ASIMPL: computing approximate minimum link simplification for curve of complexity ", pcurve.complexity());
1515
Curve &curve = const_cast<Curve&>(pcurve);
1616
const curve_size_t complexity = curve.complexity();
1717

18-
curve_size_t i = 0, j = 0;
18+
curve_size_t i = 0, j = 0, low, mid, high;
1919

2020
Curve simplification(curve.dimensions()), segment(2, curve.dimensions());
2121
simplification.push_back(curve.front());
@@ -28,7 +28,7 @@ Curve Simplification::approximate_minimum_link_simplification(const Curve &pcurv
2828
j = 0;
2929
distance = 0;
3030

31-
if (Config::verbosity > 1) py::print("ASIMPL: computing maximum shortcut starting at ", i);
31+
if (Config::verbosity > 1) py::print("ASIMPL: computing maximum length shortcut starting at ", i);
3232

3333
if (Config::verbosity > 1) py::print("ASIMPL: exponential error search");
3434

@@ -44,27 +44,30 @@ Curve Simplification::approximate_minimum_link_simplification(const Curve &pcurv
4444
distance = Frechet::Continuous::distance(curve, segment).value;
4545
}
4646

47-
curve_size_t low, mid, high;
48-
49-
low = j == 1 ? 0 : std::pow(2, j - 1);
47+
low = std::pow(2, j - 1);
5048
high = std::min(static_cast<curve_size_t>(std::pow(2, j)), complexity - i - 1);
5149

52-
if (Config::verbosity > 1) py::print("ASIMPL: binary error search");
50+
if (Config::verbosity > 1) py::print("ASIMPL: binary error search for low = ", low, " and high = ", high);
51+
5352
while (low < high) {
54-
mid = std::ceil((low + high) / 2.);
53+
mid = std::ceil(low + (high - low) * .5);
5554

5655
curve.reset_subcurve();
5756
segment[1] = curve[i + mid];
5857
curve.set_subcurve(i, i + mid);
5958

6059
distance = Frechet::Continuous::distance(curve, segment).value;
6160

62-
if (distance <= epsilon) low = mid;
63-
else high = mid - 1;
61+
if (distance > epsilon) high = mid - 1;
62+
else low = mid;
6463
}
64+
6565
if (Config::verbosity > 1) py::print("ASIMPL: shortcutting from ", i, " to ", i+low);
66+
6667
i += low;
68+
6769
curve.reset_subcurve();
70+
6871
simplification.push_back(curve[i]);
6972
}
7073
return simplification;

0 commit comments

Comments
 (0)