at.tuwien.ifs.somtoolbox.visualization
Class Snapper2D

java.lang.Object
  extended by at.tuwien.ifs.somtoolbox.visualization.Snapper
      extended by at.tuwien.ifs.somtoolbox.visualization.Snapper2D

public class Snapper2D
extends Snapper


Field Summary
private  Point2D[] grid
           
private  double[] gridDiffs
           
private  double[] gridSums
           
 
Fields inherited from class at.tuwien.ifs.somtoolbox.visualization.Snapper
distanceFunction, lineDistanceFunction
 
Constructor Summary
Snapper2D(AbstractMetric distanceFunction, DistanceFunctionType lineDistanceFunction, int xSize, int ySize)
           
 
Method Summary
 Point2D[] createGrid(int xSize, int ySize)
           
 Point2D[] getNeighbouringUnits(Point2D p)
          Finds the four units around the given point.
 Point2D[] snap(Point2D[] line)
          Returns a snapped line of the given line.
 Point2D[][] snap(Point2D[][] lines)
           
private  Point2D[] snapPoint(Point2D startPoint, Point2D[] line, int currentPosition, int direction)
          Snaps the next point on the line.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

grid

private Point2D[] grid

gridSums

private double[] gridSums

gridDiffs

private double[] gridDiffs
Constructor Detail

Snapper2D

public Snapper2D(AbstractMetric distanceFunction,
                 DistanceFunctionType lineDistanceFunction,
                 int xSize,
                 int ySize)
Method Detail

createGrid

public Point2D[] createGrid(int xSize,
                            int ySize)

snapPoint

private Point2D[] snapPoint(Point2D startPoint,
                            Point2D[] line,
                            int currentPosition,
                            int direction)
Snaps the next point on the line.

Parameters:
startPoint - the point to start from
line - the line to snap
currentPosition - the current position on the line
direction - forward (1) or backwards (-1)
Returns:
a snapped line

snap

public Point2D[][] snap(Point2D[][] lines)

snap

public Point2D[] snap(Point2D[] line)
Returns a snapped line of the given line. Snapping the metro lines means to find a line as similar as possible to the given line, which has all bin centres in the unit centres, and line segments are connected in multiples of 45° degree angles to each other.
TODO: Consider disallowing 135° / 315° as too sharp turns.


getNeighbouringUnits

public Point2D[] getNeighbouringUnits(Point2D p)
Finds the four units around the given point.

Parameters:
p - point to find neighbours for.
Returns:
four neighbours.