Giter Site home page Giter Site logo

csteuer / linesegmentsintersectionsplitter Goto Github PK

View Code? Open in Web Editor NEW
5.0 1.0 1.0 97 KB

An algorithm for splitting line segments at their intersections.

License: MIT License

CMake 14.60% C++ 65.88% C 0.66% Python 18.65% Shell 0.21%
computational-geometry c-plus-plus line-intersection

linesegmentsintersectionsplitter's Introduction

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:

mkdir build
cd build
cmake ..
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:

git clone https://github.com/google/googletest.git
cd build
cmake .. -DBUILD_TESTS=ON
./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

#include <intersectionsplitter/intersectionsplitter.h>
#include <intersectionsplitter/printutils.h>

int main(int, char**) {

    std::vector<intersectionsplitter::LineSegmentPtr> input = {
        intersectionsplitter::LineSegment::create(0,2, 4,2),
        intersectionsplitter::LineSegment::create(2,4, 2,0)
    };

    std::cout << "Splitting: " << std::endl << input << std::endl;

    std::vector<intersectionsplitter::LineSegmentPtr> result = intersectionsplitter::splitLineSegmentsAtIntersections(input);

    std::cout << "Result: " << std::endl << result;

    return 0;

}

Output:

Splitting:
[s: (0, 2), e: (4, 2), len: 4]
[s: (2, 4), e: (2, 0), len: 4]

Result:
[s: (2, 2), e: (2, 0), len: 2]
[s: (2, 2), e: (4, 2), len: 2]
[s: (2, 4), e: (2, 2), len: 2]
[s: (0, 2), e: (2, 2), len: 2]

linesegmentsintersectionsplitter's People

Contributors

csteuer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

robinlzw

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.