Skip to content

Commit

Permalink
Move coordinate_type from geometry.hpp to geometry_int.hpp
Browse files Browse the repository at this point in the history
This will help prevent accidental usage of integral geometry, which is required
by some algorithms but is usually a mistake to use.
  • Loading branch information
eyal0 committed Oct 30, 2019
1 parent c7f2e55 commit 356c134
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 37 deletions.
3 changes: 2 additions & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pcb2gcode_SOURCES = \
eulerian_paths.cpp \
exporter.hpp \
geometry.hpp \
geometry_int.hpp \
gerberimporter.hpp \
gerberimporter.cpp \
importer.hpp \
Expand Down Expand Up @@ -69,7 +70,7 @@ check_PROGRAMS = voronoi_tests eulerian_paths_tests segmentize_tests tsp_solver_
available_drills_tests gerberimporter_tests options_tests path_finding_tests \
autoleveller_tests
voronoi_tests_SOURCES = voronoi.hpp voronoi.cpp voronoi_tests.cpp
eulerian_paths_tests_SOURCES = eulerian_paths_tests.cpp
eulerian_paths_tests_SOURCES = eulerian_paths_tests.cpp eulerian_paths.hpp geometry_int.hpp
segmentize_tests_SOURCES = segmentize_tests.cpp segmentize.cpp segmentize.hpp
path_finding_tests_SOURCES = path_finding_tests.cpp path_finding.cpp path_finding.hpp
tsp_solver_tests_SOURCES = tsp_solver_tests.cpp tsp_solver.hpp
Expand Down
11 changes: 0 additions & 11 deletions bg_helpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,17 +188,6 @@ static inline multi_polygon_type_fp buffer(polygon_type_fp const & geometry_in,
return geometry_out;
}

template<typename CoordinateType>
static inline void buffer(polygon_type const & geometry_in, multi_polygon_type_fp & geometry_out, CoordinateType expand_by) {
if (expand_by == 0) {
bg::convert(geometry_in, geometry_out);
} else {
polygon_type_fp geometry_in_fp;
bg::convert(geometry_in, geometry_in_fp);
buffer(geometry_in_fp, geometry_out, expand_by);
}
}

