项目作者: csteuer

项目描述 :
An algorithm for splitting line segments at their intersections.
高级语言: C++
项目地址: git://github.com/csteuer/LineSegmentsIntersectionSplitter.git
创建时间: 2015-04-11T18:48:43Z
项目社区:https://github.com/csteuer/LineSegmentsIntersectionSplitter

开源协议:MIT License

下载


LineSegmentsIntersectionSplitter

Build Status

Calculates the intersections of a set of line segments and splits the line segments at their intersections.
Implements a modified version of the Bentley–Ottmann algorithm described in de Berg, Mark, et al. Computational Geometry: Algorithms and Applications (2008).

Dependencies

Requires gcc 4.7+ or clang 3.1+, cmake 2.8.12+, gmock 1.7+ for building the tests (optional),
hayai for building the benchmarks (optional) and doxygen for generating the documentatíon (also optional).

How to build

In the project root run:

  1. mkdir build
  2. cd build
  3. cmake ..
  4. make

To install the library at the location defined by the CMAKE_INSTALL_PREFIX variable run make install inside the build directory.

Set STATIC_INTERSECTIONSPLITTER=ON to build a static library (shared by default).

Run make doc to generate the documentation (doxygen must be installed and and found by cmake).

Build and run the tests

Clone googletest into <project-root>/googletest and set the cmake variable BUILD_TESTS=ON:

  1. git clone https://github.com/google/googletest.git
  2. cd build
  3. cmake .. -DBUILD_TESTS=ON
  4. ./intersectionsplitter/tests/intersectionsplitter-tests

Build and run the benchmarks

Install hayai, set the cmake variable BUILD_BENCHMARKS=ON then run the benchmark executable.

How to use

  1. #include <intersectionsplitter/intersectionsplitter.h>
  2. #include <intersectionsplitter/printutils.h>
  3. int main(int, char**) {
  4. std::vector<intersectionsplitter::LineSegmentPtr> input = {
  5. intersectionsplitter::LineSegment::create(0,2, 4,2),
  6. intersectionsplitter::LineSegment::create(2,4, 2,0)
  7. };
  8. std::cout << "Splitting: " << std::endl << input << std::endl;
  9. std::vector<intersectionsplitter::LineSegmentPtr> result = intersectionsplitter::splitLineSegmentsAtIntersections(input);
  10. std::cout << "Result: " << std::endl << result;
  11. return 0;
  12. }

Output:

  1. Splitting:
  2. [s: (0, 2), e: (4, 2), len: 4]
  3. [s: (2, 4), e: (2, 0), len: 4]
  4. Result:
  5. [s: (2, 2), e: (2, 0), len: 2]
  6. [s: (2, 2), e: (4, 2), len: 2]
  7. [s: (2, 4), e: (2, 2), len: 2]
  8. [s: (0, 2), e: (2, 2), len: 2]