IntersectionDistanceComparator.java :  » Scripting » gml-tracer » de » hauschild » gmltracer » tracer » impl » tier1 » Java Open Source

Java Open Source » Scripting » gml tracer 
gml tracer » de » hauschild » gmltracer » tracer » impl » tier1 » IntersectionDistanceComparator.java
package de.hauschild.gmltracer.tracer.impl.tier1;

import java.util.Comparator;

import de.hauschild.gmltracer.tracer.Intersection;

/**
 * Compares {@link Intersection} by distance of {@link Intersection#getPoint()} to coordinate system origin. Nearer
 * first.
 * 
 * @since 1.0.0
 * @author Klaus Hauschild
 */
public class IntersectionDistanceComparator implements Comparator<Intersection> {

  /**
   * Instantiates a new {@link IntersectionDistanceComparator}.
   */
  public IntersectionDistanceComparator() {
  }

  @Override
  public int compare(final Intersection firstIntersection, final Intersection secondIntersection) {
    final double firstSquareLength = firstIntersection.getPoint().getX() * firstIntersection.getPoint().getX()
        + firstIntersection.getPoint().getY() * firstIntersection.getPoint().getY()
        + firstIntersection.getPoint().getZ() * firstIntersection.getPoint().getZ();
    final double secondSquareLength = secondIntersection.getPoint().getX() * secondIntersection.getPoint().getX()
        + secondIntersection.getPoint().getY() * secondIntersection.getPoint().getY()
        + secondIntersection.getPoint().getZ() * secondIntersection.getPoint().getZ();
    return (int) (firstSquareLength - secondSquareLength);
  }

}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.