With the rising need for ever more immersive UI and elements of menus I think expanding the Vector2 class to include :Dot() and :Cross() to perform basic operations C-Side would help create some of the effects we look for in dynamically drawing UI.
This would be useful for us now to (as said above) create UI that constantly changes, and it would be useful for ROBLOX so that if/when the time comes we decide to actively develop a CanvasFrame class (or something of the sort, with vector-graphics support) we can use this for drawing things with that class.
For me personally my application is to make a .Obj drawer with GUIs, I can do it without this being C-Side but I just like optimization.
Cross product is commonly defined in 2D space as u.xv.y-u.yv.x, which is equivalent to a signed parallelogram area defined by the two vectors. It’s close in spirit to 3D cross-product (e.g. assume that you have 2 vectors in a plane in 3D space - cross product will have the same length as this, and the sign can be thought of as whether the resulting vector is in the positive or negative half-space). Being able to compute signed areas in 2D is important for many algorithms, of course.
But yeah, the fastest way to do stuff like this in Lua is to just do component-wise math yourself in local variables.
This is an inconsistency between Vector3 and Vector2 and should be resolved.
Performance shouldnt be a priority when talking about writing GUI code in a slow scripting language. Providing these operations for Vector2 promotes readable (and standardized) code and minimizes unnecessary up-front development effort as you dont have to write your own functions every time.
Plus right now, what happens is that you use Vector3 for 2D coordinates because it actually has those operations, which probably isnt good for performance either.
local function Cross(a,b) --Vector2,Vector2 returns Number
return a.x*b.y-a.y*b.x
end
local v2n = Vector2.new
local function InvCross(a,b) --Number,Vector2 returns Vector2
return v2n(-a*b.y,a*b.x)
end