// Path: src/org/usfirst/frc2832/Robot_2016/Coordinate.java
// public class Coordinate
// {
// 	private final double x, y;
// 	
// 	public Coordinate(double x, double y)
// 	{
// 		this.x = x;
// 		this.y = y;
// 	}
// 	
// 	public double getX()
// 	{
// 		return x;
// 	}
// 	
// 	public double getY()
// 	{
// 		return y;
// 	}
// }


import org.usfirst.frc2832.Robot_2016.Coordinate;
import edu.wpi.first.wpilibj.Joystick;
	@Override
	public double getAxis(AxisType axis) {
		return getRawAxis(axis.value);
	}
	
	/**
	 * Radial deadzoning helper method
	 * @param x
	 * @param y
	 * @return
	 */
	private Coordinate deadzone2D(double x, double y) {
		double magnitude = Math.sqrt(x * x + y * y);
		if (magnitude <= range)
			return new Coordinate(0, 0);
		double scale = (magnitude - range) / (1 - range);
		return new Coordinate(x / magnitude * scale, y / magnitude * scale);
	}
	
	@Override
	public double getRawAxis(int axis) {
		if (arrContains(leftstickAxis, axis)) {
			Coordinate p = (deadzone2D(
					super.getRawAxis(leftstickAxis[0]), 
					super.getRawAxis(leftstickAxis[1])));
			if (leftstickAxis[0] == axis)
				return p.getX();
			return p.getY();
		}
		if (arrContains(rightstickAxis, axis)) {
// Path: src/org/usfirst/frc2832/Robot_2016/Coordinate.java
// public class Coordinate
// {
// 	private final double x, y;
// 	
// 	public Coordinate(double x, double y)
// 	{
// 		this.x = x;
// 		this.y = y;
// 	}
// 	
// 	public double getX()
// 	{
// 		return x;
// 	}
// 	
// 	public double getY()
// 	{
// 		return y;
// 	}
// }


// Path: src/org/usfirst/frc2832/Robot_2016/HID/GamepadDeadzoned.java
import org.usfirst.frc2832.Robot_2016.Coordinate;
import edu.wpi.first.wpilibj.Joystick;

	@Override
	public double getAxis(AxisType axis) {
		return getRawAxis(axis.value);
	}
	
	/**
	 * Radial deadzoning helper method
	 * @param x
	 * @param y
	 * @return
	 */
	private Coordinate deadzone2D(double x, double y) {
		double magnitude = Math.sqrt(x * x + y * y);
		if (magnitude <= range)
			return new Coordinate(0, 0);
		double scale = (magnitude - range) / (1 - range);
		return new Coordinate(x / magnitude * scale, y / magnitude * scale);
	}
	
	@Override
	public double getRawAxis(int axis) {
		if (arrContains(leftstickAxis, axis)) {
			Coordinate p = (deadzone2D(
					super.getRawAxis(leftstickAxis[0]), 
					super.getRawAxis(leftstickAxis[1])));
			if (leftstickAxis[0] == axis)
				return p.getX();
			return p.getY();
		}
		if (arrContains(rightstickAxis, axis)) {
			Coordinate p = (deadzone2D(