<commit_before>#ifndef __ROTATE_HANDLER_H__
#define __ROTATE_HANDLER_H__

#include "mesh/Mesh.h"
#include "matrix/Transformation.h"

#include "Handler.h"

class RotateHandler : public Handler {

public:

  virtual void handle(Mesh& mesh, Json::Value& modification) {

    Json::Value& options = modification["options"];

    // read axis
    const std::string axis = options["axis"].asString();

    // read angle
    double angle = options["angle"].asDouble();

    // convert angle to radians if needed
    if( options["angleUnit"].empty() == false) {

      if( options["angleUnit"].asString() == "degrees") {

        angle = angle / 180 * M_PI;

      }

    }

    // construct transformation depending on chosen rotation
    // axis
    Transformation transform;

    if( axis == "x" ) {

      transform = Transformation(angle, 0, 0);

    }
    else if ( axis == "y" ) {

      transform = Transformation(0, angle, 0);

    }
    else if( axis == "z" ) {

      transform = Transformation(0, 0, angle);

    }

    // apply transformation to all vertices
    for( arma::vec& vertex: mesh.get_vertices() ) {

      vertex = transform.apply_matrix(vertex);

    }

  }

};

#endif
<commit_msg>added feature: rotation around mesh center<commit_after>#ifndef __ROTATE_HANDLER_H__
#define __ROTATE_HANDLER_H__

#include "mesh/Mesh.h"
#include "matrix/Transformation.h"

#include "Handler.h"

class RotateHandler : public Handler {

public:

  virtual void handle(Mesh& mesh, Json::Value& modification) {

    Json::Value& options = modification["options"];

    // read axis
    const std::string axis = options["axis"].asString();

    // read angle
    double angle = options["angle"].asDouble();

    // convert angle to radians if needed
    if( options["angleUnit"].empty() == false) {

      if( options["angleUnit"].asString() == "degrees") {

        angle = angle / 180 * M_PI;

      }

    }

    arma::vec origin = arma::zeros(3);

    const bool rotateAroundMeshCenter = (
       options["rotate around mesh center"].empty() == false &&
       options["rotate around mesh center"].asBool() == true
       );

    if( rotateAroundMeshCenter ) {

      origin = mesh.get_center();

    }

    // construct transformation depending on chosen rotation
    // axis
    Transformation transform;

    if( axis == "x" ) {

      transform = Transformation(angle, 0, 0);

    }
    else if ( axis == "y" ) {

      transform = Transformation(0, angle, 0);

    }
    else if( axis == "z" ) {

      transform = Transformation(0, 0, angle);

    }

    // apply transformation to all vertices
    for( arma::vec& vertex: mesh.get_vertices() ) {

      vertex -= origin;

      vertex = transform.apply_matrix(vertex);

      vertex += origin;

    }

  }

};

#endif

{'fraction_non_alphanumeric': 0.13693693693693693, 'fraction_numerical': 0.006846846846846847, 'mean_word_length': 2.7362045760430687, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2019070', 'n_tokens_mistral': 894, 'n_tokens_neox': 823, 'n_words': 219}