diff --git a/L2J_Mobius_Classic/java/com/l2jmobius/gameserver/ai/L2CharacterAI.java b/L2J_Mobius_Classic/java/com/l2jmobius/gameserver/ai/L2CharacterAI.java index c5cab58d48..0d66c4a387 100644 --- a/L2J_Mobius_Classic/java/com/l2jmobius/gameserver/ai/L2CharacterAI.java +++ b/L2J_Mobius_Classic/java/com/l2jmobius/gameserver/ai/L2CharacterAI.java @@ -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; diff --git a/L2J_Mobius_Classic/java/com/l2jmobius/gameserver/instancemanager/BoatManager.java b/L2J_Mobius_Classic/java/com/l2jmobius/gameserver/instancemanager/BoatManager.java index a3a325eb43..24d5c6198c 100644 --- a/L2J_Mobius_Classic/java/com/l2jmobius/gameserver/instancemanager/BoatManager.java +++ b/L2J_Mobius_Classic/java/com/l2jmobius/gameserver/instancemanager/BoatManager.java @@ -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); } } } diff --git a/L2J_Mobius_Classic/java/com/l2jmobius/gameserver/model/L2Territory.java b/L2J_Mobius_Classic/java/com/l2jmobius/gameserver/model/L2Territory.java index f0a92adc20..5152d69c0d 100644 --- a/L2J_Mobius_Classic/java/com/l2jmobius/gameserver/model/L2Territory.java +++ b/L2J_Mobius_Classic/java/com/l2jmobius/gameserver/model/L2Territory.java @@ -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; diff --git a/L2J_Mobius_Classic/java/com/l2jmobius/gameserver/model/actor/L2Character.java b/L2J_Mobius_Classic/java/com/l2jmobius/gameserver/model/actor/L2Character.java index 9fe4844c6c..8ab8348d64 100644 --- a/L2J_Mobius_Classic/java/com/l2jmobius/gameserver/model/actor/L2Character.java +++ b/L2J_Mobius_Classic/java/com/l2jmobius/gameserver/model/actor/L2Character.java @@ -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) { diff --git a/L2J_Mobius_Classic/java/com/l2jmobius/gameserver/model/actor/L2Vehicle.java b/L2J_Mobius_Classic/java/com/l2jmobius/gameserver/model/actor/L2Vehicle.java index f9904262c1..b8190b538a 100644 --- a/L2J_Mobius_Classic/java/com/l2jmobius/gameserver/model/actor/L2Vehicle.java +++ b/L2J_Mobius_Classic/java/com/l2jmobius/gameserver/model/actor/L2Vehicle.java @@ -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())); diff --git a/L2J_Mobius_Classic/java/com/l2jmobius/gameserver/model/zone/form/ZoneCylinder.java b/L2J_Mobius_Classic/java/com/l2jmobius/gameserver/model/zone/form/ZoneCylinder.java index 681f9a69de..969dd7d029 100644 --- a/L2J_Mobius_Classic/java/com/l2jmobius/gameserver/model/zone/form/ZoneCylinder.java +++ b/L2J_Mobius_Classic/java/com/l2jmobius/gameserver/model/zone/form/ZoneCylinder.java @@ -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. diff --git a/L2J_Mobius_Ertheia/java/com/l2jmobius/gameserver/ai/L2CharacterAI.java b/L2J_Mobius_Ertheia/java/com/l2jmobius/gameserver/ai/L2CharacterAI.java index c5cab58d48..0d66c4a387 100644 --- a/L2J_Mobius_Ertheia/java/com/l2jmobius/gameserver/ai/L2CharacterAI.java +++ b/L2J_Mobius_Ertheia/java/com/l2jmobius/gameserver/ai/L2CharacterAI.java @@ -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; diff --git a/L2J_Mobius_Ertheia/java/com/l2jmobius/gameserver/instancemanager/BoatManager.java b/L2J_Mobius_Ertheia/java/com/l2jmobius/gameserver/instancemanager/BoatManager.java index a3a325eb43..24d5c6198c 100644 --- a/L2J_Mobius_Ertheia/java/com/l2jmobius/gameserver/instancemanager/BoatManager.java +++ b/L2J_Mobius_Ertheia/java/com/l2jmobius/gameserver/instancemanager/BoatManager.java @@ -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); } } } diff --git a/L2J_Mobius_Ertheia/java/com/l2jmobius/gameserver/model/L2Territory.java b/L2J_Mobius_Ertheia/java/com/l2jmobius/gameserver/model/L2Territory.java index f0a92adc20..5152d69c0d 100644 --- a/L2J_Mobius_Ertheia/java/com/l2jmobius/gameserver/model/L2Territory.java +++ b/L2J_Mobius_Ertheia/java/com/l2jmobius/gameserver/model/L2Territory.java @@ -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; diff --git a/L2J_Mobius_Ertheia/java/com/l2jmobius/gameserver/model/actor/L2Character.java b/L2J_Mobius_Ertheia/java/com/l2jmobius/gameserver/model/actor/L2Character.java index 9fe4844c6c..8ab8348d64 100644 --- a/L2J_Mobius_Ertheia/java/com/l2jmobius/gameserver/model/actor/L2Character.java +++ b/L2J_Mobius_Ertheia/java/com/l2jmobius/gameserver/model/actor/L2Character.java @@ -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) { diff --git a/L2J_Mobius_Ertheia/java/com/l2jmobius/gameserver/model/actor/L2Vehicle.java b/L2J_Mobius_Ertheia/java/com/l2jmobius/gameserver/model/actor/L2Vehicle.java index f9904262c1..b8190b538a 100644 --- a/L2J_Mobius_Ertheia/java/com/l2jmobius/gameserver/model/actor/L2Vehicle.java +++ b/L2J_Mobius_Ertheia/java/com/l2jmobius/gameserver/model/actor/L2Vehicle.java @@ -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())); diff --git a/L2J_Mobius_Ertheia/java/com/l2jmobius/gameserver/model/zone/form/ZoneCylinder.java b/L2J_Mobius_Ertheia/java/com/l2jmobius/gameserver/model/zone/form/ZoneCylinder.java index 681f9a69de..969dd7d029 100644 --- a/L2J_Mobius_Ertheia/java/com/l2jmobius/gameserver/model/zone/form/ZoneCylinder.java +++ b/L2J_Mobius_Ertheia/java/com/l2jmobius/gameserver/model/zone/form/ZoneCylinder.java @@ -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. diff --git a/L2J_Mobius_Helios/java/com/l2jmobius/gameserver/ai/L2CharacterAI.java b/L2J_Mobius_Helios/java/com/l2jmobius/gameserver/ai/L2CharacterAI.java index c5cab58d48..0d66c4a387 100644 --- a/L2J_Mobius_Helios/java/com/l2jmobius/gameserver/ai/L2CharacterAI.java +++ b/L2J_Mobius_Helios/java/com/l2jmobius/gameserver/ai/L2CharacterAI.java @@ -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; diff --git a/L2J_Mobius_Helios/java/com/l2jmobius/gameserver/instancemanager/BoatManager.java b/L2J_Mobius_Helios/java/com/l2jmobius/gameserver/instancemanager/BoatManager.java index a3a325eb43..24d5c6198c 100644 --- a/L2J_Mobius_Helios/java/com/l2jmobius/gameserver/instancemanager/BoatManager.java +++ b/L2J_Mobius_Helios/java/com/l2jmobius/gameserver/instancemanager/BoatManager.java @@ -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); } } } diff --git a/L2J_Mobius_Helios/java/com/l2jmobius/gameserver/model/L2Territory.java b/L2J_Mobius_Helios/java/com/l2jmobius/gameserver/model/L2Territory.java index f0a92adc20..5152d69c0d 100644 --- a/L2J_Mobius_Helios/java/com/l2jmobius/gameserver/model/L2Territory.java +++ b/L2J_Mobius_Helios/java/com/l2jmobius/gameserver/model/L2Territory.java @@ -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; diff --git a/L2J_Mobius_Helios/java/com/l2jmobius/gameserver/model/actor/L2Character.java b/L2J_Mobius_Helios/java/com/l2jmobius/gameserver/model/actor/L2Character.java index 9fe4844c6c..8ab8348d64 100644 --- a/L2J_Mobius_Helios/java/com/l2jmobius/gameserver/model/actor/L2Character.java +++ b/L2J_Mobius_Helios/java/com/l2jmobius/gameserver/model/actor/L2Character.java @@ -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) { diff --git a/L2J_Mobius_Helios/java/com/l2jmobius/gameserver/model/actor/L2Vehicle.java b/L2J_Mobius_Helios/java/com/l2jmobius/gameserver/model/actor/L2Vehicle.java index f9904262c1..b8190b538a 100644 --- a/L2J_Mobius_Helios/java/com/l2jmobius/gameserver/model/actor/L2Vehicle.java +++ b/L2J_Mobius_Helios/java/com/l2jmobius/gameserver/model/actor/L2Vehicle.java @@ -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())); diff --git a/L2J_Mobius_Helios/java/com/l2jmobius/gameserver/model/zone/form/ZoneCylinder.java b/L2J_Mobius_Helios/java/com/l2jmobius/gameserver/model/zone/form/ZoneCylinder.java index 681f9a69de..969dd7d029 100644 --- a/L2J_Mobius_Helios/java/com/l2jmobius/gameserver/model/zone/form/ZoneCylinder.java +++ b/L2J_Mobius_Helios/java/com/l2jmobius/gameserver/model/zone/form/ZoneCylinder.java @@ -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. diff --git a/L2J_Mobius_HighFive/java/com/l2jmobius/gameserver/ai/L2CharacterAI.java b/L2J_Mobius_HighFive/java/com/l2jmobius/gameserver/ai/L2CharacterAI.java index 74a7095a7d..3c0c7ef1e6 100644 --- a/L2J_Mobius_HighFive/java/com/l2jmobius/gameserver/ai/L2CharacterAI.java +++ b/L2J_Mobius_HighFive/java/com/l2jmobius/gameserver/ai/L2CharacterAI.java @@ -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; diff --git a/L2J_Mobius_HighFive/java/com/l2jmobius/gameserver/instancemanager/BoatManager.java b/L2J_Mobius_HighFive/java/com/l2jmobius/gameserver/instancemanager/BoatManager.java index bdc41df8f9..458824d1ef 100644 --- a/L2J_Mobius_HighFive/java/com/l2jmobius/gameserver/instancemanager/BoatManager.java +++ b/L2J_Mobius_HighFive/java/com/l2jmobius/gameserver/instancemanager/BoatManager.java @@ -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); } } } diff --git a/L2J_Mobius_HighFive/java/com/l2jmobius/gameserver/model/L2Territory.java b/L2J_Mobius_HighFive/java/com/l2jmobius/gameserver/model/L2Territory.java index 5241f2e848..70a4bc4c16 100644 --- a/L2J_Mobius_HighFive/java/com/l2jmobius/gameserver/model/L2Territory.java +++ b/L2J_Mobius_HighFive/java/com/l2jmobius/gameserver/model/L2Territory.java @@ -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; diff --git a/L2J_Mobius_HighFive/java/com/l2jmobius/gameserver/model/actor/L2Character.java b/L2J_Mobius_HighFive/java/com/l2jmobius/gameserver/model/actor/L2Character.java index 28c2db77a4..b566499caf 100644 --- a/L2J_Mobius_HighFive/java/com/l2jmobius/gameserver/model/actor/L2Character.java +++ b/L2J_Mobius_HighFive/java/com/l2jmobius/gameserver/model/actor/L2Character.java @@ -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) { diff --git a/L2J_Mobius_HighFive/java/com/l2jmobius/gameserver/model/actor/L2Vehicle.java b/L2J_Mobius_HighFive/java/com/l2jmobius/gameserver/model/actor/L2Vehicle.java index 71bc448497..6df34f1cd7 100644 --- a/L2J_Mobius_HighFive/java/com/l2jmobius/gameserver/model/actor/L2Vehicle.java +++ b/L2J_Mobius_HighFive/java/com/l2jmobius/gameserver/model/actor/L2Vehicle.java @@ -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())); diff --git a/L2J_Mobius_HighFive/java/com/l2jmobius/gameserver/model/zone/form/ZoneCylinder.java b/L2J_Mobius_HighFive/java/com/l2jmobius/gameserver/model/zone/form/ZoneCylinder.java index 2469472278..ec8300ace4 100644 --- a/L2J_Mobius_HighFive/java/com/l2jmobius/gameserver/model/zone/form/ZoneCylinder.java +++ b/L2J_Mobius_HighFive/java/com/l2jmobius/gameserver/model/zone/form/ZoneCylinder.java @@ -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. diff --git a/L2J_Mobius_Underground/java/com/l2jmobius/gameserver/ai/L2CharacterAI.java b/L2J_Mobius_Underground/java/com/l2jmobius/gameserver/ai/L2CharacterAI.java index c5cab58d48..0d66c4a387 100644 --- a/L2J_Mobius_Underground/java/com/l2jmobius/gameserver/ai/L2CharacterAI.java +++ b/L2J_Mobius_Underground/java/com/l2jmobius/gameserver/ai/L2CharacterAI.java @@ -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; diff --git a/L2J_Mobius_Underground/java/com/l2jmobius/gameserver/instancemanager/BoatManager.java b/L2J_Mobius_Underground/java/com/l2jmobius/gameserver/instancemanager/BoatManager.java index a3a325eb43..24d5c6198c 100644 --- a/L2J_Mobius_Underground/java/com/l2jmobius/gameserver/instancemanager/BoatManager.java +++ b/L2J_Mobius_Underground/java/com/l2jmobius/gameserver/instancemanager/BoatManager.java @@ -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); } } } diff --git a/L2J_Mobius_Underground/java/com/l2jmobius/gameserver/model/L2Territory.java b/L2J_Mobius_Underground/java/com/l2jmobius/gameserver/model/L2Territory.java index f0a92adc20..5152d69c0d 100644 --- a/L2J_Mobius_Underground/java/com/l2jmobius/gameserver/model/L2Territory.java +++ b/L2J_Mobius_Underground/java/com/l2jmobius/gameserver/model/L2Territory.java @@ -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; diff --git a/L2J_Mobius_Underground/java/com/l2jmobius/gameserver/model/actor/L2Character.java b/L2J_Mobius_Underground/java/com/l2jmobius/gameserver/model/actor/L2Character.java index 9fe4844c6c..8ab8348d64 100644 --- a/L2J_Mobius_Underground/java/com/l2jmobius/gameserver/model/actor/L2Character.java +++ b/L2J_Mobius_Underground/java/com/l2jmobius/gameserver/model/actor/L2Character.java @@ -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) { diff --git a/L2J_Mobius_Underground/java/com/l2jmobius/gameserver/model/actor/L2Vehicle.java b/L2J_Mobius_Underground/java/com/l2jmobius/gameserver/model/actor/L2Vehicle.java index f9904262c1..b8190b538a 100644 --- a/L2J_Mobius_Underground/java/com/l2jmobius/gameserver/model/actor/L2Vehicle.java +++ b/L2J_Mobius_Underground/java/com/l2jmobius/gameserver/model/actor/L2Vehicle.java @@ -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())); diff --git a/L2J_Mobius_Underground/java/com/l2jmobius/gameserver/model/zone/form/ZoneCylinder.java b/L2J_Mobius_Underground/java/com/l2jmobius/gameserver/model/zone/form/ZoneCylinder.java index 681f9a69de..969dd7d029 100644 --- a/L2J_Mobius_Underground/java/com/l2jmobius/gameserver/model/zone/form/ZoneCylinder.java +++ b/L2J_Mobius_Underground/java/com/l2jmobius/gameserver/model/zone/form/ZoneCylinder.java @@ -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.