Giter VIP home page Giter VIP logo

ruby_vectormath's People

Contributors

leviongit avatar lyniat avatar xenobrain avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

lyniat leviongit

ruby_vectormath's Issues

Name conflict with built-in Vec2

Since DragonRuby 3.9, there is a built-in Vec2:

e = Vec2.new
# {}
e.class
# Vec2
Vec2.superclass
# Hash
a = MatrixFunctions.vec2(1, 2)
# {:x=>1, :y=>2}
b = MatrixFunctions.vec2(3, 4)
# {:x=>3, :y=>4}
c = a + b
# {:x=>4.0, :y=>6.0}
d = Vec2.new(1, 2)
# EXCEPTION: wrong number of arguments (given 2, expected 0..1)

if you include vectormath_2d from this library (without wrapping it in a module), it monkey-patches the built-in class which results in some odd behavior:

a = MatrixFunctions.vec2(1, 2)
b = MatrixFunctions.vec2(3, 4)
c = a + b
c.x
# 0.0
c.y
# 0.0
c[:x]
# 1
c[:y]
# 2

Some options that spring to mind:

  • If this implementation is superior to the built-in one, it should be renamed to make it distinct (or wrapped in a module)
  • If there is some performance reason why the built-in one uses Hashes, it would be great if this could intentionally monkey-patch the built-in Vec2 to add all of the in-place methods

Relevant part of the DR changelog:

** [Standard] The following matrix math apis have been added to Object (accessible from anywhere):
The intent of these matrix functions is to mirror GLSL matrix apis.

  • vec(2|3|4): Creates a vec with the given dimension. Represented as a Hash
    with the primitive_marker set to :vec2, :vec3, or vec4.
  • mat(2|3|4): Creates a mat with the given dimension. Represented as a Hash of Hashes
    with the primitive_marker set to :mat2, :mat3, :mat4 at the top level,
    and :vec(2|3|4) for each vector component.
  • add: Adds matrices given to the function (returns nil if a matrix multiplication isn't valid).
  • mul: Multiplies matrices given to the function. Returns nil if the matrices are incompatible.
  • dot: Performs a scalar dot product for matrices given a list of matrices. Returns nil if the matrices are incompatible.
  • cross: Performs a cross product for matrices given a list of matrices. Returns nil if the matrices are incompatible.
  • normalize: Normalizes a vector. Returns the new normalized vector as a new Hash.
  • normalize!: Normalizes a vector. Mutates the vector passed in.
  • distance: Returns the distance between to vectors. Returns nil if the vectors are incompatible.
  • Hash#+: Delegates to add for matrix multiplication. Returns nil if the matrices are
    incompatible or if primitive_marker isn't set on the Hash.
  • Hash#*: Delegates to mul for matrix multiplication. Returns nil if the matrices are
    incompatible or if primitive_marker isn't set on the Hash.

Vec2#sub_from! copy-paste error

Calling sub_from! always sets @y to 0.

   def sub_from!(vec2_lhs, vec2_rhs)
     @x = vec2_lhs.x - vec2_rhs.x
-    @y = vec2_lhs.y - vec2_lhs.y
+    @y = vec2_lhs.y - vec2_rhs.y
     self
   end

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.