<commit_before>#!/usr/bin/env perl6

use v6;

use lib $?FILE.path.directory;
use Generator;

Math::ThreeD::Library.new(
    name => 'Vec3',
    constructor => 'vec3',
    elems => 3,
    ops => (

        op( operator => '+',
            function => 'add',
            mutator => 'plus',
            args => [[ <obj> ],[ <num> ]],

        ),

        op( operator => '-',
            function => 'sub',
            mutator => 'minus',
            args => [[ <obj> ],[ <num> ]],
        ),

        op( operator => '-',
            function => 'neg',
            mutator => 'negate',
        ),

        op( operator => '*',
            function => 'mul',
            mutator => 'times',
            args => [[ <obj> ],[ <num> ]],
        ),

        op( operator => '/',
            function => 'div',
            mutator => 'divide',
            args => [[ <obj> ],[ <num> ]],
        ),

        op( operator => '%',
            function => 'mod',
            mutator => 'modulus',
            args => [[ <obj> ],[ <num> ]],
        ),

        op( operator => '!',
            postfix => True,
            # not correct or optimal; just testing postfix
            expressions => ['([*] 1..$a[0])', '([*] 1..$a[1])', '([*] 1..$a[2])'],
        ),

        op( operator => '⨯',
            function => 'cross',
            mutator => 'cross-with',
            args => [ ['obj'] ],
            expressions => [
                '$a[1] * $b[2] - $a[2] * $b[1]',
                '$a[2] * $b[0] - $a[0] * $b[2]',
                '$a[0] * $b[1] - $a[1] * $b[0]'
            ],
        ),

        op( operator => '⋅',
            function => 'dot',
            args => [ ['obj'] ],
            return => 'num',
            expression => '$a[0]*$b[0] + $a[1]*$b[1] + $a[2]*$b[2]',
        ),

        op( function => 'length_sqr',
            return => 'num',
            expression => '$a[0]*$a[0] + $a[1]*$a[1] + $a[2]*$a[2]',
        ),

        op( function => 'length',
            return => 'num',
            expression => 'sqrt( $a[0]*$a[0] + $a[1]*$a[1] + $a[2]*$a[2] )',
        ),

        op( function => 'rot-x',
            mutator => 'rotate-x',
            args => [ ['num'] ],
            intro => 'my ($sin, $cos) = sin($b), cos($b);',
            expressions => [
                '$a[0]',
                '$a[1] * $cos - $a[2] * $sin',
                '$a[1] * $sin + $a[2] * $cos',
            ],
        ),

        op( function => 'rot-y',
            mutator => 'rotate-y',
            args => [ ['num'] ],
            intro => 'my ($sin, $cos) = sin($b), cos($b);',
            expressions => [
                '$a[0] * $cos - $a[2] * $sin',
                '$a[1]',
                '$a[0] * $sin + $a[2] * $cos',
            ],
        ),

        op( function => 'rot-z',
            mutator => 'rotate-z',
            args => [ ['num'] ],
            intro => 'my ($sin, $cos) = sin($b), cos($b);',
            expressions => [
                '$a[0] * $cos - $a[1] * $sin',
                '$a[0] * $sin + $a[1] * $cos',
                '$a[2]',
            ],
        ),

        op( function => 'dump',
            body => 'say $a.perl',
            return => '',
        ),

    ),
).write('lib/Math/ThreeD/Vec3.pm');

# vim: set expandtab:ts=4:sw=4
<commit_msg>Add matrix transformation support<commit_after>#!/usr/bin/env perl6

use v6;

use lib $?FILE.path.directory;
use Generator;

