GithubHelp home page GithubHelp logo

mourner / simplify-js Goto Github PK

View Code? Open in Web Editor NEW
2.3K 57.0 206.0 729 KB

High-performance JavaScript polyline simplification library

Home Page: http://mourner.github.io/simplify-js

License: BSD 2-Clause "Simplified" License

JavaScript 100.00%

simplify-js's People

Contributors

andriichumak avatar anotheredward avatar are avatar deniscarriere avatar dhritzkiv avatar fnicollet avatar fungiboletus avatar imshz avatar kade-robertson avatar mourner avatar odlp avatar shubhamjain avatar turbo87 avatar yhara avatar yrsh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

simplify-js's Issues

straight lines issue

I convert your code to a language I'm using.
But it's not possible to get only the 'important' points if needed.

Maybe I can't use your code, maybe I can, I don't know.

Look at this image: http://s16.postimg.org/afccosymd/test_col.png
I have the exact outline coordinate's, what I need is only the corners (in this case)
So 16 x,y points.

When I set the tolerance using your script very high, it will create gaps inside the corners...

Always return 2 points of polyline

i have got array of points (x,y) and i need to reduce points of polyline.

const rawLine = '109.550362,18.337531;109.550401,18.337592;.......more than 1k points;109.561543,18.238463;109.561631,18.238322'

const line = rawLine.split(";").map((point) => {
  const [x, y] = point.split(",");
  return {
    x: Number(x),
    y: Number(y),
  };
});
const simplified = simplify(line, {
  tolerance: 0.001,
});

always return 2 points.

what it is not work?

Unable to return complex polygon shapes without coordinate 'inflation'

I've noticed a small bug in the simplify() function. I've had trouble with the resulting coordinates almost always being 4-7 length polygons. The answer is to inflate the coordinates before and after, e.g. by a factor of 1000. Only once these values pass through the function are the results useful...

asm.js

Just a thought at this point, but I'm curious whether this could be substantially faster if some functions could be re-written to be asm.js-compatible. Do you have any thoughts?

geojson

hi, is there a way to simplify geoJSON with this awesome algorithm??

Are there any plans for Catmull-Rom smoothing?

I'm using the lib in a project I'm on:

It works flawlessly and is pretty fast(which is critical, I'm working with very tight performance tolerances)
I'm using it to simplify a pencil line that a user can draw on a canvas. Having less points makes it ideal for real-time collaboration since there's not too much data to transmit between each client for each path.

However, I'd love if there was also smoothing available through the lib.
Most of the smoothing algorithms won't really work since they are distorting the original path.

However Centripetal Catmull–Rom smoothing can actually work since it:

  • Does not self-intersect on tight corners
  • Fits much more snug on the points given

Are there any plans to allow such sort of smoothing through Simplify.js?

An image for comparing between the different Catmull-Rom interpolations:

image

How to utilize with stroke data including pressure/z-axis data?

Love this great little utility.

I'm working with a sketch application that receives pressure data, and applies it to the resulting stroke (width and/or density...etc). I suppose it could considered x, y & z axis data.

I'd love to simplify the curves from the user's raw input, but I need to reapply the pressure data, along with the point locations for the idealized curve.

Do you have any suggestions how that could be done with simplify-js? Any help would be appreciated. :)

Coordinates

I have a problem with the simplify function. I have an array with latitude and longitude of each point. It's like ["45.00", "11.20"]. I noticed that in every example are used values like 200.
i think i will need to convert them. How can i convert from lat and lon to x and y?

Thank you

Return copy of original points

This may be by design, but should copies of the original points be returned instead of references?

For example:

> a = [{x:0,y:0},{x:1,y:1},{x:2,y:2}];
[object Object],[object Object],[object Object]
> b = simplify(a, 0.8, false);
[object Object],[object Object]
> b[0].x = 5;
5
> a[0].x
5

I would be happy to make a Pull Request, but I wanted to see if this is your preference first.

Getting only 2 results back

Hi I am using the latest version of this lib but I am having issues

My input data are lat,long and I do convert them to x,y

 const b = positions.map((position) => {
            return {x: position.latitudeDegrees , y: position.longitudeDegrees}

          });

Screenshot 2019-07-22 at 12 50 10

Then

          const a  = simplify(b, 0.1, true);

Screenshot 2019-07-22 at 12 50 20

However the result only has a 2 item array.

(also the lib is not published related to latest master)

Feature Request: time component

Is there a simple way to consider / include time series data (or an arbitrary extra component/unit) or is this better left to post processing? E.g something that could solve for the following:

// a simple track
const timed = [
  { x: 0, y: 0, t: 0},
  { x: 0, y: 1, t: 1}, // speed == 1/t
  { x: 0, y: 1, t: 2}, // speed == 0
  { x: 1, y: 0, t: 3}, // speed == 1
];

simplify(timed, 0.5);
/* Shows losing time context through over-simplification
[
  { x: 0, y: 0, t: 0},
  { x: 0, y: 1, t: 1}, // speed == 1
  { x: 1, y: 0, t: 3}, // speed == 0.5
];
*/

Maximum call stack size exceeded

When operating on large data sets (array of 20K+ {x,y} objects), the library throws the stack size exceeded exception.

angular.js:13708 RangeError: Maximum call stack size exceeded
    at simplifyDPStep (simplify.js:71)
    at simplifyDPStep (simplify.js:85)
    at simplifyDPStep (simplify.js:85)
    at simplifyDPStep (simplify.js:85)
    at simplifyDPStep (simplify.js:85)
    at simplifyDPStep (simplify.js:85)
    at simplifyDPStep (simplify.js:85)
    at simplifyDPStep (simplify.js:85)
    at simplifyDPStep (simplify.js:85)
    at simplifyDPStep (simplify.js:85)

jam

you should upload it to jam it dosn't look like it needs any modifications for it to work with jam.

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.