GithubHelp home page GithubHelp logo

permute's Introduction

permute

Generates permutation combinations for all inputs.

Usage

cargo build
./permute input_file.json

Defining Inputs

json is used define inputs which permutations can be generated from:

"channel_map": {
    "v2-v2": [
        [ {"name": "x", "index": 0}, {"name": "y", "index": 1} ], 
        [ {"name": "x", "index": 0}, {"name": "y", "index": 1} ]
    ],

    "v3-v2": [
        [ {"name": "x", "index": 0}, {"name": "y", "index": 1}, {"name": "z", "index": 2} ], 
        [ {"name": "x", "index": 0}, {"name": "y", "index": 1}, {"name": "z", "index": 2} ]
    ]
},

Supply an array of map of channels, each element is called an option, you can then specify outputs which use an entry in the channel map:

"outputs": [
    {
        "channels": "v2-v2",
        "format_string": "Swizzle<T, 2, %d, %i[0], %i[1]> %n[0]%n[1];", 
        "ignore_duplicates": false,
        "include_least_index": 0
    }
]

format_string allows you specify a string which will be formatted on output:

%i replaces with option index and %n replaces with the option name, the array %i[1] syntax is to select which channel the option comes from. %d will be replaced with 0 if none of the indices in the result are duplicated, 1 if there are duplicates in the result.

ignore_duplicates ensure each element inside the permutation is unique.
include_least_index allows you to select permuatation combination containing element that is this value or greater.

Examples

Generate all permutations of vector swizzles

To perform shader-style swizzles with c++ requires some templates and leg-work.. here are all the generated c++ templated declarations of a vec4 to a vec2 swizzle.

Swizzle<T, 0, 0> xx;
Swizzle<T, 0, 1> xy;
Swizzle<T, 0, 2> xz;
Swizzle<T, 0, 3> xw;
Swizzle<T, 1, 0> yx;
Swizzle<T, 1, 1> yy;
Swizzle<T, 1, 2> yz;
Swizzle<T, 1, 3> yw;
Swizzle<T, 2, 0> zx;
Swizzle<T, 2, 1> zy;
Swizzle<T, 2, 2> zz;
Swizzle<T, 2, 3> zw;
Swizzle<T, 3, 0> wx;
Swizzle<T, 3, 1> wy;
Swizzle<T, 3, 2> wz;
Swizzle<T, 3, 3> ww;

Here is some generated output of swizzles in rust.

fn xw(self) -> Vec2<T>;
fn yw(self) -> Vec2<T>;
fn zw(self) -> Vec2<T>;
fn wx(self) -> Vec2<T>;
fn wy(self) -> Vec2<T>;
fn wz(self) -> Vec2<T>;
fn ww(self) -> Vec2<T>;

fn set_xw(&mut self, other: Vec2<T>);
fn set_yw(&mut self, other: Vec2<T>);
fn set_zw(&mut self, other: Vec2<T>);
fn set_wx(&mut self, other: Vec2<T>);
fn set_wy(&mut self, other: Vec2<T>);
fn set_wz(&mut self, other: Vec2<T>);

fn xw(self) -> Vec2<T> {
    Vec2::new(self.x, self.w)
}

fn yw(self) -> Vec2<T> {
    Vec2::new(self.y, self.w)
}

fn zw(self) -> Vec2<T> {
    Vec2::new(self.z, self.w)
}

fn wx(self) -> Vec2<T> {
    Vec2::new(self.w, self.x)
}

fn wy(self) -> Vec2<T> {
    Vec2::new(self.w, self.y)
}

fn wz(self) -> Vec2<T> {
    Vec2::new(self.w, self.z)
}

fn ww(self) -> Vec2<T> {
    Vec2::new(self.w, self.w)
}

permute's People

Contributors

polymonster avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Forkers

dseeni

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.