// Path: src/java/cd4017be/kineng/Main.java
// @Mod(modid = Main.ID, useMetadata = true)
// public class Main {
// 
// 	public static final String ID = "kineng";
// 
// 	@Instance(ID)
// 	public static Main instance;
// 
// 	public static Logger LOG;
// 
// 	@SidedProxy(clientSide = "cd4017be." + ID + ".ClientProxy", serverSide = "cd4017be." + ID + ".CommonProxy")
// 	public static CommonProxy proxy;
// 
// 	public Main() {
// 		RecipeScriptContext.scriptRegistry.add(new Version("kinetic", "/assets/" + ID + "/config/recipes.rcp"));
// 	}
// 
// 	@Mod.EventHandler
// 	public void preInit(FMLPreInitializationEvent event) {
// 		LOG = event.getModLog();
// 		proxy.preInit();
// 		StructureLocations.register();
// 		RecipeScriptContext.instance.run("kinetic.PRE_INIT");
// 	}
// 
// 	@Mod.EventHandler
// 	public void load(FMLInitializationEvent event) {
// 		Objects.init();
// 		proxy.init(new ConfigConstants(RecipeScriptContext.instance.modules.get("kinetic")));
// 	}
// 
// 	@Mod.EventHandler
// 	public void postInit(FMLPostInitializationEvent event) {
// 		Ticking.init();
// 	}
// 
// 	@Mod.EventHandler
// 	public void onShutdown(FMLServerStoppingEvent event) {
// 		Ticking.clear();
// 	}
// 
// }


import java.util.Arrays;
import java.util.Formatter;
import cd4017be.kineng.Main;

package cd4017be.kineng.physics;


/** 
 * @author CD4017BE */
public class Formula {

	static final double PI_2 = Math.PI * 0.5, PI2_3 = Math.PI * 2.0 / 3.0;

	/**@param r [m] radius
	 * @param h [m] height
	 * @return [m^5] the moment of inertia [kg*m²] per density [kg/m³] for a cylinder */
	public static double J_cylinder(double r, double h) {
		r *= r;
		return r * r * h * PI_2;
	}

	/**@param r0 [m] inner radius
	 * @param d0 [kg/m³] inner material density
	 * @param r1 [m] outer radius
	 * @param d1 [kg/m³] outer material density
	 * @param h1 [m] outer height
	 * @return [kgm²] the moment of inertia for two merged cylinders (inner has height 1.0) */
	public static double J_biCylinder(double r0, double d0, double r1, double d1, double h1) {
		return J_cylinder(r0, 1.0 - h1) * d0 + J_cylinder(r1, h1) * d1;
	}

	/**@param r [m] radius
	 * @return [m³] the maximum torsion torque [Nm] per material strength [N/m²] for a circular cross-section */
	public static double torsionStrength_circle(double r) {
		return r * r * r * PI2_3;
	}

	/**@param str [Nm/kg] material strength [N/m²] relative to density [kg/m³]
	 * @param r [m] disk radius
	 * @return [r/s] max angular velocity before material rips apart from centrifugal forces. */
	public static double rip_vel(double str, double r) {
		return Math.sqrt(3.0 * str) / r;
	}

	/**@param a
	 * @param b
	 * @return the exponent base 2 of the relative difference between a and b (usually < 0) */
	public static int relDeltaExp(double a, double b) {
		return Math.getExponent(a - b) - Math.getExponent(a + b);
	}

	/** global matrix for linear algebra (only the server main thread should use this)*/
	public static float[][] MATRIX = new float[4][8];
	public static int m, n;

