Coder Social home page Coder Social logo

Comments (3)

hfutrell avatar hfutrell commented on August 19, 2024

Hello @mbutterick

Thank you once again for the level of detail you've gone into opening this issue.

I believe that what's going on here is that offset doesn't work properly with corners. I haven't given the offset method the attention it should get to ensure correctness. The behavior you're seeing at 90 degree corners where the point moves 1/2 the expected distance is because the code to compute the corner position is based on taking the average of the point's position if it were moved along one edge (vertically) and moved along the other edge (horizontally). The code needs a better approach.

from bezierkit.

mbutterick avatar mbutterick commented on August 19, 2024

Instead of using a linear average of the startPoint and endPoint of curves that are noncontiguous after offset, I propose that the better idea is to project the intersection of the two segments, and then move the startPoint and endPoint of the offset curves to that intersection.

Here’s how that looks using the original test cases, still applying offset(10).

All curves

In this case, no change. Just like before, each on-curve point is shifted in the offset direction by 10 units.

Screen Shot 2021-10-20 at 1 56 31 PM
Screen Shot 2021-10-20 at 1 56 42 PM

All straights

Previously, with linear averaging, the points were only moving a net 5 units from their original positions. But with projection, they all move 10 points.

Screen Shot 2021-10-20 at 1 56 56 PM
Screen Shot 2021-10-20 at 1 57 03 PM

Mix of curves and straights

Previously, with linear averaging, the straight segments were moving only half the distance, but curve points were moving the full distance, resulting in top and bottom edges that were no longer horizontal. With projection, however, every point moves the correct distance, and parallelism is preserved:

Screen Shot 2021-10-20 at 1 57 09 PM
Screen Shot 2021-10-20 at 1 57 14 PM

from bezierkit.

mbutterick avatar mbutterick commented on August 19, 2024

PR #98 shows how I did this, though it is not offered as a fully tested work of art.

from bezierkit.

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.