2

I would like to make a simple web application (a static website where all computation happens on the client) that generates a mesh and displays it. I have a working prototype in Unity and now I'm wondering what a good framework / language is for the task.

The problem: I would like to use Typescript or Javascript, but neither support operator overloading.

A line like this in C#

a = Vector3.forward * 3 + direction * length * 0.5;

would look horrible without operator overloading:

a = Vector3.forward.times(3).add(direction.times(length * 0.5));

What is the most elegant solution to this?

Toast
  • 128

1 Answers1

7

You either pick a language that allows the syntax you want, or write it out longhand and accept that it "look[s] horrible".

For vector arithmetic, there are at least 3 different operations that are reasonably denoted by * (or times or product), and you'd have to have a language that takes return types into account to disambiguate all of them. It's then not such a burden to have to name scale, dot product and cross product.

As a note, it's likely there are existing linear algebra libraries in all the languages that you could use. Don't try to write one yourself unless you really can't find one.

Caleth
  • 12,190