| /******************************************************************************* |
| * Copyright (c) 2018 Agence spatiale canadienne / Canadian Space Agency |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License v1.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/epl-v10.html |
| * |
| * Contributors: |
| * Pierre Allard, |
| * Regent L'Archeveque, |
| * Sebastien Gemme - initial API and implementation |
| * |
| * SPDX-License-Identifier: EPL-1.0 |
| * |
| *******************************************************************************/ |
| package org.eclipse.apogy.core.impl; |
| |
| import javax.vecmath.Matrix4d; |
| import javax.vecmath.Point3d; |
| import javax.vecmath.Vector3d; |
| |
| import org.eclipse.apogy.core.Positioned; |
| |
| public class DistanceComparatorCustomImpl<T extends Positioned> extends DistanceComparatorImpl<T> { |
| @Override |
| public int compare(Positioned o1, Positioned o2) { |
| Point3d point = new Point3d(getPosition().asTuple3d()); |
| |
| Matrix4d m1 = o1.getPose().asMatrix4d(); |
| Vector3d p1 = new Vector3d(); |
| m1.get(p1); |
| |
| Matrix4d m2 = o2.getPose().asMatrix4d(); |
| Vector3d p2 = new Vector3d(); |
| m2.get(p2); |
| |
| double distance1 = point.distance(new Point3d(p1)); |
| double distance2 = point.distance(new Point3d(p2)); |
| |
| if (distance1 > distance2) { |
| return 1; |
| } else if (distance1 < distance2) { |
| return -1; |
| } else { |
| return 0; |
| } |
| } |
| |
| } // DistanceComparatorImpl |