[Committed] Possible Bug in LineSegment

I'm making LineSegments from two Vectors,

like here in the Example: from (0,0,0) to (0,0,2)



so the extent should be 1… am I right?

And the positiveEnd should be (0,0,2) and the negativeEnd(0,0,0)…



but in the output, it says:

run:
Extent: 2.0
NegEnd: com.jme.math.Vector3f [X=0.0, Y=0.0, Z=-1.0]
PosEnd: com.jme.math.Vector3f [X=0.0, Y=0.0, Z=3.0]
BUILD SUCCESSFUL (total time: 0 seconds)


public static void main(String[] args) {
      LineSegment seg = new LineSegment(Vector3f.ZERO.clone(),
            new Vector3f(0,0,2));
      System.out.println("Extent: " + seg.getExtent());
      System.out.println("NegEnd: " + seg.getNegativeEnd(null));
      System.out.println("PosEnd: " + seg.getPositiveEnd(null));
   }



Is this a feature or a bug? :D
In the LineSegment code, it explictly sais start and end..
I've got a Bugfix already, but first I want to be sure, that it isn't my faut.. ;)

So… Nobody seems to care of this :wink:



Anyway, the fix though:



Change

public LineSegment(Vector3f start, Vector3f end) {
      this.origin = new Vector3f(0.5f * (start.x + end.x), 0.5f * (start.y + end.y), 0.5f * (start.z + end.z));
      this.direction = end.subtract(start);
      this.extent = direction.length();
      direction.normalizeLocal();
   }


to:

public LineSegment(Vector3f start, Vector3f end) {
      this.origin = new Vector3f(0.5f * (start.x + end.x), 0.5f * (start.y + end.y), 0.5f * (start.z + end.z));
      this.direction = end.subtract(start);
      this.extent = direction.length() / 2;
      direction.normalizeLocal();
   }



I also wants to add equals() and hashcode() to LineSegment, cause I use it in a BSP-Tree..

Hello.



I am responsible for that, I added that method and documentation in rev 4060 (http://code.google.com/p/jmonkeyengine/source/diff?spec=svn4060&r=4060&format=side&path=/trunk/src/com/jme/math/LineSegment.java&old_path=/trunk/src/com/jme/math/LineSegment.java&old=3977)



I think you are right. Extent should be divided by 2.



I have committed your fix to the repository. Feel free to post .hashCode() and .equals() methods if you wish.



Thank you for catching that :).