Math::ThreeD::Library.new(
    name => 'Vec3',
    constructor => 'vec3',
    elems => 3,
    use => 'Math::ThreeD::Mat44',
    ops => (

        op( operator => '+',
            function => 'add',
            mutator => 'plus',
            args => [[ <obj> ],[ <num> ]],

        ),

        op( operator => '-',
            function => 'sub',
            mutator => 'minus',
            args => [[ <obj> ],[ <num> ]],
        ),

        op( operator => '-',
            function => 'neg',
            mutator => 'negate',
        ),

        op( operator => '*',
            function => 'mul',
            mutator => 'times',
            args => [[ <obj> ],[ <num> ]],
        ),

        op( operator => '/',
            function => 'div',
            mutator => 'divide',
            args => [[ <obj> ],[ <num> ]],
        ),

        op( operator => '%',
            function => 'mod',
            mutator => 'modulus',
            args => [[ <obj> ],[ <num> ]],
        ),

        op( operator => '!',
            postfix => True,
            # not correct or optimal; just testing postfix
            expressions => ['([*] 1..$a[0])', '([*] 1..$a[1])', '([*] 1..$a[2])'],
        ),

        op( operator => '⨯',
            function => 'cross',
            mutator => 'cross-with',
            args => [ ['obj'] ],
            expressions => [
                '$a[1] * $b[2] - $a[2] * $b[1]',
                '$a[2] * $b[0] - $a[0] * $b[2]',
                '$a[0] * $b[1] - $a[1] * $b[0]'
            ],
        ),

        op( operator => '⋅',
            function => 'dot',
            args => [ ['obj'] ],
            return => 'num',
            expression => '$a[0]*$b[0] + $a[1]*$b[1] + $a[2]*$b[2]',
        ),

        op( function => 'length_sqr',
            return => 'num',
            expression => '$a[0]*$a[0] + $a[1]*$a[1] + $a[2]*$a[2]',
        ),

        op( function => 'length',
            return => 'num',
            expression => 'sqrt( $a[0]*$a[0] + $a[1]*$a[1] + $a[2]*$a[2] )',
        ),

        op( function => 'rot-x',
            mutator => 'rotate-x',
            args => [ ['num'] ],
            intro => 'my ($sin, $cos) = sin($b), cos($b);',
            expressions => [
                '$a[0]',
                '$a[1] * $cos - $a[2] * $sin',
                '$a[1] * $sin + $a[2] * $cos',
            ],
        ),

        op( function => 'rot-y',
            mutator => 'rotate-y',
            args => [ ['num'] ],
            intro => 'my ($sin, $cos) = sin($b), cos($b);',
            expressions => [
                '$a[0] * $cos - $a[2] * $sin',
                '$a[1]',
                '$a[0] * $sin + $a[2] * $cos',
            ],
        ),

        op( function => 'rot-z',
            mutator => 'rotate-z',
            args => [ ['num'] ],
            intro => 'my ($sin, $cos) = sin($b), cos($b);',
            expressions => [
                '$a[0] * $cos - $a[1] * $sin',
                '$a[0] * $sin + $a[1] * $cos',
                '$a[2]',
            ],
        ),

        op( function => 'dump',
            body => 'say $a.perl',
            return => '',
        ),

        op( function => 'trans',
            mutator => 'transform',
            args => [ ['Mat44'] ],
            expressions => [
                '$a[0]*$b[0][0] + $a[1]*$b[0][1] + $a[2]*$b[0][2] + $b[0][3]',
                '$a[0]*$b[1][0] + $a[1]*$b[1][1] + $a[2]*$b[1][2] + $b[1][3]',
                '$a[0]*$b[2][0] + $a[1]*$b[2][1] + $a[2]*$b[2][2] + $b[2][3]',
            ],
        ),

    ),
).write('lib/Math/ThreeD/Vec3.pm');

# vim: set expandtab:ts=4:sw=4

{'fraction_non_alphanumeric': 0.24612320386968276, 'fraction_numerical': 0.022051500924740362, 'mean_word_length': 1.2402804333970683, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 156, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, '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': '1586964', 'n_tokens_mistral': 2482, 'n_tokens_neox': 2412, 'n_words': 459}