Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Geos #443

Closed
wants to merge 6 commits into from
Closed

Geos #443

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
24 changes: 24 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ jobs:
matrix:
os: [ubuntu, macos]
boost: [1_60_0, 1_66_0]
geos: ["3.8.1", ""]
compiler: ['g++', 'g++-8', 'clang++']
exclude:
- os: macos
Expand All @@ -23,6 +24,7 @@ jobs:
- os: ubuntu
boost: 1_66_0
compiler: g++-8
geos: "3.8.1"
code_coverage: "--enable-code-coverage"
- boost: 1_60_0
skip_gerberimporter_tests: "SKIP_GERBERIMPORTER_TESTS=1"
Expand Down Expand Up @@ -74,6 +76,10 @@ jobs:
echo "::set-env name=PKG_CONFIG_PATH::$PKG_CONFIG_PATH:/usr/local/opt/libffi/lib/pkgconfig"
echo "::set-env name=CPPFLAGS_gerbv::-DQUARTZ"
echo "::set-env name=PATH::/usr/local/opt/gettext/bin:$PATH"
- name: Macos geos
if: matrix.geos != ""
run:
brew install geos
- name: Sanitize cache key
id: sanitize-key
run: echo "::set-output name=key::$(echo '${{ matrix.os }}_${{ matrix.boost }}_${{ matrix.compiler }}' | sed 's/+/plus/g')"
Expand Down Expand Up @@ -101,6 +107,24 @@ jobs:
popd
fi
echo "::set-env name=BOOST_ROOT::$(echo ${HOME}/.local)"
- name: Build and install geos
if: matrix.os == "ubuntu"
env:
GEOS: ${{ matrix.geos }}
run: |
if [ ! -d "${HOME}/.local/include/geos" ]; then
pushd ~
for i in {1..5}; do
wget -q -T20 -t1 -O "geos-${GEOS}.tar.bz2" "http://download.osgeo.org/geos/geos-${GEOS}.tar.bz2" && break;
done
tar xjf "geos-${GEOS}.tar.bz2"
pushd geos-${GEOS}
./configure --prefix=${HOME}/.local
./make -j ${NUM_CPUS}
./make install
popd
popd
fi
- name: coverage specific setup
if: matrix.code_coverage
run: |
Expand Down
4 changes: 2 additions & 2 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ ACLOCAL_AMFLAGS = -I m4
GIT_VERSION = `git describe --dirty --always --tags`
GERBV_VERSION = `pkg-config --modversion libgerbv`

AM_CPPFLAGS = $(BOOST_CPPFLAGS_SYSTEM) $(glibmm_CFLAGS) $(gdkmm_CFLAGS_SYSTEM) $(gerbv_CFLAGS) $(CODE_COVERAGE_CPPFLAGS) -DGIT_VERSION=\"$(GIT_VERSION)\" -Wall -Wpedantic -Wextra $(pcb2gcode_CPPFLAGS_EXTRA)
AM_CPPFLAGS = $(BOOST_CPPFLAGS_SYSTEM) $(glibmm_CFLAGS) $(gdkmm_CFLAGS_SYSTEM) $(gerbv_CFLAGS) $(CODE_COVERAGE_CPPFLAGS) -DGIT_VERSION=\"$(GIT_VERSION)\" -Wall -Wpedantic -Wextra $(pcb2gcode_CPPFLAGS_EXTRA) $(GEOS_CFLAGS) $(GEOS_EXTRA)
AM_CXXFLAGS = $(CODE_COVERAGE_CXXFLAGS) -DGIT_VERSION=\"$(GIT_VERSION)\" -DGERBV_VERSION=\"$(GERBV_VERSION)\"
AM_LDFLAGS = $(BOOST_PROGRAM_OPTIONS_LDFLAGS)
LIBS = $(gerbv_LIBS) $(BOOST_PROGRAM_OPTIONS_LIBS) $(CODE_COVERAGE_LIBS)
LIBS = $(gerbv_LIBS) $(BOOST_PROGRAM_OPTIONS_LIBS) $(CODE_COVERAGE_LIBS) $(GEOS_LIBS)

EXTRA_DIST = millproject

Expand Down
28 changes: 24 additions & 4 deletions bg_helpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
#define BG_HELPERS_H

#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

template <typename polygon_type_t, typename rhs_t>
static inline bg::model::multi_polygon<polygon_type_t> operator-(const bg::model::multi_polygon<polygon_type_t>& lhs,
Expand Down Expand Up @@ -194,18 +199,33 @@ static inline void buffer(multi_linestring_type_fp const & geometry_in, multi_po
geometry_out.clear();
return;
}
#ifdef GEOS_VERSION
geos::io::WKTReader reader;
std::stringstream ss;
ss << bg::wkt(geometry_in);
auto geos_in = reader.read(ss.str());
auto 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);
free(geos_out);
if (strncmp(geos_wkt.c_str(), "MULTIPOLYGON", 12) == 0) {
bg::read_wkt(geos_wkt, geometry_out);
} else {
polygon_type_fp poly;
bg::read_wkt(geos_wkt, poly);
geometry_out.clear();
geometry_out.push_back(poly);
}
#else
// 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);
geometry_out.clear();
if (expand_by == 0) {
return;
}
for (const auto& ls : mls) {
multi_polygon_type_fp buf;
buffer(ls, buf, expand_by);
geometry_out = geometry_out + buf;
}
#endif
}

template<typename CoordinateType>
Expand Down
9 changes: 9 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,15 @@ PKG_CHECK_MODULES([gdkmm], [gdkmm-2.4 >= 2.8])
PKG_CHECK_MODULES([gerbv], [libgerbv >= 2.1.0])
PKG_CHECK_MODULES([rsvg], [librsvg-2.0 >= 2.0])

# Optional GEOS, as a slower but more reliable replacement for Boost geometry.
GEOS_INIT
AS_IF([test "x$HAVE_GEOS" = "xyes"],
[AC_MSG_NOTICE([Found geos, we'll use it instead of some of the boost geometry for greater accuracy though it can be slower.])],
[AC_MSG_NOTICE([Didn't find geos, we'll use boost geometry for all geometry functions. If you see inaccuracy, try geos.])])
AS_IF([test "x$HAVE_GEOS" = "xyes"],
[AC_SUBST(GEOS_EXTRA, ["-DUSE_UNSTABLE_GEOS_CPP_API -DGEOS_VERSION=\\\"\$(GEOS_VERSION)\\\""])])


AC_SUBST([gdkmm_CFLAGS_SYSTEM], ['$(subst -I,-isystem ,$(gdkmm_CFLAGS))'])

AC_SUBST(gerbv_LIBS)
Expand Down
1 change: 1 addition & 0 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ void do_pcb2gcode(int argc, const char* argv[]) {
cout << "Git commit: " << GIT_VERSION << endl;
cout << "Boost: " << BOOST_VERSION << endl;
cout << "Gerbv: " << GERBV_VERSION << endl;
cout << "Geos: " << GEOS_VERSION "" << endl;
return;
}

Expand Down
Loading