Giter Club home page Giter Club logo

Comments (3)

the-ssd avatar the-ssd commented on August 27, 2024

Alternatively, it can be implemented like this. (But this doesn't allow passing &mut Vec2 to a function, for example)

pub trait Vec3SwizzleSet {
    fn set_xz(&mut self, thing: Vec2);
    fn set_xy(&mut self, thing: Vec2);
    fn set_zy(&mut self, thing: Vec2);
    fn set_yz(&mut self, thing: Vec2);
}

impl Vec3SwizzleSet for Vec3 {
    fn set_xz(&mut self, thing: Vec2) {
        self.x = thing.x;
        self.z = thing.y;
    }

    fn set_xy(&mut self, thing: Vec2) {
        self.x = thing.x;
        self.y = thing.y;
    }

    fn set_zy(&mut self, thing: Vec2) {
        self.z = thing.x;
        self.y = thing.y;
    }

    fn set_yz(&mut self, thing: Vec2) {
        self.y = thing.x;
        self.z = thing.y;
    }
}

from glam-rs.

bitshifter avatar bitshifter commented on August 27, 2024

I was thinking about this when adding the with_x etc. methods, which would be an alternative to a set that mutates,

So rather than fn set_zy(&mut self, v: Vec2) it would be fn with_zy(self, v: Vec2) -> Self, although both have their uses.

The swizzles are all generated code which does reduce the amount of typing required but that particular bit of codegen is reasonably complex.

One complication is it would be good to support Vec3 and Vec3A as the thing vector which will probably make the trait slightly more complex.

from glam-rs.

the-ssd avatar the-ssd commented on August 27, 2024

What about making it impl Into<Vec3>?
If both have their use cases, then maybe have both?

I saw, and I was trying to understand what was going on, but failed.
I made a marco which generates Vec3SwizzleSet. But AFAIK macros will slow down compilation compared to the current approach. (maybe with proc-marco2 the codegen can be modified to output the generated code into a file?)

from glam-rs.

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.