private void drawPath(final Graphics2D g, final List<MazeCell> path, final int offset,
boolean trimTail)
{
if (path != null && !path.isEmpty())
{
MazeCell here = path.get(0);
MazeCell there;
int x, y;
int width, height;
for (int i = 1; i < path.size(); i++)
{
there = path.get(i);
// Check for a rare case where a lack of thread safety changes the list while in use.
if (there == null)
return;
final Point center = this.getCellCenterInner(here);
if (here.getX() < there.getX())
{
//here is west of there, going east.
x = center.x + this.csm.getWallWidthHalf();
y = center.y - this.csm.getWallHeightHalf();
width = this.csm.getCellWidth();
height = this.csm.getWallHeight();
}
else if (here.getX() > there.getX())
{
//here is east of there, going west.
x = center.x - this.csm.getWallWidthHalf() - this.csm.getCellWidth();
y = center.y - this.csm.getWallHeightHalf();
width = this.csm.getCellWidth();
height = this.csm.getWallHeight();
}
else if (here.getY() > there.getY())
{
//here is south of there, going north.
x = center.x - this.csm.getWallWidthHalf();
y = center.y - this.csm.getWallHeightHalf() - this.csm.getCellHeight();
width = this.csm.getWallWidth();
height = this.csm.getCellHeight();
}
else
{
//here is north of there, going south.
x = center.x - this.csm.getWallWidthHalf();
y = center.y + this.csm.getWallHeightHalf();
width = this.csm.getWallWidth();
height = this.csm.getCellHeight();
}
// If we are at the last cell and we are trimming the tail up to the robot.
if (i == path.size() - 1 && trimTail && this.robotLocation != null)
{
if (here.getX() < there.getX())
{
//here is west of there, going east.
width = Math.abs(x - this.robotLocation.x);
}
else if (here.getX() > there.getX())
{
//here is east of there, going west.
width -= this.robotLocation.x - x;
x = this.robotLocation.x;
}
else if (here.getY() > there.getY())
{
//here is south of there, going north.
height -= this.robotLocation.y - y;
y = this.robotLocation.y;
}