diff --git a/src/edt/edt/edtServiceImpl.cc b/src/edt/edt/edtServiceImpl.cc index 462794098..99b79163a 100644 --- a/src/edt/edt/edtServiceImpl.cc +++ b/src/edt/edt/edtServiceImpl.cc @@ -365,54 +365,35 @@ PolygonService::do_mouse_click (const db::DPoint &p) void PolygonService::do_finish_edit () { - // one point is reserved for the current one - if (m_points.size () < 4) { - throw tl::Exception (tl::to_string (QObject::tr ("A polygon must have at least 3 points"))); - } - m_points.pop_back (); - - deliver_shape (get_polygon (true /*compress*/)); + deliver_shape (get_polygon ()); } db::Polygon -PolygonService::get_polygon (bool compress) const +PolygonService::get_polygon () const { db::Polygon poly; + if (m_points.size () < 4) { + throw tl::Exception (tl::to_string (QObject::tr ("A polygon must have at least 3 points"))); + } + std::vector points_dbu; - points_dbu.reserve (m_points.size () + 1); - for (std::vector::const_iterator p = m_points.begin (); p != m_points.end (); ++p) { + points_dbu.reserve (m_points.size ()); + + // one point is reserved for the current one + for (std::vector::const_iterator p = m_points.begin (); p + 1 != m_points.end (); ++p) { points_dbu.push_back (trans () * *p); } if (m_closure_set) { points_dbu.push_back (trans () * m_closure); } - if (compress) { - - std::vector::iterator wp = points_dbu.begin (); - - db::Point p0 = points_dbu.back (); - - for (std::vector::const_iterator p = points_dbu.begin (); p != points_dbu.end (); ++p) { - - db::Point p1 = *p; - db::Point p2 = (p + 1 == points_dbu.end () ? points_dbu [0] : p[1]); - - if (db::vprod_sign (db::Vector (p0, p1), db::Vector (p1, p2)) != 0) { - *wp++ = p1; - } - - p0 = p1; - - } - - points_dbu.erase (wp, points_dbu.end ()); + poly.assign_hull (points_dbu.begin (), points_dbu.end (), true, true /*remove reflected*/); + if (poly.hull ().size () < 3) { + throw tl::Exception (tl::to_string (QObject::tr ("A polygon must have at least 3 effective points"))); } - poly.assign_hull (points_dbu.begin (), points_dbu.end (), false); - return poly; } diff --git a/src/edt/edt/edtServiceImpl.h b/src/edt/edt/edtServiceImpl.h index 503581144..3f305c0a2 100644 --- a/src/edt/edt/edtServiceImpl.h +++ b/src/edt/edt/edtServiceImpl.h @@ -100,7 +100,7 @@ private: db::DPoint m_last; void update_marker (); - db::Polygon get_polygon (bool compress) const; + db::Polygon get_polygon () const; void add_closure (); void set_last_point (const db::DPoint &p); };