Skip to content

Commit

Permalink
Merge pull request #463 from eyal0/faster_compile
Browse files Browse the repository at this point in the history
Improve compile time by splitting up files
  • Loading branch information
eyal0 committed Jul 1, 2020
2 parents 8a0f6cf + 1aa4eec commit df978ac
Show file tree
Hide file tree
Showing 59 changed files with 963 additions and 802 deletions.
17 changes: 11 additions & 6 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ pcb2gcode_SOURCES = \
board.hpp \
board.cpp \
bg_helpers.hpp \
bg_helpers.cpp \
bg_operators.hpp \
bg_operators.cpp \
common.hpp \
common.cpp \
drill.hpp \
Expand Down Expand Up @@ -45,6 +48,8 @@ pcb2gcode_SOURCES = \
options.cpp \
outline_bridges.hpp \
outline_bridges.cpp \
svg_writer.hpp \
svg_writer.cpp \
units.hpp \
unique_codes.hpp \
voronoi.hpp \
Expand Down Expand Up @@ -74,19 +79,19 @@ check_PROGRAMS = voronoi_tests eulerian_paths_tests segmentize_tests tsp_solver_
available_drills_tests gerberimporter_tests options_tests path_finding_tests \
autoleveller_tests common_tests backtrack_tests trim_paths_tests
voronoi_tests_SOURCES = voronoi.hpp voronoi.cpp voronoi_tests.cpp boost_unit_test.cpp
eulerian_paths_tests_SOURCES = eulerian_paths_tests.cpp eulerian_paths.hpp geometry_int.hpp boost_unit_test.cpp
segmentize_tests_SOURCES = segmentize_tests.cpp segmentize.cpp segmentize.hpp merge_near_points.cpp merge_near_points.hpp boost_unit_test.cpp
path_finding_tests_SOURCES = path_finding_tests.cpp path_finding.cpp path_finding.hpp boost_unit_test.cpp
eulerian_paths_tests_SOURCES = eulerian_paths_tests.cpp eulerian_paths.hpp geometry_int.hpp boost_unit_test.cpp bg_operators.hpp bg_operators.cpp bg_helpers.hpp bg_helpers.cpp eulerian_paths.cpp segmentize.cpp merge_near_points.cpp
segmentize_tests_SOURCES = segmentize_tests.cpp segmentize.cpp segmentize.hpp merge_near_points.cpp merge_near_points.hpp boost_unit_test.cpp bg_helpers.hpp bg_helpers.cpp eulerian_paths.cpp bg_operators.hpp bg_operators.cpp
path_finding_tests_SOURCES = path_finding_tests.cpp path_finding.cpp path_finding.hpp boost_unit_test.cpp bg_helpers.cpp bg_helpers.hpp eulerian_paths.cpp eulerian_paths.hpp segmentize.hpp segmentize.cpp merge_near_points.cpp merge_near_points.hpp bg_operators.hpp bg_operators.cpp
tsp_solver_tests_SOURCES = tsp_solver_tests.cpp tsp_solver.hpp boost_unit_test.cpp
units_tests_SOURCES = units_tests.cpp units.hpp boost_unit_test.cpp
available_drills_tests_SOURCES = available_drills_tests.cpp available_drills.hpp boost_unit_test.cpp
gerberimporter_tests_SOURCES = gerberimporter.hpp gerberimporter.cpp gerberimporter_tests.cpp merge_near_points.hpp merge_near_points.cpp eulerian_paths.cpp eulerian_paths.hpp segmentize.cpp segmentize.hpp boost_unit_test.cpp
gerberimporter_tests_SOURCES = gerberimporter.hpp gerberimporter.cpp gerberimporter_tests.cpp merge_near_points.hpp merge_near_points.cpp eulerian_paths.cpp eulerian_paths.hpp segmentize.cpp segmentize.hpp boost_unit_test.cpp bg_helpers.cpp bg_helpers.hpp bg_operators.hpp bg_operators.cpp
gerberimporter_tests_LDFLAGS = $(glibmm_LIBS) $(gdkmm_LIBS) $(rsvg_LIBS)
options_tests_SOURCES = options_tests.cpp options.hpp options.cpp boost_unit_test.cpp
autoleveller_tests_SOURCES = autoleveller_tests.cpp autoleveller.hpp autoleveller.cpp options.cpp options.hpp boost_unit_test.cpp
common_tests_SOURCES = common.hpp common.cpp common_tests.cpp boost_unit_test.cpp
backtrack_tests_SOURCES = backtrack.hpp backtrack.cpp backtrack_tests.cpp boost_unit_test.cpp
trim_paths_tests_SOURCES = trim_paths.hpp trim_paths.cpp trim_paths_tests.cpp boost_unit_test.cpp
backtrack_tests_SOURCES = backtrack.hpp backtrack.cpp backtrack_tests.cpp boost_unit_test.cpp bg_helpers.hpp bg_helpers.cpp eulerian_paths.hpp eulerian_paths.cpp segmentize.hpp segmentize.cpp merge_near_points.hpp merge_near_points.cpp bg_operators.hpp bg_operators.cpp
trim_paths_tests_SOURCES = trim_paths.hpp trim_paths.cpp trim_paths_tests.cpp boost_unit_test.cpp bg_helpers.hpp bg_helpers.cpp eulerian_paths.hpp eulerian_paths.cpp segmentize.hpp segmentize.cpp merge_near_points.hpp merge_near_points.cpp bg_operators.hpp bg_operators.cpp

