Giter VIP home page Giter VIP logo

simpleline's Introduction

simpleline GoDoc

Simpleline simplifies N dimensional lines using the Ramer–Douglas–Peucker algorithm.

It is a port of https://github.com/mourner/simplify-js by Vladimir Agafonkin, extended to support N dimensions and custom metrics (distance functions).

Usage

To use simpleline, you provide a slice of Point objects.

Point is an interface defined by:

type Point interface {
	Vector() []float64
	Scale(float64) Point
	Subtract(Point) Point
	Zero() Point
}

A three dimensional point, Point3d, is provided. You can use use it in 2D if you want.

You simplify your list of points by calling

points := []Point{...}

results, err := simpleline.RDP(points, 5, simpleline.Euclidean, true)
if err != nil {
	// handle error
}

simpleline.RDP is called like:

simpleline.RDP(points, epsilon, metric function, simplify first?)

Custom metric

The Euclidean metric is provided. You can implement your own function that satisfies the Metric interface.

type Metric func(Point, Point) float64

Caveats

You could get better performance. For example, this implementation uses vector math and calculates the actual distance rather than its square.

Be careful with floats near MaxFloat64.

simpleline's People

Contributors

deet avatar

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.