Skip to content

MDL roundtrip loses original view coordinates due to compose_views offset #401

Description

@bpowers

Problem

When multiple MDL views are parsed, compose_views (in src/simlin-engine/src/mdl/view/processing.rs) stacks views vertically starting at (100, 120), applying an additive coordinate offset. This offset is NOT reversed during MDL writing. The roundtripped coordinates differ from the originals by a constant offset per view (e.g., +18 for x, +112 for y in view 1 of mark2.mdl).

This does not affect simulation correctness, but will confuse Vensim users who open a roundtripped file and find their diagram layout shifted.

Components affected

  • src/simlin-engine/src/mdl/view/processing.rs (compose_views function)
  • src/simlin-engine/src/mdl/writer.rs (MDL serialization path)

Why it matters

  • User experience: Vensim users expect opening a roundtripped MDL file to show the same layout they saved. Shifted coordinates break that expectation.
  • Roundtrip fidelity: MDL roundtrip tests currently must accept coordinate offsets as known divergences rather than asserting exact equality.

Possible approaches

  1. Store original coordinates in ViewElementCompat -- preserve the pre-transformation coordinates alongside the composed ones, and use the originals when writing back to MDL.
  2. Skip coordinate transformation for MDL-sourced models -- avoid applying the compose_views offset when the source format is MDL, since Vensim handles multi-view layout itself.
  3. Reverse the transformation during writing -- compute the view segment's min_x/min_y and subtract the offset when serializing back to MDL.

Context

Identified during MDL roundtrip fidelity work on the mdl-roundtrip-fidelity branch. The mark2.mdl test model demonstrates the issue clearly with its multiple views.

Activity

  1. added
    engineIssues with the rust-based simulation engine
    compatCompatibility (XMILE, Vensim, etc) problem or enhancement
    on Jun 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    compatCompatibility (XMILE, Vensim, etc) problem or enhancementengineIssues with the rust-based simulation engine

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions