Giter Site home page Giter Site logo

Comments (4)

KTibow avatar KTibow commented on June 10, 2024

Z can be skipped under certain conditions (though what are they precisely?)

If the cursor is already at the home point and if it's safe. How do you determine if it's safe?

// This is how.
const isSafeToUseZ = maybeHasStroke
  ? computedStyle["stroke-linecap"]?.type === "static" &&
    computedStyle["stroke-linecap"].value === "round" &&
    computedStyle["stroke-linejoin"]?.type === "static" &&
    computedStyle["stroke-linejoin"].value === "round"
  : true;

If you're looking for help with implementation, consider that
a. you can already split paths into chunks by checking for move instructions
b. if you're trying to see if it's closed, just 1. keep track of the "home" point 2. keep track of the current cursor 3. see if the cursor is basically at the home point at the last command before the end or another move

from svgo.

alecmev avatar alecmev commented on June 10, 2024

Is isSafeToUseZ === !isSafeToSkipZ though? I feel like it isn't, no?

Also, as you can see with the triangle examples above, the stroke is not continuous despite the cursor arriving at the home point. So there must be some limit to the acuteness of the resulting corner, since the square does get auto-closed 🤔 These screenshots are from Firefox, just in case.

from svgo.

KTibow avatar KTibow commented on June 10, 2024

Is isSafeToUseZ === !isSafeToSkipZ though? I feel like it isn't, no?

You can look through the code, isSafeToUseZ === isSafeToSkipZ for all of SVGO's purposes. We define "safe" as not having a non-round stroke. It's really that simple.

Also, as you can see with the triangle examples above, the stroke is not continuous despite the cursor arriving at the home point.

You're correct, when you have a non-round stroke sometimes you can still skip z. However SVGO never skips z with a non-round stroke - I was initially planning to do so but the logic that converts lines to z if the following command is z is good enough.

from svgo.

alecmev avatar alecmev commented on June 10, 2024

Okay, I see, SVGO can be more aggressive if it's assumed that the image is used as-is. In our case, we later programmatically manipulate it and add/remove stroking, and change its style, the miter limit, etc. Would it make sense to have an option for this? Something like "don't remove Z if it could affect the behavior of any stroke cap/join style".

from svgo.

Related Issues (20)

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.