Some math improvements.

This commit is contained in:
MobiusDev 2017-08-26 00:49:24 +00:00
parent e31b86dd67
commit eaad59b366
30 changed files with 75 additions and 135 deletions

View File

@ -894,7 +894,7 @@ public class L2CharacterAI extends AbstractAI
final double dx = worldPosition.getX() - x;
final double dy = worldPosition.getY() - y;
double dist = Math.sqrt((dx * dx) + (dy * dy));
double dist = Math.hypot(dx, dy);
final double sin = dy / dist;
final double cos = dx / dist;

View File

@ -177,25 +177,18 @@ public class BoatManager
{
for (L2PcInstance player : L2World.getInstance().getPlayers())
{
double dx = (double) player.getX() - point1.getX();
double dy = (double) player.getY() - point1.getY();
if (Math.sqrt((dx * dx) + (dy * dy)) < Config.BOAT_BROADCAST_RADIUS)
if (Math.hypot(player.getX() - point1.getX(), player.getY() - point1.getY()) < Config.BOAT_BROADCAST_RADIUS)
{
for (IClientOutgoingPacket p : packets)
{
player.sendPacket(p);
}
}
else
else if (Math.hypot(player.getX() - point2.getX(), player.getY() - point2.getY()) < Config.BOAT_BROADCAST_RADIUS)
{
dx = (double) player.getX() - point2.getX();
dy = (double) player.getY() - point2.getY();
if (Math.sqrt((dx * dx) + (dy * dy)) < Config.BOAT_BROADCAST_RADIUS)
for (IClientOutgoingPacket p : packets)
{
for (IClientOutgoingPacket p : packets)
{
player.sendPacket(p);
}
player.sendPacket(p);
}
}
}

View File

@ -175,9 +175,7 @@ public class L2Territory
int zmin = _zMin;
for (Point p1 : _points)
{
final double dx = p1._x - x;
final double dy = p1._y - y;
final double distance = Math.sqrt((dx * dx) + (dy * dy));
double distance = Math.hypot(p1._x - x, p1._y - y);
if ((curdistance == 0) || (distance < curdistance))
{
curdistance = distance;

View File

@ -3503,7 +3503,7 @@ public abstract class L2Character extends L2Object implements ISkillsHolder, IDe
double dx = (x - curX);
double dy = (y - curY);
double dz = (z - curZ);
double distance = Math.sqrt((dx * dx) + (dy * dy));
double distance = Math.hypot(dx, dy);
final boolean verticalMovementOnly = isFlying() && (distance == 0) && (dz != 0);
if (verticalMovementOnly)
@ -3522,7 +3522,7 @@ public abstract class L2Character extends L2Object implements ISkillsHolder, IDe
dx = (x - curX);
dy = (y - curY);
dz = (z - curZ);
distance = Math.sqrt((dx * dx) + (dy * dy));
distance = Math.hypot(dx, dy);
}
// Define movement angles needed
@ -3649,7 +3649,7 @@ public abstract class L2Character extends L2Object implements ISkillsHolder, IDe
dx = x - curX;
dy = y - curY;
dz = z - curZ;
distance = verticalMovementOnly ? Math.abs(dz * dz) : Math.sqrt((dx * dx) + (dy * dy));
distance = verticalMovementOnly ? Math.pow(dz, 2) : Math.hypot(dx, dy);
}
// Pathfinding checks. Only when geodata setting is 2, the LoS check gives shorter result
// than the original movement was and the LoS gives a shorter distance than 2000
@ -3723,7 +3723,7 @@ public abstract class L2Character extends L2Object implements ISkillsHolder, IDe
dx = x - curX;
dy = y - curY;
dz = z - curZ;
distance = verticalMovementOnly ? Math.abs(dz * dz) : Math.sqrt((dx * dx) + (dy * dy));
distance = verticalMovementOnly ? Math.pow(dz, 2) : Math.hypot(dx, dy);
sin = dy / distance;
cos = dx / distance;
}
@ -3743,7 +3743,7 @@ public abstract class L2Character extends L2Object implements ISkillsHolder, IDe
// Apply Z distance for flying or swimming for correct timing calculations
if ((isFlying() || isInsideZone(ZoneId.WATER)) && !verticalMovementOnly)
{
distance = Math.sqrt((distance * distance) + (dz * dz));
distance = Math.hypot(distance, dz);
}
// Caclulate the Nb of ticks between the current position and the destination
@ -3827,9 +3827,8 @@ public abstract class L2Character extends L2Object implements ISkillsHolder, IDe
m._yDestination = md.geoPath.get(m.onGeodataPathIndex).getY();
m._zDestination = md.geoPath.get(m.onGeodataPathIndex).getZ();
}
final double dx = (m._xDestination - super.getX());
final double dy = (m._yDestination - super.getY());
final double distance = Math.sqrt((dx * dx) + (dy * dy));
double distance = Math.hypot(m._xDestination - super.getX(), m._yDestination - super.getY());
// Calculate and set the heading of the L2Character
if (distance != 0)
{

View File

@ -152,9 +152,7 @@ public abstract class L2Vehicle extends L2Character
m._zDestination = point.getZ();
m._heading = 0;
final double dx = point.getX() - getX();
final double dy = point.getY() - getY();
final double distance = Math.sqrt((dx * dx) + (dy * dy));
final double distance = Math.hypot(point.getX() - getX(), point.getY() - getY());
if (distance > 1)
{
setHeading(Util.calculateHeadingFrom(getX(), getY(), point.getX(), point.getY()));

View File

@ -107,7 +107,7 @@ public class ZoneCylinder extends L2ZoneForm
@Override
public double getDistanceToZone(int x, int y)
{
return (Math.sqrt((Math.pow(_x - x, 2) + Math.pow(_y - y, 2))) - _rad);
return Math.hypot(_x - x, _y - y) - _rad;
}
// getLowZ() / getHighZ() - These two functions were added to cope with the demand of the new fishing algorithms, wich are now able to correctly place the hook in the water, thanks to getHighZ(). getLowZ() was added, considering potential future modifications.

View File

@ -894,7 +894,7 @@ public class L2CharacterAI extends AbstractAI
final double dx = worldPosition.getX() - x;
final double dy = worldPosition.getY() - y;
double dist = Math.sqrt((dx * dx) + (dy * dy));
double dist = Math.hypot(dx, dy);
final double sin = dy / dist;
final double cos = dx / dist;

View File

@ -177,25 +177,18 @@ public class BoatManager
{
for (L2PcInstance player : L2World.getInstance().getPlayers())
{
double dx = (double) player.getX() - point1.getX();
double dy = (double) player.getY() - point1.getY();
if (Math.sqrt((dx * dx) + (dy * dy)) < Config.BOAT_BROADCAST_RADIUS)
if (Math.hypot(player.getX() - point1.getX(), player.getY() - point1.getY()) < Config.BOAT_BROADCAST_RADIUS)
{
for (IClientOutgoingPacket p : packets)
{
player.sendPacket(p);
}
}
else
else if (Math.hypot(player.getX() - point2.getX(), player.getY() - point2.getY()) < Config.BOAT_BROADCAST_RADIUS)
{
dx = (double) player.getX() - point2.getX();
dy = (double) player.getY() - point2.getY();
if (Math.sqrt((dx * dx) + (dy * dy)) < Config.BOAT_BROADCAST_RADIUS)
for (IClientOutgoingPacket p : packets)
{
for (IClientOutgoingPacket p : packets)
{
player.sendPacket(p);
}
player.sendPacket(p);
}
}
}

View File

@ -175,9 +175,7 @@ public class L2Territory
int zmin = _zMin;
for (Point p1 : _points)
{
final double dx = p1._x - x;
final double dy = p1._y - y;
final double distance = Math.sqrt((dx * dx) + (dy * dy));
double distance = Math.hypot(p1._x - x, p1._y - y);
if ((curdistance == 0) || (distance < curdistance))
{
curdistance = distance;

View File

@ -3503,7 +3503,7 @@ public abstract class L2Character extends L2Object implements ISkillsHolder, IDe
double dx = (x - curX);
double dy = (y - curY);
double dz = (z - curZ);
double distance = Math.sqrt((dx * dx) + (dy * dy));
double distance = Math.hypot(dx, dy);
final boolean verticalMovementOnly = isFlying() && (distance == 0) && (dz != 0);
if (verticalMovementOnly)
@ -3522,7 +3522,7 @@ public abstract class L2Character extends L2Object implements ISkillsHolder, IDe
dx = (x - curX);
dy = (y - curY);
dz = (z - curZ);
distance = Math.sqrt((dx * dx) + (dy * dy));
distance = Math.hypot(dx, dy);
}
// Define movement angles needed
@ -3649,7 +3649,7 @@ public abstract class L2Character extends L2Object implements ISkillsHolder, IDe
dx = x - curX;
dy = y - curY;
dz = z - curZ;
distance = verticalMovementOnly ? Math.abs(dz * dz) : Math.sqrt((dx * dx) + (dy * dy));
distance = verticalMovementOnly ? Math.pow(dz, 2) : Math.hypot(dx, dy);
}
// Pathfinding checks. Only when geodata setting is 2, the LoS check gives shorter result
// than the original movement was and the LoS gives a shorter distance than 2000
@ -3723,7 +3723,7 @@ public abstract class L2Character extends L2Object implements ISkillsHolder, IDe
dx = x - curX;
dy = y - curY;
dz = z - curZ;
distance = verticalMovementOnly ? Math.abs(dz * dz) : Math.sqrt((dx * dx) + (dy * dy));
distance = verticalMovementOnly ? Math.pow(dz, 2) : Math.hypot(dx, dy);
sin = dy / distance;
cos = dx / distance;
}
@ -3743,7 +3743,7 @@ public abstract class L2Character extends L2Object implements ISkillsHolder, IDe
// Apply Z distance for flying or swimming for correct timing calculations
if ((isFlying() || isInsideZone(ZoneId.WATER)) && !verticalMovementOnly)
{
distance = Math.sqrt((distance * distance) + (dz * dz));
distance = Math.hypot(distance, dz);
}
// Caclulate the Nb of ticks between the current position and the destination
@ -3827,9 +3827,8 @@ public abstract class L2Character extends L2Object implements ISkillsHolder, IDe
m._yDestination = md.geoPath.get(m.onGeodataPathIndex).getY();
m._zDestination = md.geoPath.get(m.onGeodataPathIndex).getZ();
}
final double dx = (m._xDestination - super.getX());
final double dy = (m._yDestination - super.getY());
final double distance = Math.sqrt((dx * dx) + (dy * dy));
double distance = Math.hypot(m._xDestination - super.getX(), m._yDestination - super.getY());
// Calculate and set the heading of the L2Character
if (distance != 0)
{

View File

@ -152,9 +152,7 @@ public abstract class L2Vehicle extends L2Character
m._zDestination = point.getZ();
m._heading = 0;
final double dx = point.getX() - getX();
final double dy = point.getY() - getY();
final double distance = Math.sqrt((dx * dx) + (dy * dy));
final double distance = Math.hypot(point.getX() - getX(), point.getY() - getY());
if (distance > 1)
{
setHeading(Util.calculateHeadingFrom(getX(), getY(), point.getX(), point.getY()));

View File

@ -107,7 +107,7 @@ public class ZoneCylinder extends L2ZoneForm
@Override
public double getDistanceToZone(int x, int y)
{
return (Math.sqrt((Math.pow(_x - x, 2) + Math.pow(_y - y, 2))) - _rad);
return Math.hypot(_x - x, _y - y) - _rad;
}
// getLowZ() / getHighZ() - These two functions were added to cope with the demand of the new fishing algorithms, wich are now able to correctly place the hook in the water, thanks to getHighZ(). getLowZ() was added, considering potential future modifications.

View File

@ -894,7 +894,7 @@ public class L2CharacterAI extends AbstractAI
final double dx = worldPosition.getX() - x;
final double dy = worldPosition.getY() - y;
double dist = Math.sqrt((dx * dx) + (dy * dy));
double dist = Math.hypot(dx, dy);
final double sin = dy / dist;
final double cos = dx / dist;

View File

@ -177,25 +177,18 @@ public class BoatManager
{
for (L2PcInstance player : L2World.getInstance().getPlayers())
{
double dx = (double) player.getX() - point1.getX();
double dy = (double) player.getY() - point1.getY();
if (Math.sqrt((dx * dx) + (dy * dy)) < Config.BOAT_BROADCAST_RADIUS)
if (Math.hypot(player.getX() - point1.getX(), player.getY() - point1.getY()) < Config.BOAT_BROADCAST_RADIUS)
{
for (IClientOutgoingPacket p : packets)
{
player.sendPacket(p);
}
}
else
else if (Math.hypot(player.getX() - point2.getX(), player.getY() - point2.getY()) < Config.BOAT_BROADCAST_RADIUS)
{
dx = (double) player.getX() - point2.getX();
dy = (double) player.getY() - point2.getY();
if (Math.sqrt((dx * dx) + (dy * dy)) < Config.BOAT_BROADCAST_RADIUS)
for (IClientOutgoingPacket p : packets)
{
for (IClientOutgoingPacket p : packets)
{
player.sendPacket(p);
}
player.sendPacket(p);
}
}
}

View File

@ -175,9 +175,7 @@ public class L2Territory
int zmin = _zMin;
for (Point p1 : _points)
{
final double dx = p1._x - x;
final double dy = p1._y - y;
final double distance = Math.sqrt((dx * dx) + (dy * dy));
double distance = Math.hypot(p1._x - x, p1._y - y);
if ((curdistance == 0) || (distance < curdistance))
{
curdistance = distance;

View File

@ -3503,7 +3503,7 @@ public abstract class L2Character extends L2Object implements ISkillsHolder, IDe
double dx = (x - curX);
double dy = (y - curY);
double dz = (z - curZ);
double distance = Math.sqrt((dx * dx) + (dy * dy));
double distance = Math.hypot(dx, dy);
final boolean verticalMovementOnly = isFlying() && (distance == 0) && (dz != 0);
if (verticalMovementOnly)
@ -3522,7 +3522,7 @@ public abstract class L2Character extends L2Object implements ISkillsHolder, IDe
dx = (x - curX);
dy = (y - curY);
dz = (z - curZ);
distance = Math.sqrt((dx * dx) + (dy * dy));
distance = Math.hypot(dx, dy);
}
// Define movement angles needed
@ -3649,7 +3649,7 @@ public abstract class L2Character extends L2Object implements ISkillsHolder, IDe
dx = x - curX;
dy = y - curY;
dz = z - curZ;
distance = verticalMovementOnly ? Math.abs(dz * dz) : Math.sqrt((dx * dx) + (dy * dy));
distance = verticalMovementOnly ? Math.pow(dz, 2) : Math.hypot(dx, dy);
}
// Pathfinding checks. Only when geodata setting is 2, the LoS check gives shorter result
// than the original movement was and the LoS gives a shorter distance than 2000
@ -3723,7 +3723,7 @@ public abstract class L2Character extends L2Object implements ISkillsHolder, IDe
dx = x - curX;
dy = y - curY;
dz = z - curZ;
distance = verticalMovementOnly ? Math.abs(dz * dz) : Math.sqrt((dx * dx) + (dy * dy));
distance = verticalMovementOnly ? Math.pow(dz, 2) : Math.hypot(dx, dy);
sin = dy / distance;
cos = dx / distance;
}
@ -3743,7 +3743,7 @@ public abstract class L2Character extends L2Object implements ISkillsHolder, IDe
// Apply Z distance for flying or swimming for correct timing calculations
if ((isFlying() || isInsideZone(ZoneId.WATER)) && !verticalMovementOnly)
{
distance = Math.sqrt((distance * distance) + (dz * dz));
distance = Math.hypot(distance, dz);
}
// Caclulate the Nb of ticks between the current position and the destination
@ -3827,9 +3827,8 @@ public abstract class L2Character extends L2Object implements ISkillsHolder, IDe
m._yDestination = md.geoPath.get(m.onGeodataPathIndex).getY();
m._zDestination = md.geoPath.get(m.onGeodataPathIndex).getZ();
}
final double dx = (m._xDestination - super.getX());
final double dy = (m._yDestination - super.getY());
final double distance = Math.sqrt((dx * dx) + (dy * dy));
double distance = Math.hypot(m._xDestination - super.getX(), m._yDestination - super.getY());
// Calculate and set the heading of the L2Character
if (distance != 0)
{

View File

@ -152,9 +152,7 @@ public abstract class L2Vehicle extends L2Character
m._zDestination = point.getZ();
m._heading = 0;
final double dx = point.getX() - getX();
final double dy = point.getY() - getY();
final double distance = Math.sqrt((dx * dx) + (dy * dy));
final double distance = Math.hypot(point.getX() - getX(), point.getY() - getY());
if (distance > 1)
{
setHeading(Util.calculateHeadingFrom(getX(), getY(), point.getX(), point.getY()));

View File

@ -107,7 +107,7 @@ public class ZoneCylinder extends L2ZoneForm
@Override
public double getDistanceToZone(int x, int y)
{
return (Math.sqrt((Math.pow(_x - x, 2) + Math.pow(_y - y, 2))) - _rad);
return Math.hypot(_x - x, _y - y) - _rad;
}
// getLowZ() / getHighZ() - These two functions were added to cope with the demand of the new fishing algorithms, wich are now able to correctly place the hook in the water, thanks to getHighZ(). getLowZ() was added, considering potential future modifications.

View File

@ -947,7 +947,7 @@ public class L2CharacterAI extends AbstractAI
final double dx = worldPosition.getX() - x;
final double dy = worldPosition.getY() - y;
double dist = Math.sqrt((dx * dx) + (dy * dy));
double dist = Math.hypot(dx, dy);
final double sin = dy / dist;
final double cos = dx / dist;

View File

@ -171,25 +171,18 @@ public class BoatManager
{
for (L2PcInstance player : L2World.getInstance().getPlayers())
{
double dx = (double) player.getX() - point1.getX();
double dy = (double) player.getY() - point1.getY();
if (Math.sqrt((dx * dx) + (dy * dy)) < Config.BOAT_BROADCAST_RADIUS)
if (Math.hypot(player.getX() - point1.getX(), player.getY() - point1.getY()) < Config.BOAT_BROADCAST_RADIUS)
{
for (L2GameServerPacket p : packets)
{
player.sendPacket(p);
}
}
else
else if (Math.hypot(player.getX() - point2.getX(), player.getY() - point2.getY()) < Config.BOAT_BROADCAST_RADIUS)
{
dx = (double) player.getX() - point2.getX();
dy = (double) player.getY() - point2.getY();
if (Math.sqrt((dx * dx) + (dy * dy)) < Config.BOAT_BROADCAST_RADIUS)
for (L2GameServerPacket p : packets)
{
for (L2GameServerPacket p : packets)
{
player.sendPacket(p);
}
player.sendPacket(p);
}
}
}

View File

@ -149,9 +149,7 @@ public class L2Territory
int zmin = _zMin;
for (Point p1 : _points)
{
final double dx = p1._x - x;
final double dy = p1._y - y;
final double distance = Math.sqrt((dx * dx) + (dy * dy));
double distance = Math.hypot(p1._x - x, p1._y - y);
if ((curdistance == 0) || (distance < curdistance))
{
curdistance = distance;

View File

@ -4294,7 +4294,7 @@ public abstract class L2Character extends L2Object implements ISkillsHolder, IDe
double dx = (x - curX);
double dy = (y - curY);
double dz = (z - curZ);
double distance = Math.sqrt((dx * dx) + (dy * dy));
double distance = Math.hypot(dx, dy);
final boolean verticalMovementOnly = isFlying() && (distance == 0) && (dz != 0);
if (verticalMovementOnly)
@ -4313,7 +4313,7 @@ public abstract class L2Character extends L2Object implements ISkillsHolder, IDe
dx = (x - curX);
dy = (y - curY);
dz = (z - curZ);
distance = Math.sqrt((dx * dx) + (dy * dy));
distance = Math.hypot(dx, dy);
}
// @formatter:off
@ -4439,7 +4439,7 @@ public abstract class L2Character extends L2Object implements ISkillsHolder, IDe
dx = x - curX;
dy = y - curY;
dz = z - curZ;
distance = verticalMovementOnly ? Math.abs(dz * dz) : Math.sqrt((dx * dx) + (dy * dy));
distance = verticalMovementOnly ? Math.pow(dz, 2) : Math.hypot(dx, dy);
}
// Pathfinding checks. Only when geodata setting is 2, the LoS check gives shorter result
// than the original movement was and the LoS gives a shorter distance than 2000
@ -4504,7 +4504,7 @@ public abstract class L2Character extends L2Object implements ISkillsHolder, IDe
dx = x - curX;
dy = y - curY;
dz = z - curZ;
distance = verticalMovementOnly ? Math.abs(dz * dz) : Math.sqrt((dx * dx) + (dy * dy));
distance = verticalMovementOnly ? Math.pow(dz, 2) : Math.hypot(dx, dy);
sin = dy / distance;
cos = dx / distance;
}
@ -4525,7 +4525,7 @@ public abstract class L2Character extends L2Object implements ISkillsHolder, IDe
// Apply Z distance for flying or swimming for correct timing calculations
if ((isFlying() || isInsideZone(ZoneId.WATER)) && !verticalMovementOnly)
{
distance = Math.sqrt((distance * distance) + (dz * dz));
distance = Math.hypot(distance, dz);
}
// Caclulate the Nb of ticks between the current position and the destination
@ -4609,9 +4609,8 @@ public abstract class L2Character extends L2Object implements ISkillsHolder, IDe
m._yDestination = md.geoPath.get(m.onGeodataPathIndex).getY();
m._zDestination = md.geoPath.get(m.onGeodataPathIndex).getZ();
}
final double dx = (m._xDestination - super.getX());
final double dy = (m._yDestination - super.getY());
final double distance = Math.sqrt((dx * dx) + (dy * dy));
double distance = Math.hypot(m._xDestination - super.getX(), m._yDestination - super.getY());
// Calculate and set the heading of the L2Character
if (distance != 0)
{

View File

@ -157,9 +157,7 @@ public abstract class L2Vehicle extends L2Character
m._zDestination = point.getZ();
m._heading = 0;
final double dx = point.getX() - getX();
final double dy = point.getY() - getY();
final double distance = Math.sqrt((dx * dx) + (dy * dy));
final double distance = Math.hypot(point.getX() - getX(), point.getY() - getY());
if (distance > 1)
{
setHeading(Util.calculateHeadingFrom(getX(), getY(), point.getX(), point.getY()));

View File

@ -60,7 +60,7 @@ public class ZoneCylinder extends L2ZoneForm
@Override
public double getDistanceToZone(int x, int y)
{
return Math.sqrt(Math.pow(_x - x, 2) + Math.pow(_y - y, 2)) - _rad;
return Math.hypot(_x - x, _y - y) - _rad;
}
// getLowZ() / getHighZ() - These two functions were added to cope with the demand of the new fishing algorithms, wich are now able to correctly place the hook in the water, thanks to getHighZ(). getLowZ() was added, considering potential future modifications.

View File

@ -894,7 +894,7 @@ public class L2CharacterAI extends AbstractAI
final double dx = worldPosition.getX() - x;
final double dy = worldPosition.getY() - y;
double dist = Math.sqrt((dx * dx) + (dy * dy));
double dist = Math.hypot(dx, dy);
final double sin = dy / dist;
final double cos = dx / dist;

View File

@ -177,25 +177,18 @@ public class BoatManager
{
for (L2PcInstance player : L2World.getInstance().getPlayers())
{
double dx = (double) player.getX() - point1.getX();
double dy = (double) player.getY() - point1.getY();
if (Math.sqrt((dx * dx) + (dy * dy)) < Config.BOAT_BROADCAST_RADIUS)
if (Math.hypot(player.getX() - point1.getX(), player.getY() - point1.getY()) < Config.BOAT_BROADCAST_RADIUS)
{
for (IClientOutgoingPacket p : packets)
{
player.sendPacket(p);
}
}
else
else if (Math.hypot(player.getX() - point2.getX(), player.getY() - point2.getY()) < Config.BOAT_BROADCAST_RADIUS)
{
dx = (double) player.getX() - point2.getX();
dy = (double) player.getY() - point2.getY();
if (Math.sqrt((dx * dx) + (dy * dy)) < Config.BOAT_BROADCAST_RADIUS)
for (IClientOutgoingPacket p : packets)
{
for (IClientOutgoingPacket p : packets)
{
player.sendPacket(p);
}
player.sendPacket(p);
}
}
}

View File

@ -175,9 +175,7 @@ public class L2Territory
int zmin = _zMin;
for (Point p1 : _points)
{
final double dx = p1._x - x;
final double dy = p1._y - y;
final double distance = Math.sqrt((dx * dx) + (dy * dy));
double distance = Math.hypot(p1._x - x, p1._y - y);
if ((curdistance == 0) || (distance < curdistance))
{
curdistance = distance;

View File

@ -3503,7 +3503,7 @@ public abstract class L2Character extends L2Object implements ISkillsHolder, IDe
double dx = (x - curX);
double dy = (y - curY);
double dz = (z - curZ);
double distance = Math.sqrt((dx * dx) + (dy * dy));
double distance = Math.hypot(dx, dy);
final boolean verticalMovementOnly = isFlying() && (distance == 0) && (dz != 0);
if (verticalMovementOnly)
@ -3522,7 +3522,7 @@ public abstract class L2Character extends L2Object implements ISkillsHolder, IDe
dx = (x - curX);
dy = (y - curY);
dz = (z - curZ);
distance = Math.sqrt((dx * dx) + (dy * dy));
distance = Math.hypot(dx, dy);
}
// Define movement angles needed
@ -3649,7 +3649,7 @@ public abstract class L2Character extends L2Object implements ISkillsHolder, IDe
dx = x - curX;
dy = y - curY;
dz = z - curZ;
distance = verticalMovementOnly ? Math.abs(dz * dz) : Math.sqrt((dx * dx) + (dy * dy));
distance = verticalMovementOnly ? Math.pow(dz, 2) : Math.hypot(dx, dy);
}
// Pathfinding checks. Only when geodata setting is 2, the LoS check gives shorter result
// than the original movement was and the LoS gives a shorter distance than 2000
@ -3723,7 +3723,7 @@ public abstract class L2Character extends L2Object implements ISkillsHolder, IDe
dx = x - curX;
dy = y - curY;
dz = z - curZ;
distance = verticalMovementOnly ? Math.abs(dz * dz) : Math.sqrt((dx * dx) + (dy * dy));
distance = verticalMovementOnly ? Math.pow(dz, 2) : Math.hypot(dx, dy);
sin = dy / distance;
cos = dx / distance;
}
@ -3743,7 +3743,7 @@ public abstract class L2Character extends L2Object implements ISkillsHolder, IDe
// Apply Z distance for flying or swimming for correct timing calculations
if ((isFlying() || isInsideZone(ZoneId.WATER)) && !verticalMovementOnly)
{
distance = Math.sqrt((distance * distance) + (dz * dz));
distance = Math.hypot(distance, dz);
}
// Caclulate the Nb of ticks between the current position and the destination
@ -3827,9 +3827,8 @@ public abstract class L2Character extends L2Object implements ISkillsHolder, IDe
m._yDestination = md.geoPath.get(m.onGeodataPathIndex).getY();
m._zDestination = md.geoPath.get(m.onGeodataPathIndex).getZ();
}
final double dx = (m._xDestination - super.getX());
final double dy = (m._yDestination - super.getY());
final double distance = Math.sqrt((dx * dx) + (dy * dy));
double distance = Math.hypot(m._xDestination - super.getX(), m._yDestination - super.getY());
// Calculate and set the heading of the L2Character
if (distance != 0)
{

View File

@ -152,9 +152,7 @@ public abstract class L2Vehicle extends L2Character
m._zDestination = point.getZ();
m._heading = 0;
final double dx = point.getX() - getX();
final double dy = point.getY() - getY();
final double distance = Math.sqrt((dx * dx) + (dy * dy));
final double distance = Math.hypot(point.getX() - getX(), point.getY() - getY());
if (distance > 1)
{
setHeading(Util.calculateHeadingFrom(getX(), getY(), point.getX(), point.getY()));

View File

@ -107,7 +107,7 @@ public class ZoneCylinder extends L2ZoneForm
@Override
public double getDistanceToZone(int x, int y)
{
return (Math.sqrt((Math.pow(_x - x, 2) + Math.pow(_y - y, 2))) - _rad);
return Math.hypot(_x - x, _y - y) - _rad;
}
// getLowZ() / getHighZ() - These two functions were added to cope with the demand of the new fishing algorithms, wich are now able to correctly place the hook in the water, thanks to getHighZ(). getLowZ() was added, considering potential future modifications.