Scala.js and Java geom library

I wrote a Scala 3 project depending on this Java library
math.geom2d:javaGeom 0.11.1
for performing geometric computations.

I would like to compile my project for scala.js as well.

How can I achieve this result?

  • It seems not possible to use the dependency as is in a Scala JS project, if I am not mistaken. Are there solutions to somehow convert it or wrap it?

  • Or should I refactor the whole project to depend on a different equivalent Scala library that can be used for Scala JS as well? In case, any suggestion for a replacement?

Thank you,

Mario

I asked the same on the Scala JS discord channel and the initial reply is “go for replacement”.

Then I went thorugh ScalaDex Search geometry and did not find anything comparable. Maybe GitHub - fdietze/vectory: A 2D geometry library in Scala. is the nearest option.

Any advice?

Depending on how extensively you are using that dependency it may be feasible to add a small wrapper around it that only exposes the parts you use. And then you can add jvm-specific sources that implement the wrapper with javaGeom and js-specific sources that use some javascript library instead.

1 Like

Hi @Jasper-M, understood; it might be a feasible plan, the dependency is to a relatively small number of methods. Thank you for your suggestion.