Skip to content

SimplifyPaths

Seth Hillbrand edited this page Oct 29, 2026 · 2 revisions

Home › clipper.h › SimplifyPaths

SimplifyPaths

inline Path<T> SimplifyPath(const Path<T>& path, double epsilon,
 bool isClosedPath = true);
inline Paths<T> SimplifyPaths(const Paths<T>& path, double epsilon,
 bool isClosedPath = true);


This function removes vertices that are less than the specified epsilon distance from an imaginary line that passes through its 2 adjacent vertices. Logically, smaller epsilon values will be less aggressive in removing vertices than larger epsilon values.

This function is strongly recommended before offsetting (ie before inflating/shrinking) when paths may contain redundant segments. (See notes on redundant segments here.) And removing redundant segments is especially important when offsetting paths that have themselves been offset.

Example:

#include "../../Clipper2Lib/clipper.h"
#include "../../Utils/clipper.svg.h"
#include "../../Utils/clipper.svg.utils.h"
...
using namespace Clipper2Lib;

int main()
{
  SvgReader svg_reader;
  svg_reader.LoadFromFile("./rabbit.svg");
  PathsD p = svg_reader.GetPaths(), solution;

  while (p.size())
  {
    //copy each iteration of 'p' into solution until 'p' is no more
    solution.reserve(solution.size() + p.size());
    copy(p.begin(), p.end(), back_inserter(solution));

    p = InflatePaths(p, -2.5, JoinType::Round, EndType::Polygon);
    p = SimplifyPaths(p, 0.025);
  }

  SvgAddSolution(svg, solution, false);
  SvgSaveToFile(svg, "rabbit_offset.svg", 338, 540, 0);
}

See Also

ClipperOffset, InflatePaths

Clone this wiki locally