Giter Club home page Giter Club logo

Comments (5)

Pomax avatar Pomax commented on May 30, 2024

Rather than (just) a zip file, can you show the code you're using in your post (or as follow-up comment) or as a jsbin link so that the code can be easily checked and interacted with by anyone who looks in on this issue tracker? The reduced example of what you're experiencing should not require all that much - just set up hardcoded list of the points you have (I assume these were abstracted with a RDP reduction while drawing 寸), and hardcoded the result of what comes out of any not-bezier-js code, so that the only real code that "does something" is the part where you feed points into bezier.js and ask it to do something for you.

Stackoverflow's guide on http://stackoverflow.com/help/mcve is a good read to understand how to form a good reduced example.

Bezier.js doesn't do any curve fitting, for instance, so the image in your issue looks fine to me: it's a single curve, with what looks like a correct red outline (and some extra blue offset curves for visual debugging?)

from bezierjs.

chengdu avatar chengdu commented on May 30, 2024

cannot be blank

from bezierjs.

Pomax avatar Pomax commented on May 30, 2024

Can you update that jsbin with a rawgit script instead of making lots of files in jsbin for each .js library? Because it looks like you made several jsbin files to act as script resources and then the JavaScript panel itself still has a huge file in it too, making it impossible to see the code you actually want to show (which, to ensure your script timings make sense, should be in that JS panel, not in the HTML source: don't put script code in your HTML, always load it with a script tag at the end of the DOM).

The following should work just fine in order to get the library included:

<script src="https://rawgit.com/Pomax/bezierjs/gh-pages/bezier.js"></script>

I'm happy to help figure this out, but I do need you to help me focus on "just the parts that go wrong": you have lots of code, almost none of it related or relevant to the problem. So, if I reduce your code to just importing bezier.js, and then only these lines:

var d = "M669 58L669 630L669 785C669 807.098 673.216 836.889 662.095 857C650.173 878.559 614.273 877.898 593 878.001C562.286 878.149 531.727 877.194 501 875.089C487.001 874.131 468.138 875.855 455 870.436C450.226 868.467 446.817 863.611 443 860.289C436.095 854.281 428.555 849.138 421 844M97 282L231 282L502 282L773 282L908 282M273 419C317.063 463.063 356.443 512.361 392.71 563C403.232 577.692 412.91 592.813 422.692 608C427.478 615.431 433.858 622.71 437 631";
var curve = Bezier.fromSVG(d);
var outline = curve.outline(25);

That's enough code to throw an error. When a minimal example is requested, really prune as much as you can because any code left in that isn't part of the problem, is a potential waste of time and effort in terms of seeing whether or not it's actually related to the problem. The above three lines, without any drawing code, and without any special HTML placeholder tags for content that will get slotted in later, is all we need to demonstrate this problem.

So with these three lines, we can see there are four possible problems that need investigation, instead of a million:

  • is the SVG path malformed
  • is the SVG path malformed as far as using it for constructing a Bezier curve goes
  • is the fromSVG function yielding a bad curve
  • is there a bug somewhere in the outline() code path.

Checking the SVG path: yes, for Bezier.js purposes this path is incredibly malformed because it's not a Bezier curve at all, it's a complex shape consisting of curve/line combinations as well as multiple subpaths.

Technically the fromSVG function is not part of the public, documented API, so you shouldn't really be relying on it to begin with, but it should work correctly when called correctly, and in this case you do not call it correctly: it is not for loading "arbitrary SVG pathing code". Bezier.js is a library for working with Bezier curves, not arbitrarily complex paths, and so fromSVG is a factory method for creating a single Bezier curve, from the SVG code for a single Bezier curve (a Q... or C... instruction).

Throwing anything more than a single curve's definition at it, like you're doing here, will absolutely break. If you want this kind of functionality, just use Paper.js or a similar library, instead.

from bezierjs.

chengdu avatar chengdu commented on May 30, 2024

cannot be blank

from bezierjs.

Pomax avatar Pomax commented on May 30, 2024

I have no intention for Bezier.js to be a general purpose pathing library. Please use something like Paper.js for that, it is easy to use and well written.

from bezierjs.

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.