<commit_before>using UnityEngine;
using System.Collections;

public static class ViveGrip_JointFactory {
  public static ConfigurableJoint JointToConnect(GameObject jointObject, Rigidbody desiredObject, Vector3 offset, Quaternion desiredRotation) {
    ConfigurableJoint joint = jointObject.AddComponent<ConfigurableJoint>();

    ViveGrip_JointFactory.SetLinearDrive(joint, desiredObject.mass);
    ViveGrip_JointFactory.ConfigureBase(joint, offset);

    ViveGrip_JointFactory.SetAngularDrive(joint, desiredObject.mass);
    Quaternion currentRotation = desiredObject.transform.rotation;
    joint.SetTargetRotationLocal(desiredRotation, currentRotation);

    joint.connectedBody = desiredObject;
    joint.connectedBody.useGravity = false;
    return joint;
  }

  private static void ConfigureBase(ConfigurableJoint joint, Vector3 offset) {
    ConfigurableJointMotion linearMotion = ConfigurableJointMotion.Free;
    ConfigurableJointMotion angularMotion = ConfigurableJointMotion.Free;
    joint.xMotion = linearMotion;
    joint.yMotion = linearMotion;
    joint.zMotion = linearMotion;
    joint.angularXMotion = angularMotion;
    joint.angularYMotion = angularMotion;
    joint.angularZMotion = angularMotion;
    joint.autoConfigureConnectedAnchor = false;
    joint.connectedAnchor = offset;
  }

  private static void SetLinearDrive(ConfigurableJoint joint, float mass) {
    float gripStrength = 3000f * mass;
    float gripSpeed = 10f * mass;
    JointDrive jointDrive = joint.xDrive;
    jointDrive.positionSpring = gripStrength;
    jointDrive.positionDamper = gripSpeed;
    joint.xDrive = jointDrive;
    jointDrive = joint.yDrive;
    jointDrive.positionSpring = gripStrength;
    jointDrive.positionDamper = gripSpeed;
    joint.yDrive = jointDrive;
    jointDrive = joint.zDrive;
    jointDrive.positionSpring = gripStrength;
    jointDrive.positionDamper = gripSpeed;
    joint.zDrive = jointDrive;
  }

  private static void SetAngularDrive(ConfigurableJoint joint, float mass) {
    float gripStrength = 3000f * mass;
    float gripSpeed = 10f * mass;
    joint.rotationDriveMode = RotationDriveMode.XYAndZ;
    JointDrive jointDrive = joint.angularYZDrive;
    jointDrive.positionSpring = gripStrength;
    jointDrive.positionDamper = gripSpeed;
    joint.angularYZDrive = jointDrive;
    jointDrive = joint.angularXDrive;
    jointDrive.positionSpring = gripStrength;
    jointDrive.positionDamper = gripSpeed;
    joint.angularXDrive = jointDrive;
  }
}
<commit_msg>Cleaning up the joint factory<commit_after>using UnityEngine;
using System.Collections;

public static class ViveGrip_JointFactory {
  public static ConfigurableJoint JointToConnect(GameObject jointObject, Rigidbody desiredObject, Vector3 offset, Quaternion desiredRotation) {
    ConfigurableJoint joint = jointObject.AddComponent<ConfigurableJoint>();
    ViveGrip_JointFactory.SetLinearDrive(joint, desiredObject.mass);
    ViveGrip_JointFactory.SetAngularDrive(joint, desiredObject.mass);
    ViveGrip_JointFactory.ConfigureAnchor(joint, offset);
    ViveGrip_JointFactory.ConfigureRotation(joint, desiredObject, desiredRotation);
    ViveGrip_JointFactory.Attach(joint, desiredObject);
    return joint;
  }

  private static void ConfigureAnchor(ConfigurableJoint joint, Vector3 offset) {
    joint.autoConfigureConnectedAnchor = false;
    joint.connectedAnchor = offset;
  }

  private static void SetLinearDrive(ConfigurableJoint joint, float mass) {
    float gripStrength = 3000f * mass;
    float gripSpeed = 10f * mass;
    JointDrive jointDrive = joint.xDrive;
    jointDrive.positionSpring = gripStrength;
    jointDrive.positionDamper = gripSpeed;
    joint.xDrive = jointDrive;
    jointDrive = joint.yDrive;
    jointDrive.positionSpring = gripStrength;
    jointDrive.positionDamper = gripSpeed;
    joint.yDrive = jointDrive;
    jointDrive = joint.zDrive;
    jointDrive.positionSpring = gripStrength;
    jointDrive.positionDamper = gripSpeed;
    joint.zDrive = jointDrive;
  }

  private static void ConfigureRotation(ConfigurableJoint joint, Rigidbody desiredObject, Quaternion desiredRotation) {
    Quaternion currentRotation = desiredObject.transform.rotation;
    joint.SetTargetRotationLocal(desiredRotation, currentRotation);
  }

  private static void SetAngularDrive(ConfigurableJoint joint, float mass) {
    float gripStrength = 3000f * mass;
    float gripSpeed = 10f * mass;
    joint.rotationDriveMode = RotationDriveMode.XYAndZ;
    JointDrive jointDrive = joint.angularYZDrive;
    jointDrive.positionSpring = gripStrength;
    jointDrive.positionDamper = gripSpeed;
    joint.angularYZDrive = jointDrive;
    jointDrive = joint.angularXDrive;
    jointDrive.positionSpring = gripStrength;
    jointDrive.positionDamper = gripSpeed;
    joint.angularXDrive = jointDrive;
  }

  private static void Attach(ConfigurableJoint joint, Rigidbody desiredObject) {
    joint.connectedBody = desiredObject;
    joint.connectedBody.useGravity = false;
  }
}

{'fraction_non_alphanumeric': 0.0706401766004415, 'fraction_numerical': 0.005619104956853301, 'mean_word_length': 4.80209545983702, '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': '7144131', 'n_tokens_mistral': 1543, 'n_tokens_neox': 1367, 'n_words': 291}