2013-11-22 21:38:30 +00:00
|
|
|
#ifndef slic3r_Geometry_hpp_
|
|
|
|
#define slic3r_Geometry_hpp_
|
|
|
|
|
2015-12-07 23:39:54 +00:00
|
|
|
#include "libslic3r.h"
|
2014-01-09 18:56:12 +00:00
|
|
|
#include "BoundingBox.hpp"
|
2016-03-19 14:33:58 +00:00
|
|
|
#include "ExPolygon.hpp"
|
2013-11-22 21:38:30 +00:00
|
|
|
#include "Polygon.hpp"
|
2014-01-10 15:18:55 +00:00
|
|
|
#include "Polyline.hpp"
|
2013-11-22 21:38:30 +00:00
|
|
|
|
2014-01-09 18:56:12 +00:00
|
|
|
#include "boost/polygon/voronoi.hpp"
|
|
|
|
using boost::polygon::voronoi_builder;
|
|
|
|
using boost::polygon::voronoi_diagram;
|
|
|
|
|
2013-11-23 20:54:56 +00:00
|
|
|
namespace Slic3r { namespace Geometry {
|
2013-11-22 21:38:30 +00:00
|
|
|
|
2017-03-15 15:33:25 +00:00
|
|
|
inline bool ray_ray_intersection(const Pointf &p1, const Vectorf &v1, const Pointf &p2, const Vectorf &v2, Pointf &res)
|
|
|
|
{
|
|
|
|
double denom = v1.x * v2.y - v2.x * v1.y;
|
|
|
|
if (std::abs(denom) < EPSILON)
|
|
|
|
return false;
|
|
|
|
double t = (v2.x * (p1.y - p2.y) - v2.y * (p1.x - p2.x)) / denom;
|
|
|
|
res.x = p1.x + t * v1.x;
|
|
|
|
res.y = p1.y + t * v1.y;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool segment_segment_intersection(const Pointf &p1, const Vectorf &v1, const Pointf &p2, const Vectorf &v2, Pointf &res)
|
|
|
|
{
|
|
|
|
double denom = v1.x * v2.y - v2.x * v1.y;
|
|
|
|
if (std::abs(denom) < EPSILON)
|
|
|
|
// Lines are collinear.
|
|
|
|
return false;
|
|
|
|
double s12_x = p1.x - p2.x;
|
|
|
|
double s12_y = p1.y - p2.y;
|
|
|
|
double s_numer = v1.x * s12_y - v1.y * s12_x;
|
|
|
|
bool denom_is_positive = false;
|
|
|
|
if (denom < 0.) {
|
|
|
|
denom_is_positive = true;
|
|
|
|
denom = - denom;
|
|
|
|
s_numer = - s_numer;
|
|
|
|
}
|
|
|
|
if (s_numer < 0.)
|
|
|
|
// Intersection outside of the 1st segment.
|
|
|
|
return false;
|
|
|
|
double t_numer = v2.x * s12_y - v2.y * s12_x;
|
|
|
|
if (! denom_is_positive)
|
|
|
|
t_numer = - t_numer;
|
|
|
|
if (t_numer < 0. || s_numer > denom || t_numer > denom)
|
|
|
|
// Intersection outside of the 1st or 2nd segment.
|
|
|
|
return false;
|
|
|
|
// Intersection inside both of the segments.
|
|
|
|
double t = t_numer / denom;
|
|
|
|
res.x = p1.x + t * v1.x;
|
|
|
|
res.y = p1.y + t * v1.y;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-01-19 17:53:04 +00:00
|
|
|
Polygon convex_hull(Points points);
|
|
|
|
Polygon convex_hull(const Polygons &polygons);
|
2014-11-09 11:25:59 +00:00
|
|
|
void chained_path(const Points &points, std::vector<Points::size_type> &retval, Point start_near);
|
|
|
|
void chained_path(const Points &points, std::vector<Points::size_type> &retval);
|
2013-11-23 22:21:59 +00:00
|
|
|
template<class T> void chained_path_items(Points &points, T &items, T &retval);
|
2014-05-02 16:46:22 +00:00
|
|
|
bool directions_parallel(double angle1, double angle2, double max_diff = 0);
|
2014-11-23 19:14:13 +00:00
|
|
|
template<class T> bool contains(const std::vector<T> &vector, const Point &point);
|
2014-11-15 21:41:22 +00:00
|
|
|
double rad2deg(double angle);
|
|
|
|
double rad2deg_dir(double angle);
|
2017-03-22 14:35:09 +00:00
|
|
|
template<typename T> T deg2rad(T angle) { return T(PI) * angle / T(180.0); }
|
2015-01-30 17:33:20 +00:00
|
|
|
void simplify_polygons(const Polygons &polygons, double tolerance, Polygons* retval);
|
2013-11-22 21:38:30 +00:00
|
|
|
|
2015-04-29 17:19:07 +00:00
|
|
|
double linint(double value, double oldmin, double oldmax, double newmin, double newmax);
|
2016-11-04 14:03:51 +00:00
|
|
|
bool arrange(
|
|
|
|
// input
|
|
|
|
size_t num_parts, const Pointf &part_size, coordf_t gap, const BoundingBoxf* bed_bounding_box,
|
|
|
|
// output
|
|
|
|
Pointfs &positions);
|
2015-04-29 17:19:07 +00:00
|
|
|
|
2014-01-09 18:56:12 +00:00
|
|
|
class MedialAxis {
|
|
|
|
public:
|
|
|
|
Lines lines;
|
2016-03-19 14:33:58 +00:00
|
|
|
const ExPolygon* expolygon;
|
2014-03-09 16:46:02 +00:00
|
|
|
double max_width;
|
|
|
|
double min_width;
|
2016-05-20 04:24:05 +00:00
|
|
|
MedialAxis(double _max_width, double _min_width, const ExPolygon* _expolygon = NULL)
|
|
|
|
: max_width(_max_width), min_width(_min_width), expolygon(_expolygon) {};
|
2016-03-19 14:33:58 +00:00
|
|
|
void build(ThickPolylines* polylines);
|
2014-01-09 18:56:12 +00:00
|
|
|
void build(Polylines* polylines);
|
|
|
|
|
|
|
|
private:
|
2016-03-27 08:53:59 +00:00
|
|
|
class VD : public voronoi_diagram<double> {
|
|
|
|
public:
|
|
|
|
typedef double coord_type;
|
|
|
|
typedef boost::polygon::point_data<coordinate_type> point_type;
|
|
|
|
typedef boost::polygon::segment_data<coordinate_type> segment_type;
|
|
|
|
typedef boost::polygon::rectangle_data<coordinate_type> rect_type;
|
|
|
|
};
|
2014-01-10 15:18:55 +00:00
|
|
|
VD vd;
|
2016-03-20 19:20:32 +00:00
|
|
|
std::set<const VD::edge_type*> edges, valid_edges;
|
2016-03-19 14:33:58 +00:00
|
|
|
std::map<const VD::edge_type*, std::pair<coordf_t,coordf_t> > thickness;
|
2016-03-20 19:20:32 +00:00
|
|
|
void process_edge_neighbors(const VD::edge_type* edge, ThickPolyline* polyline);
|
|
|
|
bool validate_edge(const VD::edge_type* edge);
|
|
|
|
const Line& retrieve_segment(const VD::cell_type* cell) const;
|
|
|
|
const Point& retrieve_endpoint(const VD::cell_type* cell) const;
|
2014-01-09 18:56:12 +00:00
|
|
|
};
|
|
|
|
|
2013-11-23 20:54:56 +00:00
|
|
|
} }
|
2013-11-22 21:38:30 +00:00
|
|
|
|
|
|
|
#endif
|