From 8aed96f145c95057809fb27af918c7e3e6469362 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petri=20H=C3=A4kkinen?= Date: Thu, 21 Nov 2024 09:19:23 +0200 Subject: [PATCH] Remove implementation details --- docs/vector-library-vector2-constructor.md | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/docs/vector-library-vector2-constructor.md b/docs/vector-library-vector2-constructor.md index 1146d56..9c3706d 100644 --- a/docs/vector-library-vector2-constructor.md +++ b/docs/vector-library-vector2-constructor.md @@ -6,7 +6,7 @@ Add a constructor for initializing vectors from two components. ## Motivation -Currently the vector constructor supports only initializing vectors with three components (and optionally four if 4-wide vectors are enabled). However, there are problem domains such 2D graphics and graphical user interfaces which would benefit from a two component constructor. The benefits are twofold: it would improve code ergonomics because the third component does not need to be given when it is irrelevant or implicitly zero. Secondly, it would improve the performance of vector creation because the third component would not need to be loaded into a VM register. +Currently the vector constructor supports only initializing vectors with three components (and optionally four if 4-wide vectors are enabled). However, there are problem domains such 2D graphics and graphical user interfaces which would benefit from a two component constructor. The benefits are twofold: it would improve code ergonomics because the third component does not need to be given when it is irrelevant or implicitly zero. Secondly, it would improve the performance of vector creation because there is one less argument to pass in the 2D case. Existing vector library functions such as `vector.dot`, `vector.angle`, `vector.normalize`, `vector.min`, `vector.max`, `vector.abs` and `vector.clamp` already work out of the box in 2D as long as the unused components are zeroes. The functions also retain zeroes allowing function calls to be chained without issues. Out of the current functions, only `vector.cross` is not meaningful in 2D. @@ -16,13 +16,7 @@ Game engines that use a Z up coordinate system would also benefit from this chan ## Design -A new vector constructor `vector.create(x: number, y: number): vector` will be added. - -The built-in fastcall vector constructor will be extended to work with two components. This will increase the performance of creating vectors from two numbers. - -The compiler will be modified to support 2-component vector constants. This eliminates constructor calls that have two numeric constants as arguments. To keep things simple vector constants will still always have four components internally in the constant table. - -In all of the above cases the third component, and fourth component with 4-wide vectors, will be zero initialized. +A new vector constructor `vector.create(x: number, y: number): vector` will be added. The third component, and fourth component with 4-wide vectors, will be zero initialized. ## Drawbacks @@ -30,7 +24,7 @@ Accidentally omitting the third component becomes a possibility because the vect ## Alternatives -An alternative would be to add a new constructor with a different name (for example, `vector.create2`). This would effectively close the door for adding the less verbose constructor `vector(x: number, y: number, z: number?)`. It would also require a new built-in for fastcalls. Overall it seems that this alternative would not come with clear benefits. +An alternative would be to add a new constructor with a different name (for example, `vector.create2`). Another considerably more complex alternative is to add a new, separate vector type for 2D vectors. This would add significant bloat to the C API and type system in general, so it is unfeasible in practice.