	/** initialize the {@link #MATRIX} with zeroes and increase size if necessary
	 * @param m number of rows
	 * @param n number of columns
	 */
	public static void initMatrix(int m, int n) {
		int oldM = MATRIX.length, oldN = MATRIX[0].length;
		boolean grow = false;

// Path: src/java/cd4017be/kineng/Main.java
// @Mod(modid = Main.ID, useMetadata = true)
// public class Main {
// 
// 	public static final String ID = "kineng";
// 
// 	@Instance(ID)
// 	public static Main instance;
// 
// 	public static Logger LOG;
// 
// 	@SidedProxy(clientSide = "cd4017be." + ID + ".ClientProxy", serverSide = "cd4017be." + ID + ".CommonProxy")
// 	public static CommonProxy proxy;
// 
// 	public Main() {
// 		RecipeScriptContext.scriptRegistry.add(new Version("kinetic", "/assets/" + ID + "/config/recipes.rcp"));
// 	}
// 
// 	@Mod.EventHandler
// 	public void preInit(FMLPreInitializationEvent event) {
// 		LOG = event.getModLog();
// 		proxy.preInit();
// 		StructureLocations.register();
// 		RecipeScriptContext.instance.run("kinetic.PRE_INIT");
// 	}
// 
// 	@Mod.EventHandler
// 	public void load(FMLInitializationEvent event) {
// 		Objects.init();
// 		proxy.init(new ConfigConstants(RecipeScriptContext.instance.modules.get("kinetic")));
// 	}
// 
// 	@Mod.EventHandler
// 	public void postInit(FMLPostInitializationEvent event) {
// 		Ticking.init();
// 	}
// 
// 	@Mod.EventHandler
// 	public void onShutdown(FMLServerStoppingEvent event) {
// 		Ticking.clear();
// 	}
// 
// }


// Path: src/java/cd4017be/kineng/physics/Formula.java
import java.util.Arrays;
import java.util.Formatter;
import cd4017be.kineng.Main;

package cd4017be.kineng.physics;


/** 
 * @author CD4017BE */
public class Formula {

	static final double PI_2 = Math.PI * 0.5, PI2_3 = Math.PI * 2.0 / 3.0;

	/**@param r [m] radius
	 * @param h [m] height
	 * @return [m^5] the moment of inertia [kg*m²] per density [kg/m³] for a cylinder */
	public static double J_cylinder(double r, double h) {
		r *= r;
		return r * r * h * PI_2;
	}

	/**@param r0 [m] inner radius
	 * @param d0 [kg/m³] inner material density
	 * @param r1 [m] outer radius
	 * @param d1 [kg/m³] outer material density
	 * @param h1 [m] outer height
	 * @return [kgm²] the moment of inertia for two merged cylinders (inner has height 1.0) */
	public static double J_biCylinder(double r0, double d0, double r1, double d1, double h1) {
		return J_cylinder(r0, 1.0 - h1) * d0 + J_cylinder(r1, h1) * d1;
	}

	/**@param r [m] radius
	 * @return [m³] the maximum torsion torque [Nm] per material strength [N/m²] for a circular cross-section */
	public static double torsionStrength_circle(double r) {
		return r * r * r * PI2_3;
	}

	/**@param str [Nm/kg] material strength [N/m²] relative to density [kg/m³]
	 * @param r [m] disk radius
	 * @return [r/s] max angular velocity before material rips apart from centrifugal forces. */
	public static double rip_vel(double str, double r) {
		return Math.sqrt(3.0 * str) / r;
	}

	/**@param a
	 * @param b
	 * @return the exponent base 2 of the relative difference between a and b (usually < 0) */
	public static int relDeltaExp(double a, double b) {
		return Math.getExponent(a - b) - Math.getExponent(a + b);
	}

	/** global matrix for linear algebra (only the server main thread should use this)*/
	public static float[][] MATRIX = new float[4][8];
	public static int m, n;

	/** initialize the {@link #MATRIX} with zeroes and increase size if necessary
	 * @param m number of rows
	 * @param n number of columns
	 */
	public static void initMatrix(int m, int n) {
		int oldM = MATRIX.length, oldN = MATRIX[0].length;
		boolean grow = false;

		if (m > oldM) {
