How to use the svg-pathdata.SVGPathData.CLOSE_PATH function in svg-pathdata

To help you get started, we’ve selected a few svg-pathdata examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jasonwebb / 2d-diffusion-limited-aggregation-experiments / core / SVGLoader.js View on Github external
command.y
            ]);
            
            break;

          // ClosePath ('Z') commands are a naive indication that the current path can be processed and added to the world
          case SVGPathData.CLOSE_PATH:
            currentPath.closed = true;
            paths.push(currentPath);
            currentPath = {};
            currentPath.points = [];
            break;
        }

        // Unclosed paths never have CLOSE_PATH commands, so wrap up the current path when we're at the end of the path and have not found the command
        if(index == pathData.commands.length - 1 && command.type != SVGPathData.CLOSE_PATH) {
          let firstPoint = currentPath.points[0],
              lastPoint = currentPath.points[ currentPath.points.length - 1 ];

          // Automatically close the path if the first and last nodes are effectively the same, even if a CLOSE_PATH command doesn't exist
          if(Math.hypot(lastPoint.x - firstPoint.x, lastPoint.y - firstPoint.y) < .1) {
            currentPath.closed = true;
          } else {
            currentPath.closed = false;
          }

          paths.push(currentPath);
          currentPath = {};
          currentPath.points = [];
        }

        // Capture X coordinate, if there was one