template<typename CoordinateType>
static inline void buffer(multi_linestring_type_fp const & geometry_in, multi_polygon_type_fp & geometry_out, CoordinateType expand_by) {
if (expand_by == 0) {
Expand Down
7 changes: 0 additions & 7 deletions eulerian_paths.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,6 @@
#include "geometry.hpp"

namespace eulerian_paths {
static inline bool operator !=(const point_type& x, const point_type& y) {
return std::tie(x.x(), x.y()) != std::tie(y.x(), y.y());
}

static inline bool operator ==(const point_type& x, const point_type& y) {
return std::tie(x.x(), x.y()) == std::tie(y.x(), y.y());
}

static inline bool operator !=(const point_type_fp& x, const point_type_fp& y) {
return std::tie(x.x(), x.y()) != std::tie(y.x(), y.y());
Expand Down
17 changes: 14 additions & 3 deletions eulerian_paths_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,22 @@
#include <boost/test/included/unit_test.hpp>

#include <tuple>
#include "geometry_int.hpp"

namespace eulerian_paths {

static inline bool operator !=(const point_type& x, const point_type& y) {
return std::tie(x.x(), x.y()) != std::tie(y.x(), y.y());
}

static inline bool operator ==(const point_type& x, const point_type& y) {
return std::tie(x.x(), x.y()) == std::tie(y.x(), y.y());
}

} // namespace eulerian_paths

#include "eulerian_paths.hpp"
#include "geometry_int.hpp"

using std::vector;
using namespace eulerian_paths;
Expand Down Expand Up @@ -44,9 +58,6 @@ BOOST_AUTO_TEST_CASE(window_pane) {
{8,9},
{1,4},
{4,7},



{2,5},
{5,8},
{3,6},
Expand Down
13 changes: 0 additions & 13 deletions geometry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
// This one chooses the resolution of the output (viewBox).
#define SVG_DOTS_PER_IN 2000

typedef int64_t coordinate_type;
typedef double coordinate_type_fp;
typedef double ivalue_t;

Expand All @@ -48,16 +47,6 @@ BOOST_GEOMETRY_REGISTER_POINT_2D(icoordpair, ivalue_t, cs::cartesian, first, sec
// Adaptation of icoords to Boost Geometry (ring)
BOOST_GEOMETRY_REGISTER_RING(icoords)

typedef boost::geometry::model::d2::point_xy<coordinate_type> point_type;
typedef boost::geometry::model::multi_point<point_type> multi_point_type;
typedef boost::geometry::model::segment<point_type> segment_type;
typedef boost::geometry::model::ring<point_type> ring_type;
typedef boost::geometry::model::box<point_type> box_type;
typedef boost::geometry::model::linestring<point_type> linestring_type;
typedef boost::geometry::model::multi_linestring<linestring_type> multi_linestring_type;
typedef boost::geometry::model::polygon<point_type> polygon_type;
typedef boost::geometry::model::multi_polygon<polygon_type> multi_polygon_type;

typedef boost::geometry::model::d2::point_xy<coordinate_type_fp> point_type_fp;
typedef boost::geometry::model::multi_point<point_type_fp> multi_point_type_fp;
typedef boost::geometry::model::segment<point_type_fp> segment_type_fp;
Expand All @@ -70,9 +59,7 @@ typedef boost::geometry::model::multi_polygon<polygon_type_fp> multi_polygon_typ

namespace bg = boost::geometry;

typedef boost::polygon::point_data<coordinate_type> point_type_p;
typedef boost::polygon::point_data<coordinate_type_fp> point_type_fp_p;
typedef boost::polygon::segment_data<coordinate_type> segment_type_p;
typedef boost::polygon::segment_data<coordinate_type_fp> segment_type_fp_p;

#endif
24 changes: 24 additions & 0 deletions geometry_int.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#ifndef GEOMETRY_INT_H
#define GEOMETRY_INT_H

#include <vector>
#include <boost/geometry.hpp>
#include <boost/geometry/geometries/point_xy.hpp>
#include <boost/geometry/geometries/geometries.hpp>
#include <boost/geometry/geometries/register/point.hpp>
#include <boost/geometry/geometries/register/ring.hpp>
#include <boost/polygon/polygon.hpp>

typedef int64_t coordinate_type;
typedef boost::geometry::model::d2::point_xy<coordinate_type> point_type;
typedef boost::geometry::model::ring<point_type> ring_type;
typedef boost::geometry::model::box<point_type> box_type;
typedef boost::geometry::model::linestring<point_type> linestring_type;
typedef boost::geometry::model::multi_linestring<linestring_type> multi_linestring_type;
typedef boost::geometry::model::polygon<point_type> polygon_type;
typedef boost::geometry::model::multi_polygon<polygon_type> multi_polygon_type;

typedef boost::polygon::point_data<coordinate_type> point_type_p;
typedef boost::polygon::segment_data<coordinate_type> segment_type_p;

#endif
2 changes: 1 addition & 1 deletion segmentize.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <vector>
#include <map>

#include "geometry.hpp"
#include "geometry_int.hpp"
#include <boost/polygon/isotropy.hpp>
#include <boost/polygon/segment_concept.hpp>
#include <boost/polygon/segment_utils.hpp>
Expand Down
2 changes: 1 addition & 1 deletion segmentize.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <vector>
#include <map>

#include "geometry.hpp"
#include "geometry_int.hpp"
#include <boost/polygon/isotropy.hpp>
#include <boost/polygon/segment_concept.hpp>
#include <boost/polygon/segment_utils.hpp>
Expand Down
1 change: 1 addition & 0 deletions voronoi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <memory>

#include "geometry.hpp"
#include "geometry_int.hpp"

namespace boost { namespace polygon { namespace detail {

Expand Down

0 comments on commit 356c134

Please sign in to comment.