Skip to content

Metamethods for dividing a Vector and getting the reciprocal Vector#8

Open
Chr1Z93 wants to merge 2 commits into
Berserk-Games:masterfrom
Chr1Z93:patch-1
Open

Metamethods for dividing a Vector and getting the reciprocal Vector#8
Chr1Z93 wants to merge 2 commits into
Berserk-Games:masterfrom
Chr1Z93:patch-1

Conversation

@Chr1Z93
Copy link
Copy Markdown

@Chr1Z93 Chr1Z93 commented Aug 12, 2025

Example:

local vec = Vector(3, 2, 1)
local half = vec / 2 -- (1.5, 1, 0.5)
local reciprocal = vec:reciprocal() -- (0.33333, 0.5, 1)

Comment thread Vector/vector.lua Outdated
Copy link
Copy Markdown

@0x57e11a 0x57e11a left a comment

Choose a reason for hiding this comment

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

reopening @zerothi's comment, it would be best to either

  • permit number / Vector (given that we're already applying componentwise operations, this would be well defined as Vector(n / x, n / y, n / z))
  • or hard-error deny number / Vector operations

rather than silently failing with a nil

Comment thread Vector/vector.lua
@Chr1Z93 Chr1Z93 changed the title Added metamethod to divide a vector by a number Metamethods for dividing a Vector and getting the reciprocal Vector May 7, 2026
@Chr1Z93
Copy link
Copy Markdown
Author

Chr1Z93 commented May 7, 2026

reopening @zerothi's comment, it would be best to either

* permit `number / Vector` (given that we're already applying componentwise operations, this would be well defined as `Vector(n / x, n / y, n / z)`)

* or hard-error deny `number / Vector` operations

rather than silently failing with a nil

Updated it so that vector / vector and vector / number are handled.

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