Fix overflow in distance_to(Line*). It was affecting Douglas-Peucker causing massive loss of geometry. Includes regression test and a couple wkt() implementations

This commit is contained in:
Alessandro Ranellucci
2014-01-17 14:22:37 +01:00
parent 3a3e53b59b
commit 0d7f0705f0
6 changed files with 35 additions and 3 deletions

View File

@@ -1,9 +1,18 @@
#include "Point.hpp"
#include "Line.hpp"
#include <cmath>
#include <sstream>
namespace Slic3r {
std::string
Point::wkt() const
{
std::ostringstream ss;
ss << "POINT(" << this->x << " " << this->y << ")";
return ss.str();
}
void
Point::scale(double factor)
{
@@ -100,8 +109,8 @@ Point::distance_to(const Line &line) const
{
if (line.a.coincides_with(&line.b)) return this->distance_to(&line.a);
double n = (line.b.x - line.a.x) * (line.a.y - this->y)
- (line.a.x - this->x) * (line.b.y - line.a.y);
double n = (double)(line.b.x - line.a.x) * (double)(line.a.y - this->y)
- (double)(line.a.x - this->x) * (double)(line.b.y - line.a.y);
return std::abs(n) / line.length();
}