Code Monkey home page Code Monkey logo

Comments (1)

SleepProgger avatar SleepProgger commented on June 10, 2024

The reason of this behavior is that the Vec2d class uses pythons magic function (__mul__...) format but cython magic functions behave differently.
See http://cython.readthedocs.io/en/latest/src/userguide/special_methods.html#arithmetic-methods.

There are no "right side of operation" functions (rmul, rsub,...) like in python. but the same arithmetic function is called for the right side with self set to the left value and other to the right if the magic function of the left side returns NotImplemented

A fix for the __mul__ function could look like this:

    def __mul__(self, other):
        if not isinstance(self, Vec2d):
            self, other = other, self
        if isinstance(other, Vec2d):
            return Vec2d(self.x * other.x, self.y * other.y)
        if (hasattr(other, "__getitem__")):
            return Vec2d(self.x*other[0], self.y*other[1])
        else:
            return Vec2d(self.x*other, self.y*other)

I could prepare a PR with "cythonized" magic functions some when the next days.

from cymunk.

Related Issues (17)

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.