rescuecore.tools.mapgenerator
Class RescueMapToolkit

java.lang.Object
  extended byrescuecore.tools.mapgenerator.RescueMapToolkit

public class RescueMapToolkit
extends java.lang.Object

A toolkit class with useful methods for manipulating RescueMaps.


Constructor Summary
RescueMapToolkit()
           
 
Method Summary
static double angle(RescueMap m, int n1, int n2, int n3)
          Gets the angle between two connected sets of nodes.
static int area(int[][] api)
          Find the area of a building (in 100ths of sqr meters) from the apexes.
static int[] centre(int[][] api)
          Gets the centre of a building from its apexes.
static void findIntersections(RescueMap m)
          Finds any overlapping roads and creates a new node at their intersection.
static boolean intersects(int x1, int y1, int x2, int y2, int[][] api)
          Finds if an intersection of a line with a polygon exists.
static boolean isLeft(int x, int y, int ax, int ay, int bx, int by)
          Whether a point is left of a directed line.
static int makeEntrance(RescueMap rm, int[] centre)
          Splits a road to make a new entrance node.
static int[] nearestPoint(RescueMap m, int x, int y, int n1, int n2)
          Gets the closest point on a road to a given point.
static void randomise(RescueMap m, int uniformity, int density, int movement, boolean nooneway, java.util.Random rand)
          Shifts some nodes in the map by random distances and removes a number of randomly selected roads.
static void rotate(RescueMap m, double radians)
          Rotate all nodes of a RescueMap.
static void smoothRoads(RescueMap m, int size)
          Rounds the corners of wide roads.
static int[][][] split(int[][] build, int x1, int y1, int x2, int y2)
          Splits a building across a line.
static long tArea(int x1, int y1, long m1, int x2, int y2, long m2)
          Area of the triangle formed by two vectors.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RescueMapToolkit

public RescueMapToolkit()
Method Detail

randomise

public static void randomise(RescueMap m,
                             int uniformity,
                             int density,
                             int movement,
                             boolean nooneway,
                             java.util.Random rand)
Shifts some nodes in the map by random distances and removes a number of randomly selected roads.

Parameters:
m - The RescueMap to alter.
uniformity - Indicates how likely any given node is to be moved, from 0..100.
density - Indicates how likely it is that a road be removed, from 0..100.
movement - The maximum distance a node will be moved in meters.
nooneway - Whether we are allowed to remove roads in only one direction at a time.
rand - The random number generator.

rotate

public static void rotate(RescueMap m,
                          double radians)
Rotate all nodes of a RescueMap. This should be applied BEFORE any buildings are added.

Parameters:
m - The RescueMap to rotate.
radians - The number of radians to rotate by.

findIntersections

public static void findIntersections(RescueMap m)
Finds any overlapping roads and creates a new node at their intersection.

Parameters:
m - The RescueMap to work on.

smoothRoads

public static void smoothRoads(RescueMap m,
                               int size)
Rounds the corners of wide roads.

Parameters:
m - The RescueMap to smooth the roads of.
size - The minimum size of roads to smooth - given in total lanes for both directions.

angle

public static double angle(RescueMap m,
                           int n1,
                           int n2,
                           int n3)
Gets the angle between two connected sets of nodes.

Parameters:
m - The RescueMap holding the nodes.
n1 - The first node.
n2 - The connecting (middle) node.
n3 - The third node.
Returns:
A number between 0 and Pi*2. Eg: 0.01 indicates a road turning slightly left, 6.28 indicates one turning slightly right.

centre

public static int[] centre(int[][] api)
Gets the centre of a building from its apexes. Not a smart algorithm.

Parameters:
api - The apexes of the building.
Returns:
An integer array of form {x,y} giving the centre coordinates.

area

public static int area(int[][] api)
Find the area of a building (in 100ths of sqr meters) from the apexes. The apexes are assumed to double up on first and last vertices.

Parameters:
api - The apexes of the building.
Returns:
The area.

tArea

public static long tArea(int x1,
                         int y1,
                         long m1,
                         int x2,
                         int y2,
                         long m2)
Area of the triangle formed by two vectors.

Parameters:
x1 - x coordinate of the first vector.
y1 - y coordinate of the first vector.
m1 - The magnitude of the first vector.
x2 - x coordinate of the second vector.
y2 - y coordinate of the second vector.
m2 - The magnitude of the second vector.
Returns:
The area of the triangle.

isLeft

public static boolean isLeft(int x,
                             int y,
                             int ax,
                             int ay,
                             int bx,
                             int by)
Whether a point is left of a directed line.

Parameters:
x - The x coordinate of the point.
y - The y coordinate of the point.
ax - The x coordinate of the first point of the line.
ay - The y coordinate of the first point of the line.
bx - The x coordinate of the second point of the line.
by - The y coordinate of the second point of the line.
Returns:
True if x,y is to the left of the line, otherwise false.

nearestPoint

public static int[] nearestPoint(RescueMap m,
                                 int x,
                                 int y,
                                 int n1,
                                 int n2)
Gets the closest point on a road to a given point.

Parameters:
m - The RescueMap holding the road.
x - The x coordinate of the point.
y - The y coordinate of the point.
n1 - The first node of the road.
n2 - The second node of the road.
Returns:
The coordinates of the nearest point as an array of form {x,y}.

makeEntrance

public static int makeEntrance(RescueMap rm,
                               int[] centre)
Splits a road to make a new entrance node. This will be the nearest point on the nearest road in the map.

Parameters:
rm - The RescueMap to add the entrance node to.
centre - The centre of the building that needs an entrance.
Returns:
The new entrance node.

split

public static int[][][] split(int[][] build,
                              int x1,
                              int y1,
                              int x2,
                              int y2)
Splits a building across a line. The building should not yet be added to a RescueMap.

Parameters:
build - The apexes of the building.
x1 - The x coordinates of the first point on the line.
y1 - The y coordinates of the first point on the line.
x2 - The x coordinates of the second point on the line.
y2 - The y coordinates of the second point on the line.
Returns:
The two new polygons. An array of size [2][polygonsize][coordinates].

intersects

public static boolean intersects(int x1,
                                 int y1,
                                 int x2,
                                 int y2,
                                 int[][] api)
Finds if an intersection of a line with a polygon exists.

Parameters:
x1 - x coordinate of the first point on the line.
y1 - y coordinate of the first point on the line.
x2 - x coordinate of the second point on the line.
y2 - y coordinate of the second point on the line.
api - The apexes of the polygon to check.
Returns:
True if an intersection exists, otherwise false.