Merge branch 'master' into sender

This commit is contained in:
Alessandro Ranellucci 2015-01-04 19:36:28 +01:00
commit 3ab4d4b094
16 changed files with 192 additions and 61 deletions

View file

@ -328,8 +328,8 @@ MedialAxis::is_valid_edge(const VD::edge_type& edge) const
// our skeleton
Point v0( edge.vertex0()->x(), edge.vertex0()->y() );
Point v1( edge.vertex1()->x(), edge.vertex1()->y() );
double dist0 = v0.distance_to(segment1);
double dist1 = v1.distance_to(segment1);
double dist0 = v0.perp_distance_to(segment1);
double dist1 = v1.perp_distance_to(segment1);
/*
double diff = fabs(dist1 - dist0);

View file

@ -90,6 +90,7 @@ MultiPoint::_douglas_peucker(const Points &points, const double tolerance)
size_t index = 0;
Line full(points.front(), points.back());
for (Points::const_iterator it = points.begin() + 1; it != points.end(); ++it) {
// we use shortest distance, not perpendicular distance
double d = it->distance_to(full);
if (d > dmax) {
index = it - points.begin();

View file

@ -1,6 +1,7 @@
#include "Point.hpp"
#include "Line.hpp"
#include "MultiPoint.hpp"
#include <algorithm>
#include <cmath>
#include <sstream>
@ -130,8 +131,31 @@ Point::distance_to(const Point &point) const
return sqrt(dx*dx + dy*dy);
}
/* distance to the closest point of line */
double
Point::distance_to(const Line &line) const
{
const double dx = line.b.x - line.a.x;
const double dy = line.b.y - line.a.y;
const double l2 = dx*dx + dy*dy; // avoid a sqrt
if (l2 == 0.0) return this->distance_to(line.a); // line.a == line.b case
// Consider the line extending the segment, parameterized as line.a + t (line.b - line.a).
// We find projection of this point onto the line.
// It falls where t = [(this-line.a) . (line.b-line.a)] / |line.b-line.a|^2
const double t = ((this->x - line.a.x) * dx + (this->y - line.a.y) * dy) / l2;
if (t < 0.0) return this->distance_to(line.a); // beyond the 'a' end of the segment
else if (t > 1.0) return this->distance_to(line.b); // beyond the 'b' end of the segment
Point projection(
line.a.x + t * dx,
line.a.y + t * dy
);
return this->distance_to(projection);
}
double
Point::perp_distance_to(const Line &line) const
{
if (line.a.coincides_with(line.b)) return this->distance_to(line.a);

View file

@ -48,6 +48,7 @@ class Point
bool nearest_point(const Points &points, Point* point) const;
double distance_to(const Point &point) const;
double distance_to(const Line &line) const;
double perp_distance_to(const Line &line) const;
double ccw(const Point &p1, const Point &p2) const;
double ccw(const Line &line) const;
double ccw_angle(const Point &p1, const Point &p2) const;

View file

@ -126,11 +126,11 @@ PrintConfigDef::build_def() {
Options["external_fill_pattern"].enum_values.push_back("hilbertcurve");
Options["external_fill_pattern"].enum_values.push_back("archimedeanchords");
Options["external_fill_pattern"].enum_values.push_back("octagramspiral");
Options["external_fill_pattern"].enum_labels.push_back("rectilinear");
Options["external_fill_pattern"].enum_labels.push_back("concentric");
Options["external_fill_pattern"].enum_labels.push_back("hilbertcurve (slow)");
Options["external_fill_pattern"].enum_labels.push_back("archimedeanchords (slow)");
Options["external_fill_pattern"].enum_labels.push_back("octagramspiral (slow)");
Options["external_fill_pattern"].enum_labels.push_back("Rectilinear");
Options["external_fill_pattern"].enum_labels.push_back("Concentric");
Options["external_fill_pattern"].enum_labels.push_back("Hilbert Curve");
Options["external_fill_pattern"].enum_labels.push_back("Archimedean Chords");
Options["external_fill_pattern"].enum_labels.push_back("Octagram Spiral");
Options["external_fill_pattern"].aliases.push_back("solid_fill_pattern");
Options["external_perimeter_extrusion_width"].type = coFloatOrPercent;
@ -293,14 +293,14 @@ PrintConfigDef::build_def() {
Options["fill_pattern"].enum_values.push_back("hilbertcurve");
Options["fill_pattern"].enum_values.push_back("archimedeanchords");
Options["fill_pattern"].enum_values.push_back("octagramspiral");
Options["fill_pattern"].enum_labels.push_back("rectilinear");
Options["fill_pattern"].enum_labels.push_back("line");
Options["fill_pattern"].enum_labels.push_back("concentric");
Options["fill_pattern"].enum_labels.push_back("honeycomb");
Options["fill_pattern"].enum_labels.push_back("3D honeycomb");
Options["fill_pattern"].enum_labels.push_back("hilbertcurve");
Options["fill_pattern"].enum_labels.push_back("archimedeanchords");
Options["fill_pattern"].enum_labels.push_back("octagramspiral");
Options["fill_pattern"].enum_labels.push_back("Rectilinear");
Options["fill_pattern"].enum_labels.push_back("Line");
Options["fill_pattern"].enum_labels.push_back("Concentric");
Options["fill_pattern"].enum_labels.push_back("Honeycomb");
Options["fill_pattern"].enum_labels.push_back("3D Honeycomb");
Options["fill_pattern"].enum_labels.push_back("Hilbert Curve");
Options["fill_pattern"].enum_labels.push_back("Archimedean Chords");
Options["fill_pattern"].enum_labels.push_back("Octagram Spiral");
Options["first_layer_acceleration"].type = coFloat;
Options["first_layer_acceleration"].label = "First layer";
@ -965,7 +965,7 @@ PrintConfigDef::build_def() {
Options["use_relative_e_distances"].cli = "use-relative-e-distances!";
Options["vibration_limit"].type = coFloat;
Options["vibration_limit"].label = "Vibration limit";
Options["vibration_limit"].label = "Vibration limit (deprecated)";
Options["vibration_limit"].tooltip = "This experimental option will slow down those moves hitting the configured frequency limit. The purpose of limiting vibrations is to avoid mechanical resonance. Set zero to disable.";
Options["vibration_limit"].sidetext = "Hz";
Options["vibration_limit"].cli = "vibration-limit=f";