Comments (9)
@nical I'll try to reproduce it, will let you know once I have a working minimal example :)
from lyon.
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.
Thanks for filing this, I'll try to find the time to look into this this week.
from lyon.
@dbrgn what was the value of the tolerance threshold you used to reproduce this bug?
from lyon.
@nical good point. I believe it was 0.15.
from lyon.
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.
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.
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.
Fixed in #20.
from lyon.
Related Issues (20)
- Finding close point on CubicBezierSegment HOT 3
- Cubic Bezier Segment not matching SVG? HOT 1
- Create git tags (and GitHub releases?) for crates.io releases HOT 6
- hit_test_path seems to report incorrect result with FillRule::EvenOdd HOT 1
- Update wgpu dependency in the examples HOT 2
- debug_assert can panic while not being necessarily justififed HOT 1
- Tesselator doesn't handle intersections between different paths very well HOT 4
- Add `offset` parameter to `HatchingOptions`
- Stroke tessellator seems to produce wrong results for some rounded path types HOT 5
- Lifetime issue when storing Tesselator::builder() in a struct and later resetting it HOT 4
- Stroke tessellator bad triangle HOT 1
- PathParser: can't parse path using scientific notation for numbers.
- `PathSampler::split_range` seems to disregard discontinuities in the original path HOT 3
- (breaking change) Typo "InvalidParamater" in lyon_tessellation
- Is there an example of using custom attributes? HOT 2
- `end_cap` seems to have no effect if its `LineCap::Square` HOT 1
- Arc angle starting position is unusual HOT 2
- Line intersection loses lot of accuracy HOT 1
- FillTesselator produces empty indices HOT 4
- Glam types HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lyon.