/*
 * FXGL - JavaFX Game Library. The MIT License (MIT).
 * Copyright (c) AlmasB (almaslvl@gmail.com).
 * See LICENSE for details.
 */
/*
 * JBox2D - A Java Port of Erin Catto's Box2D
 * 
 * JBox2D homepage: http://jbox2d.sourceforge.net/
 * Box2D homepage: http://www.box2d.org
 * 
 * This software is provided 'as-is', without any express or implied
 * warranty.  In no event will the authors be held liable for any damages
 * arising from the use of this software.
 * 
 * Permission is granted to anyone to use this software for any purpose,
 * including commercial applications, and to alter it and redistribute it
 * freely, subject to the following restrictions:
 * 
 * 1. The origin of this software must not be misrepresented; you must not
 * claim that you wrote the original software. If you use this software
 * in a product, an acknowledgment in the product documentation would be
 * appreciated but is not required.
 * 2. Altered source versions must be plainly marked as such, and must not be
 * misrepresented as being the original software.
 * 3. This notice may not be removed or altered from any source distribution.
 */

package com.almasb.fxgl.physics.box2d.dynamics.joints;

import com.almasb.fxgl.core.math.Vec2;
import com.almasb.fxgl.physics.box2d.dynamics.Body;
import com.almasb.fxgl.physics.box2d.dynamics.World;

//Updated to rev 56->130->142 of b2DistanceJoint.cpp/.h

/**
 * Distance joint definition. This requires defining an anchor point on both bodies and the non-zero
 * length of the distance joint. The definition uses local anchor points so that the initial
 * configuration can violate the constraint slightly. This helps when saving and loading a game.
 *
 * @warning Do not use a zero or short length.
 */
public class DistanceJointDef extends JointDef<DistanceJoint> {
    /** The local anchor point relative to body1's origin. */
    public final Vec2 localAnchorA;

    /** The local anchor point relative to body2's origin. */
    public final Vec2 localAnchorB;

    /** The equilibrium length between the anchor points. */
    public float length;

    /**
     * The mass-spring-damper frequency in Hertz.
     */
    public float frequencyHz;

    /**
     * The damping ratio. 0 = no damping, 1 = critical damping.
     */
    public float dampingRatio;

    public DistanceJointDef() {
        localAnchorA = new Vec2(0.0f, 0.0f);
        localAnchorB = new Vec2(0.0f, 0.0f);
        length = 1.0f;
        frequencyHz = 0.0f;
        dampingRatio = 0.0f;
    }

    /**
     * Initialize the bodies, anchors, and length using the world anchors.
     *
     * @param b1 First body
     * @param b2 Second body
     * @param anchor1 World anchor on first body
     * @param anchor2 World anchor on second body
     */
    public void initialize(final Body b1, final Body b2, final Vec2 anchor1, final Vec2 anchor2) {
        setBodyA(b1);
        setBodyB(b2);
        localAnchorA.set(b1.getLocalPoint(anchor1));
        localAnchorB.set(b2.getLocalPoint(anchor2));
        Vec2 d = anchor2.sub(anchor1);
        length = d.length();
    }

    @Override
    protected DistanceJoint createJoint(World world) {
        return new DistanceJoint(world.getPool(), this);
    }
}

@@ -179,17 +179,16 @@
 Box2D%0A *
- 
 %0A * JBox
@@ -273,17 +273,16 @@
 d.org%0A *
- 
 %0A * This
@@ -461,17 +461,16 @@
 ware.%0A *
- 
 %0A * Perm
@@ -661,17 +661,16 @@
 ions:%0A *
- 
 %0A * 1. T
@@ -1334,65 +1334,8 @@
 d;%0A%0A
-//Updated to rev 56-%3E130-%3E142 of b2DistanceJoint.cpp/.h%0A%0A
 /**%0A
@@ -1363,16 +1363,19 @@
 inition.
+%0A *
  This re
@@ -1437,19 +1437,16 @@
 non-zero
-%0A *
  length 
@@ -1467,16 +1467,19 @@
 e joint.
+%0A *
  The def
@@ -1530,19 +1530,16 @@
  initial
-%0A *
  configu
@@ -1581,16 +1581,19 @@
 lightly.
+%0A *
  This he
@@ -1634,20 +1634,8 @@
 .%0A *
-%0A * @warning
  Do 
@@ -1734,23 +1734,31 @@
 oint%3E %7B%0A
+%0A
     /**
+%0A     *
  The loc
@@ -1792,32 +1792,37 @@
  body1's origin.
+%0A    
  */%0A    public f
@@ -1843,16 +1843,29 @@
 lAnchorA
+ = new Vec2()
 ;%0A%0A    /
@@ -1862,24 +1862,31 @@
 ();%0A%0A    /**
+%0A     *
  The local a
@@ -1924,16 +1924,21 @@
  origin.
+%0A    
  */%0A    
@@ -1967,16 +1967,29 @@
 lAnchorB
+ = new Vec2()
 ;%0A%0A    /
@@ -1990,16 +1990,23 @@
 %0A    /**
+%0A     *
  The equ
@@ -2047,16 +2047,21 @@
  points.
+%0A    
  */%0A    
@@ -2079,16 +2079,23 @@
 t length
+ = 1.0f
 ;%0A%0A    /
@@ -2183,16 +2183,23 @@
 quencyHz
+ = 0.0f
 ;%0A%0A    /
@@ -2226,16 +2226,23 @@
 g ratio.
+%0A     *
  0 = no 
@@ -2313,218 +2313,16 @@
 atio
-;%0A%0A    public DistanceJointDef() %7B%0A        localAnchorA = new Vec2(0.0f, 0.0f);%0A        localAnchorB = new Vec2(0.0f, 0.0f);%0A        length = 1.0f;%0A        frequencyHz = 0.0f;%0A        dampingRatio = 0.0f;%0A    %7D
+ = 0.0f;
 %0A%0A  
@@ -2413,65 +2413,8 @@
   *%0A
-     * @param b1 First body%0A     * @param b2 Second body%0A
     
@@ -2547,22 +2547,16 @@
 ize(
-final 
 Body b1,
  fin
@@ -2551,22 +2551,16 @@
 Body b1,
- final
  Body b2
@@ -2560,22 +2560,16 @@
 Body b2,
- final
  Vec2 an
@@ -2574,22 +2574,16 @@
 anchor1,
- final
  Vec2 an

clean up