<commit_before>//Copyright (c) 2020 <NAME>.
//CuraEngine is released under the terms of the AGPLv3 or higher.

#include "FMatrix4x3.h" //The definitions we're implementing.

#include "floatpoint.h" //This matrix gets applied to floating point coordinates.
#include "IntPoint.h" //Conversion directly into integer-based coordinates.
#include "../settings/types/Ratio.h" //Scale factor.

namespace cura
{
    
FMatrix4x3 FMatrix4x3::scale(const Ratio scale, const Point3 origin)
{
    FMatrix4x3 result;
    result.m[0][0] = scale; //X scale.
    result.m[1][1] = scale; //Y scale.
    result.m[2][2] = scale; //Z scale.

    //Apply a transformation to scale it away from the origin.
    const Ratio delta_scale = scale - 1;
    result.m[3][0] = delta_scale * -origin.x; //Arrived at by manually applying an inverse move, the scale, then a move.
    result.m[3][1] = delta_scale * -origin.y;
    result.m[3][2] = delta_scale * -origin.z;

    return result;
}

FMatrix4x3::FMatrix4x3()
{
    m[0][0] = 1.0;
    m[1][0] = 0.0;
    m[2][0] = 0.0;
    m[3][0] = 0.0;
    m[0][1] = 0.0;
    m[1][1] = 1.0;
    m[2][1] = 0.0;
    m[3][1] = 0.0;
    m[0][2] = 0.0;
    m[1][2] = 0.0;
    m[2][2] = 1.0;
    m[3][2] = 0.0;
    m[0][3] = 0.0;
    m[1][3] = 0.0;
    m[2][3] = 0.0;
    m[3][3] = 1.0;
}

Point3 FMatrix4x3::apply(const FPoint3& p) const
{
    return Point3(
        MM2INT(p.x * m[0][0] + p.y * m[1][0] + p.z * m[2][0] + m[3][0]),
        MM2INT(p.x * m[0][1] + p.y * m[1][1] + p.z * m[2][1] + m[3][1]),
        MM2INT(p.x * m[0][2] + p.y * m[1][2] + p.z * m[2][2] + m[3][2])
    );
}

Point3 FMatrix4x3::apply(const Point3& p) const
{
    return Point3(
        m[0][0] * p.x + m[1][0] * p.y + m[2][0] * p.z + m[3][0],
        m[0][1] * p.x + m[1][1] * p.y + m[2][1] * p.z + m[3][1],
        m[0][2] * p.x + m[1][2] * p.y + m[2][2] * p.z + m[3][2]
    );
}

}<commit_msg>Don't go out of bounds when initialising matrix<commit_after>//Copyright (c) 2020 <NAME>.V.
//CuraEngine is released under the terms of the AGPLv3 or higher.

#include "FMatrix4x3.h" //The definitions we're implementing.

#include "floatpoint.h" //This matrix gets applied to floating point coordinates.
#include "IntPoint.h" //Conversion directly into integer-based coordinates.
#include "../settings/types/Ratio.h" //Scale factor.

namespace cura
{
    
FMatrix4x3 FMatrix4x3::scale(const Ratio scale, const Point3 origin)
{
    FMatrix4x3 result;
    result.m[0][0] = scale; //X scale.
    result.m[1][1] = scale; //Y scale.
    result.m[2][2] = scale; //Z scale.

    //Apply a transformation to scale it away from the origin.
    const Ratio delta_scale = scale - 1;
    result.m[3][0] = delta_scale * -origin.x; //Arrived at by manually applying an inverse move, the scale, then a move.
    result.m[3][1] = delta_scale * -origin.y;
    result.m[3][2] = delta_scale * -origin.z;

    return result;
}

FMatrix4x3::FMatrix4x3()
{
    m[0][0] = 1.0;
    m[1][0] = 0.0;
    m[2][0] = 0.0;
    m[3][0] = 0.0;
    m[0][1] = 0.0;
    m[1][1] = 1.0;
    m[2][1] = 0.0;
    m[3][1] = 0.0;
    m[0][2] = 0.0;
    m[1][2] = 0.0;
    m[2][2] = 1.0;
    m[3][2] = 0.0;
}

Point3 FMatrix4x3::apply(const FPoint3& p) const
{
    return Point3(
        MM2INT(p.x * m[0][0] + p.y * m[1][0] + p.z * m[2][0] + m[3][0]),
        MM2INT(p.x * m[0][1] + p.y * m[1][1] + p.z * m[2][1] + m[3][1]),
        MM2INT(p.x * m[0][2] + p.y * m[1][2] + p.z * m[2][2] + m[3][2])
    );
}

Point3 FMatrix4x3::apply(const Point3& p) const
{
    return Point3(
        m[0][0] * p.x + m[1][0] * p.y + m[2][0] * p.z + m[3][0],
        m[0][1] * p.x + m[1][1] * p.y + m[2][1] * p.z + m[3][1],
        m[0][2] * p.x + m[1][2] * p.y + m[2][2] * p.z + m[3][2]
    );
}

}
{'fraction_non_alphanumeric': 0.22335844994617868, 'fraction_numerical': 0.07965554359526372, 'mean_word_length': 2.523222748815166, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '7524405', 'n_tokens_mistral': 1751, 'n_tokens_neox': 1694, 'n_words': 385}