/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package uk.ac.leeds.ccg.andyt.projects.genesis.society.demography; import uk.ac.leeds.ccg.andyt.projects.genesis.society.environment.Environment; import uk.ac.leeds.ccg.andyt.projects.genesis.society.environment.Location; /** * * @author geoagdt */ public class Movement { /** * This movement is first diagonal then vertical or horizontal. * @param _Location * @param _Destination * @param _Environment * @return */ public static Location getNewLocation_0( Location _Location, Location _Destination, Environment _Environment) { boolean _HandleOutOfMemoryError = _Environment._HandleOutOfMemoryError; long _NRows = _Environment._World_Grid2DSquareCellDouble.get_NRows(_HandleOutOfMemoryError); long _NCols = _Environment._World_Grid2DSquareCellDouble.get_NCols(_HandleOutOfMemoryError); int _Movement; long rowDiff = _Destination._Row - _Location._Row; if (rowDiff < 0) { _Movement = 1; } else { if (rowDiff > 0) { _Movement = 7; } else { _Movement = 4; } } long colDiff = _Destination._Col - _Location._Col; if (colDiff < 0) { _Movement--; } else { if (colDiff > 0) { _Movement++; } } return getNewLocation(_Location, _Movement); } /** * This movement is first horizontal or vertical until destination is on * a diagonal. * @param _Location * @param _Destination * @param _Environment * @return */ public static Location getNewLocation_1( Location _Location, Location _Destination, Environment _Environment) { if (_Location.equals(_Destination)) { return _Location; } boolean _HandleOutOfMemoryError = _Environment._HandleOutOfMemoryError; long _NRows = _Environment._World_Grid2DSquareCellDouble.get_NRows(_HandleOutOfMemoryError); long _NCols = _Environment._World_Grid2DSquareCellDouble.get_NCols(_HandleOutOfMemoryError); int _Movement = 4; long rowDiff = _Destination._Row - _Location._Row; long colDiff = _Destination._Col - _Location._Col; if (Math.abs(rowDiff) > Math.abs(colDiff)) { if (rowDiff < 0) { _Movement = 1; } else { if (rowDiff > 0) { _Movement = 7; } } } else { if (Math.abs(rowDiff) < Math.abs(colDiff)) { if (colDiff < 0) { _Movement = 3; } else { if (colDiff > 0) { _Movement = 5; } } } else { return getNewLocation_0( _Location, _Destination, _Environment); } } return getNewLocation(_Location, _Movement, _Environment); } /** * 0 1 2 * 3 4 5 * 6 7 8 * @param _Location * @param _Movement A value of 4 means no change * @return A new Location giving a row and column location relative to _Movement */ public static Location getNewLocation( Location _Location, int _Movement ) { if (_Movement == 4) { return _Location; } Location result = new Location(); if (_Movement < 3) { result._Row = _Location._Row - 1L; } else { if (_Movement > 5) { result._Row = _Location._Row + 1L; } else { result._Row = _Location._Row; } } if (_Movement == 0 || _Movement == 3 || _Movement == 6) { result._Col = _Location._Col - 1L; } else { if (_Movement == 2 || _Movement == 5 || _Movement == 8) { result._Col = _Location._Col + 1L; } else { result._Col = _Location._Col; } } return result; } /** * This exhibits wrapping in that an agent moving off the top of a grid * appears at the bottom. An agent moving off the right of a grid appears on * the left and vicea versa. (The world can be thought of a bit like the * surface of a taurus). * 0 1 2 * 3 4 5 * 6 7 8 * @param _Location * @param _Movement A value of 4 means no change * @return A new long[] giving a row and column location relative to _Movement */ public static Location getNewLocation( Location _Location, int _Movement, Environment _Environment) { if (_Movement == 4) { return _Location; } boolean _HandleOutOfMemoryError = _Environment._HandleOutOfMemoryError; Location result = new Location(); long _NRows = _Environment._World_Grid2DSquareCellDouble.get_NRows(_HandleOutOfMemoryError); long _NCols = _Environment._World_Grid2DSquareCellDouble.get_NCols(_HandleOutOfMemoryError); if (_Movement < 3) { if (_Location._Row > 0) { result._Row = _Location._Row - 1L; } else { result._Row = _NRows - 1L; } } else { if (_Movement > 5) { if (_Location._Row == _NRows - 1) { result._Row = 0L; } else { result._Row = _Location._Row + 1L; } } else { result._Row = _Location._Row; } } if (_Movement == 0 || _Movement == 3 || _Movement == 6) { if (_Location._Col > 0) { result._Col = _Location._Col - 1L; } else { result._Col = _NCols - 1L; } } else { if (_Movement == 2 || _Movement == 5 || _Movement == 8) { if (_Location._Col == _NCols - 1) { result._Col = 0L; } else { result._Col = _Location._Col + 1L; } } else { result._Col = _Location._Col; } } return result; } }