Skip to content

chore(vis): simplify CartesianPlane interface - #320

Open
froyo-np wants to merge 7 commits into
mainfrom
noah/plane-compatible-with-plane
Open

froyo-np wants to merge 7 commits into
mainfrom
noah/plane-compatible-with-plane

Conversation

@froyo-np

@froyo-np froyo-np commented Oct 28, 2026 •

Copy link
Copy Markdown
Collaborator

What

  • Remove class "CartesianPlane"
  • Replace that class with a simple union of 3 literal strings: 'xy'|'xz'|'yz'
  • Replace class methods with free functions
  • move the whole idea out of geometry and into omezarr, even though now it would be safe to import/export from anywhere

Why

Because of how classes work in typescript / javascript, different "versions" of the same class may not be assignable to each other. In particular, classes with private data (marked with the # prefix) are incompatible. This becomes a problem when you look at the cross-dependencies in this codebase. The example of this is a consuming project which imports both vis-geometry and vis-omezarr. Imagine the following: your project imports version 0.1 of vis-geometry, and version 0.1 of vis-omezarr. Now, you need a new feature from vis-geometry: for example 3D rotation math, completely unrelated to ome-zarr rendering in any way - so you update the version of vis-geometry to 0.2, and leave vis-omezarr alone. The result is that you have 2 definitions of the class CartesianPlane, both literally identical. one is transitive via the import of vis-omezarr@0.1 and the other is from vis-geometry@0.2.

instances of these classes cannot be assigned to each other! This is a problem because the code your consuming project uses to pass in a plane into the code provided by vis-omezarr can only see one of them - the one from vis-geometry@0.2 - you have no choice but to use the direct dependency version, but code in vis-omezarr@0.1 expects one that matches its transitive dependency. In essence, this is because classes are are nominally typed - despite being identical in source code, their prototype chains do not overlap.

How

the fix is to realize a few things:

  1. the data in CartesianPlane is not particularly mathematical - most "geometry" libraries would define a plane by way of its normal vector, so this class isn't a great fit for that package.
  2. even as a Class - the CartesianPlane can only exist in 1 of 3 states - the remaining fields exist to simplify the derivation of information about the plane - eg. what axis is orthogonal to the plane, etc.
  3. By leaning on structural typing (in this case, a union of literal strings), we can create a representation of these 3 states that is compatible with any version of itself, or itself by any other name - this is a win with regard to library ergonomics.
  4. Could we have simply moved the class out of vis-geometry and into vis-omezarr? Yes - that would have worked for the problem scenario described above, although it could re-appear in more exotic transitive dependency scenarios.

Screenshots

This section is optional if there are no visible changes

  • If possible add screenshots of the visible additions in the UI.
  • If there are changes in the UI, add Before and After Screenshots for quick overview.
  • If there was a Figma design, add a link to that here as well.
  • Hint : Drag and Drop any images you want to add to the PR. Also you can create a gif of an interactive version and add that!

PR Checklist

  • Is your PR title following our conventional commit naming recommendations?
  • Have you filled in the PR Description Template?
  • Is your branch up to date with the latest in main?
  • Do the CI checks pass successfully?
  • Have you smoke tested the example applications?
  • Did you check that the changes meet accessibility standards?
  • Have you tested the application on these browsers?
    • Chrome (Fully supported)
    • Firefox (Major bug fixes supported)
    • Safari (Major bug fixes supported)

@froyo-np
froyo-np requested a review from a team as a code owner October 28, 2026 18:05
@froyo-np
froyo-np requested review from Jarbuckle, TheMooseman, lanesawyer and suyli7 and removed request for TheMooseman and suyli7 October 28, 2026 18:05

@Jarbuckle Jarbuckle left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would argue this is more of a dependency management problem than a typing problem. It's entirely logical and understandable that two versions of a class would be incompatible -- they're supposed to be, since a major purpose of classes is to enable encapsulation.

Because of the shape of Vis as a multi-package library, we do allow devs to install potentially conflicting versions of base packages -- this is helpful because it gives devs the option to select only what they need, but it also allows them to potentially shoot themselves in the foot.

An alternate solution in this case (besides just moving the class into vis-omezarr) would be to make vis-geometry a peer dependency for vis-omezarr, so it would use whichever version the devs have installed, as long as it's within a valid version range.

Using structural typing does indeed have the advantages you're pointing out! But it also has a drawback: our ability to change the implementation of the cartesian plane construct in the future becomes significantly hampered. You just noted that typically they would be implemented differently; if we wanted to make that change later on for any number of reasons, the cost of making the needed changes (not to mention the downstream cost of upgrading) becomes noticeably steeper using structural typing than with nominal typing, since the data implementation is exposed and not encapsulated.

So. All that said: this can become a very, very pedantic discussion! Your implementation works totally fine with Vis as it is, since the majority of the library is already structurally-typed. I just have misgivings from a long-term software health perspective.

@lanesawyer lanesawyer left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I lean towards preferring the more functional style over class style, so I like what I see here.

But Joel has a good point that we need to manage dependencies better. I think we should move towards peerDependencies in general for the lower-level vis libraries!

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants