linebender / linebender/vello

Precision Issues in Flattening Straight Lines When Rendering DWG with Vello

Open
#1,139 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
4.3k
Forks
300
Avg merge
2d 13h
Merged PRs (30d)
61

Description

I am attempting to use Vello to render a DWG file and have encountered an issue where straight lines in the scene exhibit artifacts during the flattening process. Below is a minimal code snippet to reproduce the problem:

Image

let stroke = Stroke::new(2.0).with_caps(vello::kurbo::Cap::Butt);
let stroke_color = Color::new([1., 0.0, 0.0, 1.]);
let line = Line::new((41550.906, 4632.2827), (41550.926, 4632.273));
scene.stroke(
    &stroke,
    Affine::new([853.3334, 0.0, 0.0, -1360.7974, -35455741.0, 6302581.5]),
    stroke_color,
    None,
    &line,
);

After debugging, I suspect the root cause may lie in the use of local-space cubic coordinates during the WGSL flattening pass. The floating-point precision of the line data appears insufficient to maintain accuracy in calculations, particularly for straight segments.

**Key Questions:​**​

1. ​**​Known Issue?​**​ Is this a recognized problem, or has it been reported previously?
2. ​**​Precision Limitation?​**​ Could this be caused by floating-point precision constraints (e.g., IEEE-754 single-precision limitations)? 
3. ​**​Coordinate Space Choice:​**​ The code comment states: _"Flatten in local coordinates if this is a stroke. Flatten in device space otherwise."_ Why is stroke flattening restricted to local space? Performing this in device space would confine point values to screen-aligned ranges, potentially mitigating float precision issues. What are the technical barriers to this approach?
4. Through debugging, I confirmed that the issue is related to the ​**​curve flattening logic in the `flatten_euler` stage​**​. To validate this, ​**​I switched to v1.0 for comparison testing, and the problem no longer occurred​**​,

​**​Additional Context:​**​
- The artifact manifests as jagged or misaligned straight lines post-flattening.
- Floats in local space may span large numerical ranges (e.g., CAD coordinates), exacerbating precision loss when scaled. Device-space coordinates are bounded by screen resolution, offering higher effective precision.

We would appreciate clarification on these points to determine whether this is a bug, limitation, or configuration error. Thank you for your insights!

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the minimal Rust reproduction in the issue and inspect the curve-flattening logic at the flatten_euler stage, especially the local-space cubic coordinates. Compare its behavior with v1.0, where the problem reportedly does not occur. Done means the provided straight-line scene renders without jagged or misaligned artifacts, with the precision or coordinate-space cause understood.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
computer-graphics
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.