Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Find a better way of defining swizzles + types #10

Open
davepagurek opened this issue Jul 16, 2021 · 0 comments
Open

Find a better way of defining swizzles + types #10

davepagurek opened this issue Jul 16, 2021 · 0 comments
Labels
enhancement New feature or request

Comments

@davepagurek
Copy link
Owner

davepagurek commented Jul 16, 2021

Maybe this means splitting up defining the methods + defining the types, e.g.:

// Types
type VecElement = 'x' | 'y' | 'z' | 'w' | 'r' | 'g' | 'b' | 'a' | 'u' | 'v'
type Vec2Swizzle = `${VecElement}${VecElement}`
type Vec3Swizzle = `${Vec2Swizzle}${VecElement}`
type Vec4Swizzle = `${Vec3Swizzle}${VecElement}`
type Swizzled =
  & { [vec2Key in Vec2Swizzle]: () => VectorOp }
  & { [vec3Key in Vec3Swizzle]: () => VectorOp }
  & { [vec4Key in Vec4Swizzle]: () => VectorOp }
interface VectorOp extends Swizzled {}

// Methods
const elements = ['x', 'y', 'z', 'w', 'r', 'g', 'b', 'a', 'u', 'v']
const swizzles = [
  ...combinations(elements, elements), // vec2 swizzles
  ...combinations(elements, elements, elements), // vec3 swizzles
  ...combinations(elements, elements, elements, elements), // vec4 swizzles
]
for (const swizzle of swizzles) {
  this[swizzle.join('')] = function() {
    // TODO
  }
}
@davepagurek davepagurek added the enhancement New feature or request label Jul 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant