package com.thegongoliers.input.odometry;

import edu.wpi.first.wpilibj.Encoder;

public class EncoderUtils {

    public static void addGearRatio(Encoder encoder, double gearRatio){
        double distancePerPulse = encoder.getDistancePerPulse();
        encoder.setDistancePerPulse(distancePerPulse * gearRatio);
    }

    public static void addMechanism(Encoder encoder, double distancePerRevolution){
        double degPerPulse = encoder.getDistancePerPulse();
        double distancePerDegree = distancePerRevolution / 360.0;
        encoder.setDistancePerPulse(distancePerDegree * degPerPulse);
    }

    public static void setPulsesPerRevolution(Encoder encoder, double pulses){
        double degreesPerPulse = pulses / 360.0;
        encoder.setDistancePerPulse(degreesPerPulse);
    }

    public static void addWheel(Encoder encoder, double diameter){
        double distancePerRevolution = diameter * Math.PI;
        addMechanism(encoder, distancePerRevolution);
    }

    public class EncoderDistanceBuilder {
        private Encoder encoder;

        public EncoderDistanceBuilder(Encoder encoder, double encoderPulsesPerRevolution){
            this.encoder = encoder;
            EncoderUtils.setPulsesPerRevolution(encoder, encoderPulsesPerRevolution);
        }

        public EncoderDistanceBuilder addGearRatio(double gearRatio){
            EncoderUtils.addGearRatio(encoder, gearRatio);
            return this;
        }

        public EncoderDistanceBuilder addMechanism(double distancePerRevolution){
            EncoderUtils.addMechanism(encoder, distancePerRevolution);
            return this;
        }

        public EncoderDistanceBuilder addWheel(double diameter){
            EncoderUtils.addWheel(encoder, diameter);
            return this;
        }

        public Encoder build(){
            return encoder;
        }

    }

}

@@ -410,29 +410,8 @@
     
- double degPerPulse =
  enc
@@ -407,33 +407,33 @@
         encoder.
-g
+s
 etDistancePerPul
@@ -439,46 +439,8 @@
 lse(
-);%0A        double distancePerDegree = 
 dist
@@ -457,32 +457,17 @@
 olution 
-/ 360.0;%0A       
+*
  encoder
@@ -459,33 +459,33 @@
 ution * encoder.
-s
+g
 etDistancePerPul
@@ -491,39 +491,9 @@
 lse(
-distancePerDegree * degPerPulse
+)
 );%0A 
@@ -589,49 +589,30 @@
     
-double degreesPerPulse = pulses / 360.0;%0A
+if(pulses != 0) %7B%0A    
     
@@ -647,26 +647,31 @@
 lse(
-degreesPerP
+1 / p
 ulse
+s
 );%0A
+        %7D%0A
     
@@ -852,32 +852,187 @@
 lution);%0A    %7D%0A%0A
+    public static void addFudgeFactor(Encoder encoder, double factor)%7B%0A        encoder.setDistancePerPulse(encoder.getDistancePerPulse() * factor);%0A    %7D%0A%0A
     public class
@@ -1816,32 +1816,205 @@
 his;%0A        %7D%0A%0A
+        public EncoderDistanceBuilder addFudgeFactor(double fudgeFactor)%7B%0A            EncoderUtils.addFudgeFactor(encoder, fudgeFactor);%0A            return this;%0A        %7D%0A%0A
         public E

Fix encoder utils