<commit_before>#define fbext_NoBuiltinInstanciations() -1
# include once "ext/testly.bi"
# include once "ext/math/matrix.bi"

fbext_Instanciate(Vector3, ((single)))

namespace ext.tests.math

    using ext.math

    private function check_vector ( byref v as ext.math.vec3f, byval x as single, byval y as single, byval z as single) as bool

        var res = true
        if not (abs((v.x) - (x)) < 0.0000000001f) then
            res = false
        end if
        if not (abs((v.y) - (y)) < 0.0000000001f)  then
            res = false
        end if
        if not (abs((v.z) - (z)) < 0.0000000001f)  then
            res = false
        end if
        return res

    end function

    private sub test_matrix_identity

        var m = matrix(matrix.identity())
        m = m

        TESTLY_ASSERT_TRUE( check_vector(m.right,       1.0f, 0.0f, 0.0f) )
        TESTLY_ASSERT_TRUE( check_vector(m.up,          0.0f, 1.0f, 0.0f) )
        TESTLY_ASSERT_TRUE( check_vector(m.forward,     0.0f, 0.0f, 1.0f) )
        TESTLY_ASSERT_TRUE( check_vector(m.position,    0.0f, 0.0f, 0.0f) )

    end sub

    private sub test_matrix_translate

        var m = matrix(matrix.identity())
        m.translate( 1.0f, 2.0f, 3.0f )

        TESTLY_ASSERT_TRUE( check_vector(m.right,       1.0f, 0.0f, 0.0f) )
        TESTLY_ASSERT_TRUE( check_vector(m.up,          0.0f, 1.0f, 0.0f) )
        TESTLY_ASSERT_TRUE( check_vector(m.forward,     0.0f, 0.0f, 1.0f) )
        TESTLY_ASSERT_TRUE( check_vector(m.position,    1.0f, 2.0f, 3.0f) )

    end sub

    private sub test_matrix_rotate

        var m = matrix(matrix.identity())
        m.rotate( 90.0f, 180.0f, 270.0f )

        TESTLY_ASSERT_TRUE( check_vector(m.right,       3.65039e-08f,   -1.216797e-08f, -1.0f) )
        TESTLY_ASSERT_TRUE( check_vector(m.up,          -1,             2.433593e-08f,  -3.65039e-08f) )
        TESTLY_ASSERT_TRUE( check_vector(m.forward,     2.433593e-08f,  1.0f,           1.216796e-08f) )
        TESTLY_ASSERT_TRUE( check_vector(m.position,    0.0f,           0.0f,           0.0f) )

    end sub

    private sub test_matrix_invert

        var m = matrix( _
            type<vec3f>( 0.0f, 1.0f, 2.0f ), _
            type<vec3f>( 3.0f, 4.0f, 5.0f ), _
            type<vec3f>( 6.0f, 7.0f, 8.0f ), _
            type<vec3f>( 9.0f, 10.0f, 11.0f ) _
        )
        m.invert()

        TESTLY_ASSERT_TRUE( check_vector(m.right,       0f, 3f, 6f) )
        TESTLY_ASSERT_TRUE( check_vector(m.up,          1f, 4f, 7f) )
        TESTLY_ASSERT_TRUE( check_vector(m.forward,     2f, 5f, 8f) )
        TESTLY_ASSERT_TRUE( check_vector(m.position,    -32f, -122f, 212f) )

    end sub

    private sub test_matrix_multiply

        var m = matrix( _<commit_msg>Updated constants so now all tests pass.<commit_after>#define fbext_NoBuiltinInstanciations() -1
# include once "ext/testly.bi"
# include once "ext/math/matrix.bi"

fbext_Instanciate(Vector3, ((single)))

namespace ext.tests.math

    using ext.math

    private function check_vector ( byref v as ext.math.vec3f, byval x as single, byval y as single, byval z as single) as bool

        var res = true
        if not (abs((v.x) - (x)) < 0.0000000001f) then
            res = false
        end if
        if not (abs((v.y) - (y)) < 0.0000000001f)  then
            res = false
        end if
        if not (abs((v.z) - (z)) < 0.0000000001f)  then
            res = false
        end if
        return res

    end function

    private sub test_matrix_identity

        var m = matrix(matrix.identity())
        m = m

        TESTLY_ASSERT_TRUE( check_vector(m.right,       1.0f, 0.0f, 0.0f) )
        TESTLY_ASSERT_TRUE( check_vector(m.up,          0.0f, 1.0f, 0.0f) )
        TESTLY_ASSERT_TRUE( check_vector(m.forward,     0.0f, 0.0f, 1.0f) )
        TESTLY_ASSERT_TRUE( check_vector(m.position,    0.0f, 0.0f, 0.0f) )

    end sub

    private sub test_matrix_translate

        var m = matrix(matrix.identity())
        m.translate( 1.0f, 2.0f, 3.0f )

        TESTLY_ASSERT_TRUE( check_vector(m.right,       1.0f, 0.0f, 0.0f) )
        TESTLY_ASSERT_TRUE( check_vector(m.up,          0.0f, 1.0f, 0.0f) )
        TESTLY_ASSERT_TRUE( check_vector(m.forward,     0.0f, 0.0f, 1.0f) )
        TESTLY_ASSERT_TRUE( check_vector(m.position,    1.0f, 2.0f, 3.0f) )

    end sub

    private sub test_matrix_rotate

        var m = matrix(matrix.identity())
        m.rotate( 90.0f, 180.0f, 270.0f )

        TESTLY_ASSERT_TRUE( check_vector(m.right,       -8.571431e-016f,   2.857144e-016f, -1.0f) )
        TESTLY_ASSERT_TRUE( check_vector(m.up,          -1,             -5.714288e-016f,  8.571431e-016f) )
        TESTLY_ASSERT_TRUE( check_vector(m.forward,     -5.714288e-016f,  1.0f,           2.857144e-016f) )
        TESTLY_ASSERT_TRUE( check_vector(m.position,    0.0f,           0.0f,           0.0f) )

    end sub

    private sub test_matrix_invert

        var m = matrix( _
            type<vec3f>( 0.0f, 1.0f, 2.0f ), _
            type<vec3f>( 3.0f, 4.0f, 5.0f ), _
            type<vec3f>( 6.0f, 7.0f, 8.0f ), _
            type<vec3f>( 9.0f, 10.0f, 11.0f ) _
        )
        m.invert()

        TESTLY_ASSERT_TRUE( check_vector(m.right,       0f, 3f, 6f) )
        TESTLY_ASSERT_TRUE( check_vector(m.up,          1f, 4f, 7f) )
        TESTLY_ASSERT_TRUE( check_vector(m.forward,     2f, 5f, 8f) )
        TESTLY_ASSERT_TRUE( check_vector(m.position,    -32f, -122f, -212f) )

    end sub

    private sub test_matrix_multiply

        var m = matrix( _
{'fraction_non_alphanumeric': 0.12116257947320618, 'fraction_numerical': 0.07811080835603997, 'mean_word_length': 1.9256110520722636, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 6, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1420772', 'n_tokens_mistral': 2376, 'n_tokens_neox': 2108, 'n_words': 442}