/** * Get the closest spot on this trip to the location given, in meters. If this trip has no spots, * it returns null. * * @param location A Locatable * @return The spot closst to the location given. */ public LocatedSpot getClosestSpot(final Locatable location) { if (spots == null || spots.size() == 0) { return null; } // Copy this so we can reorder them without altering the order // in the copy the trip object keeps. final List<LocatedSpot> spotClone = new LinkedList<LocatedSpot>(spots); Collections.sort(spotClone, new DistanceComparator(location.getGeoLocation())); return spotClone.get(0); }
/** delegates default locate to the loEndpoint */ public void setRelocate() { loEndpoint.setRelocate(); }
/** * provides Locatable interface for both endpoints * * @param point * @param shape * @return */ private Locatable endpoint(Point3d point, TransformGroup shape) { Locatable endpoint = new Locatable() { private Point3d position; private TransformGroup shape; public void setShape(TransformGroup shape) { this.shape = shape; } @Override public Point3d getPosition() { return (Point3d) position.clone(); } /** * this allows the positions of the endpoints to be set in sequence when we add a new * ScaleInstrument. * * @see boogiepants.model.Locatable#setPosition(javax.vecmath.Point3d) */ @Override public void setPosition(Point3d position) { if (this.position == null) { this.position = position; } else { this.position.set(position); } if (ScaleLineInstrument.this.loEndpoint == this && ScaleLineInstrument.this.hiEndpoint.getPosition().equals(zeroPoint)) { ScaleLineInstrument.this.hiEndpoint.setRelocate(); } if (behavior != null) { behavior.computeLineLen(); } } @Override public void setRelocate() { setRelocate(.9); } @Override public void setRelocate(double distance) { EditPositionBehavior posEdit = EditPositionBehavior.getInstance(); posEdit.setInstrument(this); posEdit.setTransformGroup(shape); posEdit.initLocPoint(distance); BranchGroup bg = posEdit.getGroup(); editGroup.addChild(bg); } public String toString() { String name = (ScaleLineInstrument.this.loEndpoint == this) ? "loEndpoint" : "hiEndpoint"; return name + " " + position; } public void delete() { ScaleLineInstrument.this.delete(); } }; endpoint.setShape(shape); endpoint.setPosition(point); return endpoint; }
/** * Get how far away the closest spot on this trip is to the given point. A distance of zero is * returned when the trip has no spots; * * @param location A Locatable. * @return Distance, in meters. */ public long getDistanceMetersToClosestSpot(final Locatable location) { final LocatedSpot closest = getClosestSpot(location); return closest == null ? 0 : location.getGeoLocation().getDistanceMeters(closest.getGeoLocation()); }