I see some more optimization potential in the Vertex class above.
public Point Position
{
get;
set;
}
I think it would be faster as a variable and not a property.
public Point[] Adjacents
{
get
{
On each get on the above property you do some computations. You should do some caching and recompute only when necessary (position changed?).
for (var x = this.Position.X - 1; x <= this.Position.X + 1; x++)
{
for (var y = this.Position.Y - 1; y <= this.Position.Y + 1; y++)
{
if ((x < 0) || (x >= AireDeJeu.longueur) || (y < 0) || (y >= AireDeJeu.largeur)) continue;
if ((((x == this.Position.X) && (y == this.Position.Y)))) continue;
}
}
could improve to:
for (var x = this.Position.X - 1; x <= this.Position.X + 1; x++)
{
if ((x < 0) || (x >= AireDeJeu.longueur)) continue;
for (var y = this.Position.Y - 1; y <= this.Position.Y + 1; y++)
{
if ((y < 0) || (y >= AireDeJeu.largeur)) continue;
if ((((x == this.Position.X) && (y == this.Position.Y)))) continue;
}
}
In this way, you make less comparisons since x changes only in the first for and y in the second one.
_adjBuffer[currPoint++] = (new Point(x, y));
you recreate a Point in a position every time you do a get on that property. If your memory allows it, create all the points on init and afterwards just set the X and the Y in the desired position or do the following:
if (_adjBuffer[currPoint] == null) _adjBuffer[currPoint++] = new Point(x,y);
else
{
_adjBuffer[currPoint].X = x;
_adjBuffer[currPoint++].Y = y;
}
// Return the used items from buffer.
var ret = new Point[currPoint];
for (var n = 0; n < currPoint; n++)
{
ret[n] = _adjBuffer[n];
}
return ret;
It would be a lot more faster to return _adjBuffer than recreating an array with currPoint. Of course, you would need to know how many elements are used in the buffer. In this case you could do something like this:
_adjBuffer[currPoint] = null;
return _adjBuffer;
and when you iterate trough Adjacents, stop when you find a null.