-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add hex, hexa, rgb, and rgba interpolators
- Loading branch information
1 parent
33bcf8f
commit a61041e
Showing
4 changed files
with
225 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
ultraviolet/shared/src/test/scala/ultraviolet/SyntaxTests.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package ultraviolet | ||
|
||
import scala.util.Random | ||
|
||
import syntax.* | ||
|
||
class SyntaxTests extends munit.FunSuite { | ||
|
||
test("hex interpolator") { | ||
assertEquals(hex"#00FF00", vec3(0f, 1f, 0f)) | ||
assertEquals(hex"#ff00ff", vec3(1f, 0f, 1f)) | ||
val (hex1, hex2, hex3) = ("00", "ff", "00") | ||
assertEquals(hex"#$hex1$hex2$hex3", vec3(0f, 1f, 0f)) | ||
|
||
intercept[IllegalArgumentException](hex"#00000"): Unit | ||
intercept[IllegalArgumentException](hex"#0000000"): Unit | ||
intercept[IllegalArgumentException](hex"#gggggg"): Unit | ||
} | ||
|
||
test("hexa interpolator") { | ||
assertEquals(hexa"#00FF00FF", vec4(0f, 1f, 0f, 1f)) | ||
assertEquals(hexa"#ff00ff00", vec4(1f, 0f, 1f, 0f)) | ||
val (hex1, hex2, hex3, hex4) = ("00", "ff", "00", "ff") | ||
assertEquals(hexa"#$hex1$hex2$hex3$hex4", vec4(0f, 1f, 0f, 1f)) | ||
|
||
intercept[IllegalArgumentException](hexa"#0000000"): Unit | ||
intercept[IllegalArgumentException](hexa"#000000000"): Unit | ||
intercept[IllegalArgumentException](hexa"#gggggggg"): Unit | ||
} | ||
|
||
test("rgb interpolator") { | ||
assertEquals(rgb"0,0,0", vec3(0f, 0f, 0f)) | ||
assertEquals(rgb"255,0,255", vec3(1f, 0f, 1f)) | ||
val (int1, int2, int3) = (0, 255, 0) | ||
assertEquals(rgb"$int1,$int2,$int3", vec3(0f, 1f, 0f)) | ||
|
||
intercept[IllegalArgumentException](rgb"0,0"): Unit | ||
intercept[IllegalArgumentException](rgb"0,0,0,0"): Unit | ||
intercept[IllegalArgumentException](rgb"0, 0, 0"): Unit | ||
intercept[IllegalArgumentException](rgb"-1,0,0"): Unit | ||
intercept[IllegalArgumentException](rgb"256,0,0"): Unit | ||
} | ||
|
||
test("rgba interpolator") { | ||
assertEquals(rgba"0,0,0,0", vec4(0f, 0f, 0f, 0f)) | ||
assertEquals(rgba"255,0,255,0", vec4(1f, 0f, 1f, 0f)) | ||
val (int1, int2, int3, int4) = (0, 255, 0, 255) | ||
assertEquals(rgba"$int1,$int2,$int3,$int4", vec4(0f, 1f, 0f, 1f)) | ||
|
||
intercept[IllegalArgumentException](rgba"0,0,0"): Unit | ||
intercept[IllegalArgumentException](rgba"0,0,0,0,0"): Unit | ||
intercept[IllegalArgumentException](rgba"0, 0, 0, 0"): Unit | ||
intercept[IllegalArgumentException](rgba"-1,0,0,0"): Unit | ||
intercept[IllegalArgumentException](rgba"256,0,0,0"): Unit | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
ultraviolet/shared/src/test/scala/ultraviolet/acceptance/GLSLInterpolatorTests.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package ultraviolet.acceptance | ||
|
||
import ultraviolet.DebugAST | ||
import ultraviolet.syntax.* | ||
|
||
class GLSLInterpolatorTests extends munit.FunSuite { | ||
test("hex interpolator") { | ||
inline def fragment: Shader[Unit, vec4] = Shader(_ => vec4(hex"#ff00ff", 0f)) | ||
|
||
// println(DebugAST.toAST(fragment)) | ||
|
||
val actual = fragment.toGLSL[WebGL2].toOutput.code | ||
|
||
assertEquals(actual, "vec4(vec3(1.0,0.0,1.0),0.0);") | ||
} | ||
|
||
test("hexa interpolator") { | ||
inline def fragment: Shader[Unit, vec4] = Shader(_ => hexa"#ff00ff00") | ||
|
||
// println(DebugAST.toAST(fragment)) | ||
|
||
val actual = fragment.toGLSL[WebGL2].toOutput.code | ||
|
||
assertEquals(actual, "vec4(1.0,0.0,1.0,0.0);") | ||
} | ||
|
||
test("rgb interpolator") { | ||
inline def fragment: Shader[Unit, vec4] = Shader(_ => vec4(rgb"255,0,255", 0f)) | ||
|
||
// println(DebugAST.toAST(fragment)) | ||
|
||
val actual = fragment.toGLSL[WebGL2].toOutput.code | ||
|
||
assertEquals(actual, "vec4(vec3(1.0,0.0,1.0),0.0);") | ||
} | ||
|
||
test("rgba interpolator") { | ||
inline def fragment: Shader[Unit, vec4] = Shader(_ => rgba"255,0,255,0") | ||
|
||
// println(DebugAST.toAST(fragment)) | ||
|
||
val actual = fragment.toGLSL[WebGL2].toOutput.code | ||
|
||
assertEquals(actual, "vec4(1.0,0.0,1.0,0.0);") | ||
} | ||
} |