<commit_before>﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;

[System.Serializable]
public class AxleInfo {
	public WheelCollider leftWheel;
	public WheelCollider rightWheel;
	public bool brake;
	public bool motor;
	public bool steering;
}

public class CarBaseController : MonoBehaviour {
	public List<AxleInfo> axleInfos; 
	public float maxMotorTorque;
	public float maxBrakeTorque;
	public float maxSteeringAngle;
	public Rigidbody voiture;

	private Quaternion cylRotationRight =  Quaternion.AngleAxis (270, Vector3.right);
	private Quaternion cylRotationUp =  Quaternion.AngleAxis (90, Vector3.forward);
	
	// finds the corresponding visual wheel
	// correctly applies the transform
	public void ApplyLocalPositionToVisuals(WheelCollider collider)
	{
		if (collider.transform.childCount == 0) {
			return;
		}

		Transform visualWheel = collider.transform.GetChild(0);

		Vector3 position;
		Quaternion rotation;
		collider.GetWorldPose(out position, out rotation);

		visualWheel.transform.position = position;
		visualWheel.transform.rotation = rotation*cylRotationRight*cylRotationUp;
	}
	
	public void FixedUpdate()
	{
		float brake=0;
		float motor=0;

		if (Input.GetAxis ("Vertical") < 0 && GoForward()) {
			 brake = - maxBrakeTorque * Input.GetAxis ("Vertical");
		}
		else {
			 motor = maxMotorTorque * Input.GetAxis ("Vertical");
			if ( GoRewind() ) {
				motor = motor/1.5f;
			}
		}

		float steering = maxSteeringAngle * Input.GetAxis("Horizontal");
		
		foreach (AxleInfo axleInfo in axleInfos) {
			if (axleInfo.steering) {
				axleInfo.leftWheel.steerAngle = steering;
				axleInfo.rightWheel.steerAngle = steering;
			}
			if (axleInfo.motor) {
				axleInfo.leftWheel.motorTorque = motor;
				axleInfo.rightWheel.motorTorque = motor;
			}
			if (axleInfo.brake){
				axleInfo.leftWheel.brakeTorque = brake;
				axleInfo.rightWheel.brakeTorque = brake;
			}



			ApplyLocalPositionToVisuals(axleInfo.leftWheel);
			ApplyLocalPositionToVisuals(axleInfo.rightWheel);
			
		}
	}

	public bool GoForward() {
		AxleInfo axle = axleInfos [0];
		return (axle.leftWheel.rpm > 0);
	}

	public bool GoRewind() {
		return !GoForward();
	}
}<commit_msg>refactoring CarBase<commit_after>﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;

[System.Serializable]
public class AxleInfo {
	public WheelCollider leftWheel;
	public WheelCollider rightWheel;
	public bool brake;
	public bool motor;
	public bool steering;
}

public class CarBaseController : MonoBehaviour {
	public List<AxleInfo> axleInfos; 
	public float maxMotorTorque;
	public float maxBrakeTorque;
	public float maxSteeringAngle;
	public Rigidbody voiture;

	private Quaternion cylRotationRight =  Quaternion.AngleAxis (270, Vector3.right);
	private Quaternion cylRotationUp =  Quaternion.AngleAxis (90, Vector3.forward);

	public void FixedUpdate()
	{
		
		foreach (AxleInfo axleInfo in axleInfos) {
			if (axleInfo.steering) {
				axleInfo.leftWheel.steerAngle = Steer();
				axleInfo.rightWheel.steerAngle = Steer();
			}
			if (axleInfo.motor) {
				axleInfo.leftWheel.motorTorque = Motor();
				axleInfo.rightWheel.motorTorque = Motor();
			}
			if (axleInfo.brake){
				axleInfo.leftWheel.brakeTorque = Brake();
				axleInfo.rightWheel.brakeTorque = Brake();
			}

			ApplyLocalPositionToVisuals(axleInfo.leftWheel);
			ApplyLocalPositionToVisuals(axleInfo.rightWheel);
			
		}
	}

	public void ApplyLocalPositionToVisuals(WheelCollider collider)
	{
		if (collider.transform.childCount == 0) {
			return;
		}
		
		Transform visualWheel = collider.transform.GetChild(0);
		
		Vector3 position;
		Quaternion rotation;
		collider.GetWorldPose(out position, out rotation);
		
		visualWheel.transform.position = position;
		visualWheel.transform.rotation = rotation*cylRotationRight*cylRotationUp;
	}



	public float Steer () {
		return maxSteeringAngle * Horizontal();
	}

	public float Brake() {
		if (Braking()) {
			return - maxBrakeTorque * Vertical();
		}
		return 0;
	}

	public float Motor() {
		float motor;
		if (!Braking()) {
			motor = maxMotorTorque * Vertical();
			if ( GoRewind() ) {
				motor = motor/1.2f;
			}
			return motor;
		}
		return 0;
	}

	public bool Braking() {
		return Vertical() < 0 && GoForward ();
	}

	public bool GoForward() {
		AxleInfo axle = axleInfos [0];
		return (axle.leftWheel.rpm > 0);
	}
	
	public bool GoRewind() {
		return !GoForward();
	}
	
	public float Vertical() {
		return Input.GetAxis ("Vertical");
	}
	
	public float Horizontal() {
		return Input.GetAxis ("Horizontal");
	}
}
{'fraction_non_alphanumeric': 0.10279965004374453, 'fraction_numerical': 0.0074365704286964126, 'mean_word_length': 4.126681614349776, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '744583', 'n_tokens_mistral': 1785, 'n_tokens_neox': 1505, 'n_words': 333}