GithubHelp home page GithubHelp logo

Redesigning Vec family API about sdfx HOT 8 CLOSED

deadsy avatar deadsy commented on May 24, 2024
Redesigning Vec family API

from sdfx.

Comments (8)

deadsy avatar deadsy commented on May 24, 2024

So:
func Sub(a, b V3) V3

Instead of:
func (a V3) Sub(b V3) V3

The advantage of the second form is that it leaves "Sub" free in the namespace to be used for other types. E.g. V2, integer vectors, etc.

I think that's why I selected it. Blame a lack of function templates in go.

from sdfx.

soypat avatar soypat commented on May 24, 2024

What you are saying is reasonable. This namespace constraint however can be solved by creating a package for each type much like gonum does.

from sdfx.

deadsy avatar deadsy commented on May 24, 2024

This namespace constraint however can be solved by creating a package for each type

Done.

10ae73b

I haven't created an c = op(a, b) functions at this time, but it is trivial to do so.

from sdfx.

soypat avatar soypat commented on May 24, 2024

Awesome! I guess as soon as those functions are written we can close this issue. I am unavailable to contribute this feature.

from sdfx.

aprice2704 avatar aprice2704 commented on May 24, 2024

@soypat you could however do:

n := a.f(t + dt2).Sub(a.f(t - dt2))`

couldn't you?

from sdfx.

soypat avatar soypat commented on May 24, 2024

@aprice2704 my issue is not with the amount of lines it takes to express an operation but rather how readable the code is. I dont think methods as operations lend themeselves to readable code, in my experience

from sdfx.

aprice2704 avatar aprice2704 commented on May 24, 2024

I understand but respectfully disagree :) I find the method-operator version to be clearer, since it enforces the order in which operators are applied rather than relying on conventions from natural languages.
sub(a,b) results in a-b or b-a?
a.sub(b) must be a-b.
I have been writing a fairly complex set of geometry manipulations and found the operator-method to be quite clear. :)
In any event, the methods being present do not constrain you from adding sub(a,b) and friends to your own packages if you wish; however, adding methods requires forking the package, so I would much prefer @deadsy leaves them in place :)

from sdfx.

deadsy avatar deadsy commented on May 24, 2024

At this point the vector packages have been split out into individual packages for each vector type. The rest of the code has been converted to use the new packages.

At the moment the a.Op(b) for is still the main way of doing things.

The Op(a,b) form is possible without leading to name space problems.
E.g. v2.Add(a,b)

Still- I haven't created these functions, because I don't feel the need.

from sdfx.

Related Issues (20)

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.