TESTS = $(check_PROGRAMS)

Expand Down
2 changes: 1 addition & 1 deletion backtrack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <algorithm>

#include "geometry.hpp"
#include "bg_helpers.hpp"
#include "bg_operators.hpp"

#include "backtrack.hpp"

Expand Down
1 change: 1 addition & 0 deletions backtrack_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <vector>

#include "geometry.hpp"
#include "bg_operators.hpp"
#include "bg_helpers.hpp"

#include "backtrack.hpp"
Expand Down
102 changes: 102 additions & 0 deletions bg_helpers.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
#include "eulerian_paths.hpp"
#ifdef GEOS_VERSION
#include <geos/io/WKTReader.h>
#include <geos/io/WKTWriter.h>
#include <geos/operation/buffer/BufferOp.h>
#endif // GEOS_VERSION

#include "bg_operators.hpp"
#include "bg_helpers.hpp"

namespace bg_helpers {

// The below implementations of buffer are similar to bg::buffer but
// always convert to floating-point before doing work, if needed, and
// convert back afterward, if needed. Also, they work if expand_by is
// 0, unlike bg::buffer.
const int points_per_circle = 32;

multi_polygon_type_fp buffer(multi_polygon_type_fp const & geometry_in, coordinate_type_fp expand_by) {
if (expand_by == 0) {
return geometry_in;
} else {
multi_polygon_type_fp geometry_out;
bg::buffer(geometry_in, geometry_out,
bg::strategy::buffer::distance_symmetric<coordinate_type_fp>(expand_by),
bg::strategy::buffer::side_straight(),
bg::strategy::buffer::join_round(points_per_circle),
bg::strategy::buffer::end_round(points_per_circle),
bg::strategy::buffer::point_circle(points_per_circle));
return geometry_out;
}
}

template<typename CoordinateType>
multi_polygon_type_fp buffer(polygon_type_fp const & geometry_in, CoordinateType expand_by) {
return buffer(multi_polygon_type_fp{geometry_in}, expand_by);
}

template multi_polygon_type_fp buffer(polygon_type_fp const&, double);

template<typename CoordinateType>
multi_polygon_type_fp buffer(linestring_type_fp const & geometry_in, CoordinateType expand_by) {
if (expand_by == 0) {
return {};
}
multi_polygon_type_fp geometry_out;
bg::buffer(geometry_in, geometry_out,
bg::strategy::buffer::distance_symmetric<coordinate_type_fp>(expand_by),
bg::strategy::buffer::side_straight(),
bg::strategy::buffer::join_round(points_per_circle),
bg::strategy::buffer::end_round(points_per_circle),
bg::strategy::buffer::point_circle(points_per_circle));
return geometry_out;
}

template<typename CoordinateType>
multi_polygon_type_fp buffer(multi_linestring_type_fp const & geometry_in, CoordinateType expand_by) {
if (expand_by == 0) {
return {};
}
// bg::buffer of multilinestring is broken in boost. Converting the
// multilinestring to non-intersecting paths seems to help.
multi_linestring_type_fp mls = eulerian_paths::make_eulerian_paths(geometry_in, true, true);
#ifdef GEOS_VERSION
geos::io::WKTReader reader;
std::stringstream ss;
ss << bg::wkt(mls);
auto geos_in = reader.read(ss.str());
std::unique_ptr<geos::geom::Geometry> geos_out(geos::operation::buffer::BufferOp::bufferOp(geos_in.get(), expand_by, points_per_circle/4));
geos::io::WKTWriter writer;
auto geos_wkt = writer.write(geos_out.get());
multi_polygon_type_fp ret;
if (strncmp(geos_wkt.c_str(), "MULTIPOLYGON", 12) == 0) {
bg::read_wkt(geos_wkt, ret);
} else {
polygon_type_fp poly;
bg::read_wkt(geos_wkt, poly);
ret.push_back(poly);
}
return ret;
#else
if (expand_by == 0) {
return {};
}
multi_polygon_type_fp ret;
for (const auto& ls : mls) {
ret = ret + buffer(ls, expand_by);
}
return ret;
#endif
}

template multi_polygon_type_fp buffer(const multi_linestring_type_fp&, double expand_by);

template<typename CoordinateType>
multi_polygon_type_fp buffer(ring_type_fp const & geometry_in, CoordinateType expand_by) {
return buffer(polygon_type_fp{geometry_in}, expand_by);
}

template multi_polygon_type_fp buffer(ring_type_fp const&, double);

} // namespace bg_helpers
Loading

0 comments on commit df978ac

Please sign in to comment.