Code Monkey home page Code Monkey logo

Comments (9)

dbrgn avatar dbrgn commented on September 18, 2024 1

@nical I'll try to reproduce it, will let you know once I have a working minimal example :)

from lyon.

nical avatar nical commented on September 18, 2024 1

Equivalent bug filed against Gecko (this code being a straightforward port of Gecko's path flattening code): https://bugzilla.mozilla.org/show_bug.cgi?id=1360143

from lyon.

nical avatar nical commented on September 18, 2024

Thanks for filing this, I'll try to find the time to look into this this week.

from lyon.

nical avatar nical commented on September 18, 2024

@dbrgn what was the value of the tolerance threshold you used to reproduce this bug?

from lyon.

dbrgn avatar dbrgn commented on September 18, 2024

@nical good point. I believe it was 0.15.

from lyon.

nical avatar nical commented on September 18, 2024

I have tried to reproduce this by walking over the space of tolerance thresholds from 0.0000001 to 1.5 by increment of 0.0000001. And I haven't managed to get the flattening code to generate a straight line (see test below).

#[test]
fn test_issue_19() {
    let mut tolerance = 0.0000001;
    while tolerance < 1.5 {
        let c1 = CubicBezierSegment {
            from: Point::new(11.71726, 9.07143),
            ctrl1: Point::new(-9.827381, 4.15774),
            ctrl2: Point::new(6.425594, 10.20536),
            to: Point::new(6.425594, 10.20536),
        };
        let iter_points: Vec<Point> = c1.flattening_iter(tolerance).collect();
        let mut builder_points = Vec::new();
        c1.flattened_for_each(tolerance, &mut|p|{ builder_points.push(p); });

        assert_approx_eq(&iter_points[..], &builder_points[..]);

        if iter_points.len() <= 1 {
            print!(" tolerance {}", tolerance);
            print!(" points {:?}", iter_points);
            panic!();
        }

        tolerance += 0.0000001;
    }
}

I also tried to see it with the stroke tessellator using the example renderer and some hand picked threshold values (unfortunately can't try a gazillion of them manually). I did find a bug in the tessellator that is independent of the tolerance value, and looks unrelated to your issue.

So there must be something else rounding/nudging/affecting the coordinates or threshold before flattening or whatnot. @dbrgn do you have some code online that I can look at to see what else could be affecting your test case?
Which version of the crate are you using exactly?

from lyon.

dbrgn avatar dbrgn commented on September 18, 2024

Cargo.toml:

[package]
name = "straightline"
version = "0.1.0"
authors = ["Danilo Bargen <[email protected]>"]

[dependencies]
lyon_bezier = "^0.4"

main.rs:

extern crate lyon_bezier;

use lyon_bezier::{CubicBezierSegment, Vec2};

const FLATTENING_TOLERANCE: f32 = 0.15;

fn main() {
    println!("Hello, world!");

    let segment1 = CubicBezierSegment {
        from: Vec2::new(11.71726, 9.07143),
        ctrl1: Vec2::new(1.889879,13.22917),
        ctrl2: Vec2::new(18.142855,19.27679),
        to: Vec2::new(18.142855,19.27679),
    };
    println!("\nSegment: {:?}", segment1);
    for point in segment1.flattening_iter(FLATTENING_TOLERANCE) {
        println!("Point: {:?}", point);
    }

    let segment2 = CubicBezierSegment {
        from: Vec2::new(11.71726, 9.07143),
        ctrl1: Vec2::new(1.889879,13.22917),
        ctrl2: Vec2::new(18.142855,19.27679),
        to: Vec2::new(18.142855,19.27678),
    };
    println!("\nSegment: {:?}", segment2);
    for point in segment2.flattening_iter(FLATTENING_TOLERANCE) {
        println!("Point: {:?}", point);
    }

}

(Difference in segment1 and segment2: The last digit of to)

Output:

Hello, world!

Segment: CubicBezierSegment { from: (11.71726,9.07143), ctrl1: (1.889879,13.22917), ctrl2: (18.142855,19.27679), to: (18.142855,19.27679) }
Point: (18.142855,19.27679)

Segment: CubicBezierSegment { from: (11.71726,9.07143), ctrl1: (1.889879,13.22917), ctrl2: (18.142855,19.27679), to: (18.142855,19.27678) }
Point: (9.118064,10.766278)
Point: (8.563201,12.285181)
Point: (9.191999,13.824334)
Point: (11.197831,15.699478)
Point: (14.99445,17.905596)
Point: (18.142855,19.27678)

from lyon.

nical avatar nical commented on September 18, 2024

Thanks for the test case, it looks like some precision issue in find_cubic_bezier_inflection_approximation_range, I need to delve back into the maths to understand why that is but it is indeed related to the control points being very close to one another.

from lyon.

nical avatar nical commented on September 18, 2024

Fixed in #20.

from lyon.

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.