Module: RLSL::Prism::Builtins::SwizzleRules
- Defined in:
- lib/rlsl/prism/builtins/swizzle_rules.rb
Constant Summary collapse
- SWIZZLE_COMPONENTS =
{ "x" => 0, "r" => 0, "s" => 0, "y" => 1, "g" => 1, "t" => 1, "z" => 2, "b" => 2, "p" => 2, "w" => 3, "a" => 3, "q" => 3 }.freeze
- SINGLE_COMPONENT_FIELDS =
%w[x y z w r g b a s t p q].freeze
- SWIZZLE_PATTERNS =
/\A[xyzwrgba]{2,4}\z/
Class Method Summary collapse
- .single_component_field?(name) ⇒ Boolean
- .swizzle?(name) ⇒ Boolean
- .swizzle_type(components) ⇒ Object
Class Method Details
.single_component_field?(name) ⇒ Boolean
19 20 21 |
# File 'lib/rlsl/prism/builtins/swizzle_rules.rb', line 19 def single_component_field?(name) SINGLE_COMPONENT_FIELDS.include?(name.to_s) end |
.swizzle?(name) ⇒ Boolean
23 24 25 |
# File 'lib/rlsl/prism/builtins/swizzle_rules.rb', line 23 def swizzle?(name) name.to_s.match?(SWIZZLE_PATTERNS) end |
.swizzle_type(components) ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/rlsl/prism/builtins/swizzle_rules.rb', line 27 def swizzle_type(components) case components.length when 2 then :vec2 when 3 then :vec3 when 4 then :vec4 else :float end end |