Skip to content

Instantly share code, notes, and snippets.

msbarry /
Last active May 24, 2020
Visvalingam vs. Douglas-Peucker

Two well-known algorithms for polyline simplification are the Douglas Peucker and Visvalingam algorithms.

The Douglas Peucker algorithm uses a recursive divide-and-conquer approach. It starts by drawing a straight line from the first point to the last point. Then it finds the intermediate point that is furthest away from the straight line and deems this the "most important" and splits the polyline into two halves at that point. This process is repeated on both halves until the distance of the intermediate point is below a certain threshold, after which all points on that sub-polyline are thrown away since they have a negligible impact on the overall shape.

The Visvalingam algorithm works from the inside-out. It starts by computing the area of the triangle formed by each consecutive three points along the polyline. Then the midpoint of the triangle with the least area is thrown out since those three points are the closest to colinear and the area of triangles on either side are recomputed. The process

gruber / Liberal Regex Pattern for Web URLs
Last active Jun 14, 2021
Liberal, Accurate Regex Pattern for Matching Web URLs
View Liberal Regex Pattern for Web URLs
The regex patterns in this gist are intended only to match web URLs -- http,
https, and naked domains like "". For a pattern that attempts to
match all URLs, regardless of protocol, see:
# Single-line version:
staltz /
Last active Jun 19, 2021
The introduction to Reactive Programming you've been missing