cyphesis/tests/LocationTest.cpp

563 lines
18 KiB
C++
Raw Permalink Normal View History

2006-01-19 Al Riddoch <alriddoch@zepler.org> * aiclient/ClientAccount.cpp, aiclient/ClientAccount.h, aiclient/ClientConnection.cpp, aiclient/ClientConnection.h, aiclient/client.cpp, aiclient/client.h, client/BaseClient.cpp, client/BaseClient.h, client/CharacterClient.cpp, client/CharacterClient.h, client/ClientConnection.cpp, client/ClientConnection.h, client/CreatorClient.cpp, client/CreatorClient.h, client/ObserverClient.cpp, client/ObserverClient.h, client/Py_CreatorClient.cpp, client/Py_CreatorClient.h, client/client.cpp, client/define_world.cpp, client/define_world.h, common/Add.h, common/Affect.h, common/AtlasFileLoader.cpp, common/AtlasFileLoader.h, common/Attack.h, common/BaseEntity.cpp, common/BaseEntity.h, common/BaseWorld.cpp, common/BaseWorld.h, common/Burn.h, common/Chop.h, common/Connect.h, common/CustomOp.cpp, common/CustomOp.h, common/CustomOp_impl.h, common/Cut.h, common/Database.cpp, common/Database.h, common/Delve.h, common/Dig.h, common/Eat.h, common/FormattedXMLWriter.cpp, common/FormattedXMLWriter.h, common/Generic.h, common/Load.h, common/Monitor.h, common/Mow.h, common/Nourish.h, common/OOGThing.cpp, common/OOGThing.h, common/Property.cpp, common/Property.h, common/Property_impl.h, common/Save.h, common/Setup.h, common/Tick.h, common/Unseen.h, common/Update.h, common/Use.h, common/Wield.h, common/accountbase.cpp, common/accountbase.h, common/const.cpp, common/const.h, common/custom.cpp, common/debug.h, common/globals.cpp, common/globals.h, common/id.cpp, common/id.h, common/inheritance.cpp, common/inheritance.h, common/inheritance_impl.h, common/log.cpp, common/log.h, common/newid.cpp, common/nls.h, common/op_switch.h, common/operations.cpp, common/operations.h, common/random.h, common/refno.h, common/serialno.cpp, common/serialno.h, common/system.cpp, common/system.h, common/terrain_utils.cpp, common/terrain_utils.h, common/type_utils.h, common/types.h, common/utility.cpp, common/utility.h, modules/DateTime.cpp, modules/DateTime.h, modules/Location.cpp, modules/Location.h, modules/WorldTime.cpp, modules/WorldTime.h, physics/BBox.cpp, physics/BBox.h, physics/Collision.cpp, physics/Collision.h, physics/Quaternion.cpp, physics/Quaternion.h, physics/Vector3D.cpp, physics/Vector3D.h, physics/VectorPol.h, rulesets/Area.cpp, rulesets/Area.h, rulesets/AreaProperty.cpp, rulesets/AreaProperty.h, rulesets/ArithmeticScript.cpp, rulesets/ArithmeticScript.h, rulesets/BaseMind.cpp, rulesets/BaseMind.h, rulesets/CalendarProperty.cpp, rulesets/CalendarProperty.h, rulesets/Character.cpp, rulesets/Character.h, rulesets/Combat.cpp, rulesets/Combat.h, rulesets/Container.cpp, rulesets/Container.h, rulesets/Creator.cpp, rulesets/Creator.h, rulesets/Entity.cpp, rulesets/Entity.h, rulesets/EntityProperties.cpp, rulesets/Entity_getLocation.h, rulesets/Fell.cpp, rulesets/Fell.h, rulesets/Food.cpp, rulesets/Food.h, rulesets/Line.cpp, rulesets/Line.h, rulesets/LineProperty.cpp, rulesets/LineProperty.h, rulesets/MemEntity.cpp, rulesets/MemEntity.h, rulesets/MemMap.cpp, rulesets/MemMap.h, rulesets/MemMap_methods.h, rulesets/MindFactory.cpp, rulesets/MindFactory.h, rulesets/Missile.h, rulesets/Motion.cpp, rulesets/Motion.h, rulesets/Movement.cpp, rulesets/Movement.h, rulesets/Pedestrian.cpp, rulesets/Pedestrian.h, rulesets/Plant.cpp, rulesets/Plant.h, rulesets/Py_BBox.cpp, rulesets/Py_BBox.h, rulesets/Py_EntityWrapper.h, rulesets/Py_Location.cpp, rulesets/Py_Location.h, rulesets/Py_Map.cpp, rulesets/Py_Map.h, rulesets/Py_Mind.cpp, rulesets/Py_Mind.h, rulesets/Py_Object.cpp, rulesets/Py_Object.h, rulesets/Py_Operation.cpp, rulesets/Py_Operation.h, rulesets/Py_Oplist.cpp, rulesets/Py_Oplist.h, rulesets/Py_Optime.cpp, rulesets/Py_Optime.h, rulesets/Py_Point3D.cpp, rulesets/Py_Point3D.h, rulesets/Py_Property.cpp, rulesets/Py_Property.h, rulesets/Py_Quaternion.cpp, rulesets/Py_Quaternion.h, rulesets/Py_RootEntity.cpp, rulesets/Py_RootEntity.h, rulesets/Py_Statistics.cpp, rulesets/Py_Statistics.h, rulesets/Py_Task.cpp, rulesets/Py_Task.h, rulesets/Py_Thing.cpp, rulesets/Py_Thing.h, rulesets/Py_Vector3D.cpp, rulesets/Py_Vector3D.h, rulesets/Py_World.cpp, rulesets/Py_World.h, rulesets/Py_WorldTime.cpp, rulesets/Py_WorldTime.h, rulesets/PythonArithmeticScript.cpp, rulesets/PythonArithmeticScript.h, rulesets/PythonMindScript.cpp, rulesets/PythonMindScript.h, rulesets/PythonScript.cpp, rulesets/PythonScript.h, rulesets/PythonThingScript.cpp, rulesets/PythonThingScript.h, rulesets/PythonWrapper.cpp, rulesets/PythonWrapper.h, rulesets/Python_API.cpp, rulesets/Python_API.h, rulesets/Python_Script_Utils.h, rulesets/Script.cpp, rulesets/Script.h, rulesets/Stackable.cpp, rulesets/Stackable.h, rulesets/Statistics.cpp, rulesets/Statistics.h, rulesets/StatisticsProperty.cpp, rulesets/StatisticsProperty.h, rulesets/Structure.cpp, rulesets/Structure.h, rulesets/Task.cpp, rulesets/Task.h, rulesets/TaskScript.cpp, rulesets/TaskScript.h, rulesets/TerrainProperty.cpp, rulesets/TerrainProperty.h, rulesets/Thing.cpp, rulesets/Thing.h, rulesets/ThingFactory.cpp, rulesets/ThingFactory.h, rulesets/World.cpp, rulesets/World.h, rulesets/attributes.h, server/Account.cpp, server/Account.h, server/Admin.cpp, server/Admin.h, server/ArithmeticFactory.cpp, server/ArithmeticFactory.h, server/CommClient.cpp, server/CommClient.h, server/CommIdleSocket.cpp, server/CommIdleSocket.h, server/CommListener.cpp, server/CommListener.h, server/CommLocalClient.cpp, server/CommLocalClient.h, server/CommMDNSPublisher.cpp, server/CommMDNSPublisher.h, server/CommMaster.cpp, server/CommMaster.h, server/CommMetaClient.cpp, server/CommMetaClient.h, server/CommPSQLSocket.cpp, server/CommPSQLSocket.h, server/CommPeer.cpp, server/CommPeer.h, server/CommPeerListener.cpp, server/CommPeerListener.h, server/CommRemoteClient.cpp, server/CommRemoteClient.h, server/CommServer.cpp, server/CommServer.h, server/CommSlaveClient.cpp, server/CommSlaveClient.h, server/CommSlaveListener.cpp, server/CommSlaveListener.h, server/CommSocket.cpp, server/CommSocket.h, server/CommUnixListener.cpp, server/CommUnixListener.h, server/Connection.cpp, server/Connection.h, server/Connection_methods.h, server/EntityFactory.cpp, server/EntityFactory.h, server/ExternalMind.cpp, server/ExternalMind.h, server/Idle.cpp, server/Idle.h, server/Lobby.cpp, server/Lobby.h, server/Master.cpp, server/Master.h, server/Peer.cpp, server/Peer.h, server/Persistance.cpp, server/Persistance.h, server/PersistantThingFactory.cpp, server/PersistantThingFactory.h, server/PersistantThingFactory_impl.h, server/Persistor.cpp, server/Persistor.h, server/Persistor_impl.h, server/Player.cpp, server/Player.h, server/Restoration.cpp, server/Restoration.h, server/Restorer.cpp, server/Restorer.h, server/Restorer_impl.h, server/ScriptFactory.cpp, server/ScriptFactory.h, server/ServerRouting.cpp, server/ServerRouting.h, server/ServerRouting_methods.h, server/SlaveClientConnection.cpp, server/SlaveClientConnection.h, server/TaskFactory.cpp, server/TaskFactory.h, server/TrustedConnection.cpp, server/TrustedConnection.h, server/WorldRouter.cpp, server/WorldRouter.h, server/server.cpp, server/server.h, server/slave.cpp, tests/Areatest.cpp, tests/BaseEntitytest.cpp, tests/Charactertest.cpp, tests/Containertest.cpp, tests/Creatortest.cpp, tests/EntityExerciser.h, tests/EntityFactorytest.cpp, tests/Entitytest.cpp, tests/Foodtest.cpp, tests/IGEntityExerciser.h, tests/Linetest.cpp, tests/Locationtest.cpp, tests/OOGThingtest.cpp, tests/Planttest.cpp, tests/Propertytest.cpp, tests/Stackabletest.cpp, tests/Structuretest.cpp, tests/Tasktest.cpp, tests/TestWorld.h, tests/Thingtest.cpp, tests/WorldTimetest.cpp, tests/Worldtest.cpp, tests/allOperations.h, tests/collisiontest.cpp, tests/consttest.cpp, tests/distancetest.cpp, tests/emergencetest.cpp, tests/inheritancetest.cpp, tests/logtest.cpp, tests/randomtest.cpp, tests/systemtest.cpp, tests/transformtest.cpp, tests/type_utilstest.cpp, tests/utilitytest.cpp, tools/AdminClient.cpp, tools/AdminClient.h, tools/cyaddrules.cpp, tools/cycmd.cpp, tools/cyconfig.cpp, tools/cyconvertrules.cpp, tools/cyctrl.cpp, tools/cydbload.cpp, tools/cydumprules.cpp, tools/cyisoload.cpp, tools/cyloadrules.cpp, tools/cypasswd.cpp, tools/cywatchdog.cpp: Replace the copyright and license statements with new versions that include disclaimer of warranty, and permit distribution under later versions of the GPL.
2006-01-19 02:17:06 +00:00
// Cyphesis Online RPG Server and AI Engine
// Copyright (C) 2003-2005 Alistair Riddoch
2006-01-19 Al Riddoch <alriddoch@zepler.org> * aiclient/ClientAccount.cpp, aiclient/ClientAccount.h, aiclient/ClientConnection.cpp, aiclient/ClientConnection.h, aiclient/client.cpp, aiclient/client.h, client/BaseClient.cpp, client/BaseClient.h, client/CharacterClient.cpp, client/CharacterClient.h, client/ClientConnection.cpp, client/ClientConnection.h, client/CreatorClient.cpp, client/CreatorClient.h, client/ObserverClient.cpp, client/ObserverClient.h, client/Py_CreatorClient.cpp, client/Py_CreatorClient.h, client/client.cpp, client/define_world.cpp, client/define_world.h, common/Add.h, common/Affect.h, common/AtlasFileLoader.cpp, common/AtlasFileLoader.h, common/Attack.h, common/BaseEntity.cpp, common/BaseEntity.h, common/BaseWorld.cpp, common/BaseWorld.h, common/Burn.h, common/Chop.h, common/Connect.h, common/CustomOp.cpp, common/CustomOp.h, common/CustomOp_impl.h, common/Cut.h, common/Database.cpp, common/Database.h, common/Delve.h, common/Dig.h, common/Eat.h, common/FormattedXMLWriter.cpp, common/FormattedXMLWriter.h, common/Generic.h, common/Load.h, common/Monitor.h, common/Mow.h, common/Nourish.h, common/OOGThing.cpp, common/OOGThing.h, common/Property.cpp, common/Property.h, common/Property_impl.h, common/Save.h, common/Setup.h, common/Tick.h, common/Unseen.h, common/Update.h, common/Use.h, common/Wield.h, common/accountbase.cpp, common/accountbase.h, common/const.cpp, common/const.h, common/custom.cpp, common/debug.h, common/globals.cpp, common/globals.h, common/id.cpp, common/id.h, common/inheritance.cpp, common/inheritance.h, common/inheritance_impl.h, common/log.cpp, common/log.h, common/newid.cpp, common/nls.h, common/op_switch.h, common/operations.cpp, common/operations.h, common/random.h, common/refno.h, common/serialno.cpp, common/serialno.h, common/system.cpp, common/system.h, common/terrain_utils.cpp, common/terrain_utils.h, common/type_utils.h, common/types.h, common/utility.cpp, common/utility.h, modules/DateTime.cpp, modules/DateTime.h, modules/Location.cpp, modules/Location.h, modules/WorldTime.cpp, modules/WorldTime.h, physics/BBox.cpp, physics/BBox.h, physics/Collision.cpp, physics/Collision.h, physics/Quaternion.cpp, physics/Quaternion.h, physics/Vector3D.cpp, physics/Vector3D.h, physics/VectorPol.h, rulesets/Area.cpp, rulesets/Area.h, rulesets/AreaProperty.cpp, rulesets/AreaProperty.h, rulesets/ArithmeticScript.cpp, rulesets/ArithmeticScript.h, rulesets/BaseMind.cpp, rulesets/BaseMind.h, rulesets/CalendarProperty.cpp, rulesets/CalendarProperty.h, rulesets/Character.cpp, rulesets/Character.h, rulesets/Combat.cpp, rulesets/Combat.h, rulesets/Container.cpp, rulesets/Container.h, rulesets/Creator.cpp, rulesets/Creator.h, rulesets/Entity.cpp, rulesets/Entity.h, rulesets/EntityProperties.cpp, rulesets/Entity_getLocation.h, rulesets/Fell.cpp, rulesets/Fell.h, rulesets/Food.cpp, rulesets/Food.h, rulesets/Line.cpp, rulesets/Line.h, rulesets/LineProperty.cpp, rulesets/LineProperty.h, rulesets/MemEntity.cpp, rulesets/MemEntity.h, rulesets/MemMap.cpp, rulesets/MemMap.h, rulesets/MemMap_methods.h, rulesets/MindFactory.cpp, rulesets/MindFactory.h, rulesets/Missile.h, rulesets/Motion.cpp, rulesets/Motion.h, rulesets/Movement.cpp, rulesets/Movement.h, rulesets/Pedestrian.cpp, rulesets/Pedestrian.h, rulesets/Plant.cpp, rulesets/Plant.h, rulesets/Py_BBox.cpp, rulesets/Py_BBox.h, rulesets/Py_EntityWrapper.h, rulesets/Py_Location.cpp, rulesets/Py_Location.h, rulesets/Py_Map.cpp, rulesets/Py_Map.h, rulesets/Py_Mind.cpp, rulesets/Py_Mind.h, rulesets/Py_Object.cpp, rulesets/Py_Object.h, rulesets/Py_Operation.cpp, rulesets/Py_Operation.h, rulesets/Py_Oplist.cpp, rulesets/Py_Oplist.h, rulesets/Py_Optime.cpp, rulesets/Py_Optime.h, rulesets/Py_Point3D.cpp, rulesets/Py_Point3D.h, rulesets/Py_Property.cpp, rulesets/Py_Property.h, rulesets/Py_Quaternion.cpp, rulesets/Py_Quaternion.h, rulesets/Py_RootEntity.cpp, rulesets/Py_RootEntity.h, rulesets/Py_Statistics.cpp, rulesets/Py_Statistics.h, rulesets/Py_Task.cpp, rulesets/Py_Task.h, rulesets/Py_Thing.cpp, rulesets/Py_Thing.h, rulesets/Py_Vector3D.cpp, rulesets/Py_Vector3D.h, rulesets/Py_World.cpp, rulesets/Py_World.h, rulesets/Py_WorldTime.cpp, rulesets/Py_WorldTime.h, rulesets/PythonArithmeticScript.cpp, rulesets/PythonArithmeticScript.h, rulesets/PythonMindScript.cpp, rulesets/PythonMindScript.h, rulesets/PythonScript.cpp, rulesets/PythonScript.h, rulesets/PythonThingScript.cpp, rulesets/PythonThingScript.h, rulesets/PythonWrapper.cpp, rulesets/PythonWrapper.h, rulesets/Python_API.cpp, rulesets/Python_API.h, rulesets/Python_Script_Utils.h, rulesets/Script.cpp, rulesets/Script.h, rulesets/Stackable.cpp, rulesets/Stackable.h, rulesets/Statistics.cpp, rulesets/Statistics.h, rulesets/StatisticsProperty.cpp, rulesets/StatisticsProperty.h, rulesets/Structure.cpp, rulesets/Structure.h, rulesets/Task.cpp, rulesets/Task.h, rulesets/TaskScript.cpp, rulesets/TaskScript.h, rulesets/TerrainProperty.cpp, rulesets/TerrainProperty.h, rulesets/Thing.cpp, rulesets/Thing.h, rulesets/ThingFactory.cpp, rulesets/ThingFactory.h, rulesets/World.cpp, rulesets/World.h, rulesets/attributes.h, server/Account.cpp, server/Account.h, server/Admin.cpp, server/Admin.h, server/ArithmeticFactory.cpp, server/ArithmeticFactory.h, server/CommClient.cpp, server/CommClient.h, server/CommIdleSocket.cpp, server/CommIdleSocket.h, server/CommListener.cpp, server/CommListener.h, server/CommLocalClient.cpp, server/CommLocalClient.h, server/CommMDNSPublisher.cpp, server/CommMDNSPublisher.h, server/CommMaster.cpp, server/CommMaster.h, server/CommMetaClient.cpp, server/CommMetaClient.h, server/CommPSQLSocket.cpp, server/CommPSQLSocket.h, server/CommPeer.cpp, server/CommPeer.h, server/CommPeerListener.cpp, server/CommPeerListener.h, server/CommRemoteClient.cpp, server/CommRemoteClient.h, server/CommServer.cpp, server/CommServer.h, server/CommSlaveClient.cpp, server/CommSlaveClient.h, server/CommSlaveListener.cpp, server/CommSlaveListener.h, server/CommSocket.cpp, server/CommSocket.h, server/CommUnixListener.cpp, server/CommUnixListener.h, server/Connection.cpp, server/Connection.h, server/Connection_methods.h, server/EntityFactory.cpp, server/EntityFactory.h, server/ExternalMind.cpp, server/ExternalMind.h, server/Idle.cpp, server/Idle.h, server/Lobby.cpp, server/Lobby.h, server/Master.cpp, server/Master.h, server/Peer.cpp, server/Peer.h, server/Persistance.cpp, server/Persistance.h, server/PersistantThingFactory.cpp, server/PersistantThingFactory.h, server/PersistantThingFactory_impl.h, server/Persistor.cpp, server/Persistor.h, server/Persistor_impl.h, server/Player.cpp, server/Player.h, server/Restoration.cpp, server/Restoration.h, server/Restorer.cpp, server/Restorer.h, server/Restorer_impl.h, server/ScriptFactory.cpp, server/ScriptFactory.h, server/ServerRouting.cpp, server/ServerRouting.h, server/ServerRouting_methods.h, server/SlaveClientConnection.cpp, server/SlaveClientConnection.h, server/TaskFactory.cpp, server/TaskFactory.h, server/TrustedConnection.cpp, server/TrustedConnection.h, server/WorldRouter.cpp, server/WorldRouter.h, server/server.cpp, server/server.h, server/slave.cpp, tests/Areatest.cpp, tests/BaseEntitytest.cpp, tests/Charactertest.cpp, tests/Containertest.cpp, tests/Creatortest.cpp, tests/EntityExerciser.h, tests/EntityFactorytest.cpp, tests/Entitytest.cpp, tests/Foodtest.cpp, tests/IGEntityExerciser.h, tests/Linetest.cpp, tests/Locationtest.cpp, tests/OOGThingtest.cpp, tests/Planttest.cpp, tests/Propertytest.cpp, tests/Stackabletest.cpp, tests/Structuretest.cpp, tests/Tasktest.cpp, tests/TestWorld.h, tests/Thingtest.cpp, tests/WorldTimetest.cpp, tests/Worldtest.cpp, tests/allOperations.h, tests/collisiontest.cpp, tests/consttest.cpp, tests/distancetest.cpp, tests/emergencetest.cpp, tests/inheritancetest.cpp, tests/logtest.cpp, tests/randomtest.cpp, tests/systemtest.cpp, tests/transformtest.cpp, tests/type_utilstest.cpp, tests/utilitytest.cpp, tools/AdminClient.cpp, tools/AdminClient.h, tools/cyaddrules.cpp, tools/cycmd.cpp, tools/cyconfig.cpp, tools/cyconvertrules.cpp, tools/cyctrl.cpp, tools/cydbload.cpp, tools/cydumprules.cpp, tools/cyisoload.cpp, tools/cyloadrules.cpp, tools/cypasswd.cpp, tools/cywatchdog.cpp: Replace the copyright and license statements with new versions that include disclaimer of warranty, and permit distribution under later versions of the GPL.
2006-01-19 02:17:06 +00:00
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software Foundation,
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
2011-02-15 09:30:46 +00:00
#ifdef NDEBUG
#undef NDEBUG
#endif
#ifndef DEBUG
#define DEBUG
#endif
#include "modules/Location.h"
#include "rulesets/Entity.h"
2010-03-26 01:26:16 +00:00
#include "common/log.h"
#include "stubs/common/stubRouter.h"
#include "stubs/rulesets/stubEntity.h"
#include "stubs/rulesets/stubLocatedEntity.h"
#include <Atlas/Objects/Anonymous.h>
#include <Atlas/Objects/SmartPtr.h>
#include <Atlas/Objects/RootOperation.h>
#include <cassert>
void testDistanceFunctions()
{
{
Location * l = new Location;
delete l;
}
{
Entity tlve("0", 0), ent("1", 1);
ent.m_location.m_loc = &tlve;
ent.m_location.m_pos = Point3D(1, 1, 0);
ent.m_location.m_orientation = WFMath::Quaternion().identity();
Point3D relPos = relativePos(ent.m_location, ent.m_location);
std::cout << "RelPos to self: " << relPos << std::endl << std::flush;
relPos = relativePos(ent.m_location, tlve.m_location);
std::cout << "RelPos ent -> tlve: " << relPos
<< std::endl << std::flush;
relPos = relativePos(tlve.m_location, ent.m_location);
std::cout << "RelPos tlve -> ent: " << relPos
<< std::endl << std::flush;
ent.m_location.m_loc = 0;
}
// Coverage for broken entity hierarchy
{
Entity tlve("0", 0), ent1("1", 1), ent2("2", 2);
// BROKEN ent1.m_location.m_loc = &tlve;
ent1.m_location.m_pos = Point3D(-1, 1, 0);
ent1.m_location.m_orientation = WFMath::Quaternion().identity();
// BROKEN ent2.m_location.m_loc = &tlve;
ent2.m_location.m_pos = Point3D(1, 1, 0);
ent2.m_location.m_orientation = WFMath::Quaternion().identity();
Point3D relPos = relativePos(ent1.m_location, ent2.m_location);
assert(relPos.isValid());
std::cout << "RelPos ent1 -> ent2: " << relPos
<< std::endl << std::flush;
ent1.m_location.m_loc = 0;
ent2.m_location.m_loc = 0;
}
{
Entity tlve("0", 0), ent1("1", 1), ent2("2", 2);
ent1.m_location.m_loc = &tlve;
ent1.m_location.m_pos = Point3D(-1, 1, 0);
ent1.m_location.m_orientation = WFMath::Quaternion().identity();
// BROKEN ent2.m_location.m_loc = &tlve;
ent2.m_location.m_pos = Point3D(1, 1, 0);
ent2.m_location.m_orientation = WFMath::Quaternion().identity();
Point3D relPos = relativePos(ent1.m_location, ent2.m_location);
assert(relPos.isValid());
std::cout << "RelPos ent1 -> ent2: " << relPos
<< std::endl << std::flush;
ent1.m_location.m_loc = 0;
ent2.m_location.m_loc = 0;
}
{
Entity tlve("0", 0), ent1("1", 1), ent2("2", 2);
// BROKEN ent1.m_location.m_loc = &tlve;
ent1.m_location.m_pos = Point3D(-1, 1, 0);
ent1.m_location.m_orientation = WFMath::Quaternion().identity();
ent2.m_location.m_loc = &tlve;
ent2.m_location.m_pos = Point3D(1, 1, 0);
ent2.m_location.m_orientation = WFMath::Quaternion().identity();
Point3D relPos = relativePos(ent1.m_location, ent2.m_location);
assert(relPos.isValid());
std::cout << "RelPos ent1 -> ent2: " << relPos
<< std::endl << std::flush;
ent1.m_location.m_loc = 0;
ent2.m_location.m_loc = 0;
}
{
Entity tlve("0", 0), ent1("1", 1), ent2("2", 2);
ent1.m_location.m_loc = &tlve;
ent1.m_location.m_pos = Point3D(-1, 1, 0);
ent1.m_location.m_orientation = WFMath::Quaternion().identity();
ent2.m_location.m_loc = &tlve;
ent2.m_location.m_pos = Point3D(1, 1, 0);
ent2.m_location.m_orientation = WFMath::Quaternion().identity();
Point3D relPos = relativePos(ent1.m_location, ent2.m_location);
assert(relPos.isValid());
std::cout << "RelPos ent1 -> ent2: " << relPos
<< std::endl << std::flush;
ent1.m_location.m_loc = 0;
ent2.m_location.m_loc = 0;
}
{
Entity tlve("0", 0), ent1("1", 1), ent2("2", 2),
ent3("3", 3), ent4("4", 4);
ent1.m_location.m_loc = &tlve;
ent1.m_location.m_pos = Point3D(-1, 1, 0);
ent1.m_location.m_orientation = WFMath::Quaternion().identity();
ent2.m_location.m_loc = &tlve;
ent2.m_location.m_pos = Point3D(1, 1, 0);
ent2.m_location.m_orientation = WFMath::Quaternion().identity();
ent3.m_location.m_loc = &ent1;
ent3.m_location.m_pos = Point3D(-1, 1, 0);
ent3.m_location.m_orientation = WFMath::Quaternion().identity();
ent4.m_location.m_loc = &ent2;
ent4.m_location.m_pos = Point3D(1, 1, 0);
ent4.m_location.m_orientation = WFMath::Quaternion().identity();
Point3D relPos = relativePos(ent3.m_location, ent4.m_location);
std::cout << "RelPos ent3 -> ent4: " << relPos
<< std::endl << std::flush;
ent1.m_location.m_loc = 0;
ent2.m_location.m_loc = 0;
ent3.m_location.m_loc = 0;
ent4.m_location.m_loc = 0;
}
{
Entity tlve("0", 0), ent1("1", 1), ent2("2", 2), ent3("3", 3), ent4("4", 4);
ent1.m_location.m_loc = &tlve;
ent1.m_location.m_pos = Point3D(-1, 1, 0);
ent1.m_location.m_orientation = WFMath::Quaternion().identity();
ent2.m_location.m_loc = &tlve;
ent2.m_location.m_pos = Point3D(1, 1, 0);
ent2.m_location.m_orientation = WFMath::Quaternion().identity();
ent3.m_location.m_loc = &ent1;
ent3.m_location.m_pos = Point3D(-1, 1, 0);
ent3.m_location.m_orientation = WFMath::Quaternion(2, M_PI / 2.f);
ent4.m_location.m_loc = &ent2;
ent4.m_location.m_pos = Point3D(1, 1, 0);
ent4.m_location.m_orientation = WFMath::Quaternion().identity();
Point3D relPos = relativePos(ent3.m_location, ent4.m_location);
std::cout << "RelPos ent3 -> ent4: " << relPos
<< std::endl << std::flush;
ent1.m_location.m_loc = 0;
ent2.m_location.m_loc = 0;
ent3.m_location.m_loc = 0;
ent4.m_location.m_loc = 0;
}
// Coverage for no orientation
{
Entity tlve("0", 0), ent1("1", 1), ent2("2", 2),
ent3("3", 3), ent4("4", 4);
ent1.m_location.m_loc = &tlve;
ent1.m_location.m_pos = Point3D(-1, 1, 0);
ent2.m_location.m_loc = &tlve;
ent2.m_location.m_pos = Point3D(1, 1, 0);
ent3.m_location.m_loc = &ent1;
ent3.m_location.m_pos = Point3D(-1, 1, 0);
ent4.m_location.m_loc = &ent2;
ent4.m_location.m_pos = Point3D(1, 1, 0);
Point3D relPos = relativePos(ent3.m_location, ent4.m_location);
std::cout << "RelPos ent3 -> ent4: " << relPos
<< std::endl << std::flush;
ent1.m_location.m_loc = 0;
ent2.m_location.m_loc = 0;
ent3.m_location.m_loc = 0;
ent4.m_location.m_loc = 0;
}
{
Entity tlve("0", 0), ent1("1", 1), ent2("2", 2),
ent3("3", 3), ent4("4", 4);
ent1.m_location.m_loc = &tlve;
ent1.m_location.m_pos = Point3D(-1, 1, 0);
ent1.m_location.m_orientation = WFMath::Quaternion().identity();
ent2.m_location.m_loc = &tlve;
ent2.m_location.m_pos = Point3D(1, 1, 0);
ent2.m_location.m_orientation = WFMath::Quaternion(2, -M_PI / 2.f);
ent3.m_location.m_loc = &ent1;
ent3.m_location.m_pos = Point3D(-1, 1, 0);
ent3.m_location.m_orientation = WFMath::Quaternion(2, M_PI / 2.f);
ent4.m_location.m_loc = &ent2;
ent4.m_location.m_pos = Point3D(1, 1, 0);
ent4.m_location.m_orientation = WFMath::Quaternion().identity();
Point3D relPos = relativePos(ent3.m_location, ent4.m_location);
std::cout << "RelPos ent3 -> ent4: " << relPos
<< std::endl << std::flush;
ent1.m_location.m_loc = 0;
ent2.m_location.m_loc = 0;
ent3.m_location.m_loc = 0;
ent4.m_location.m_loc = 0;
}
{
Entity tlve("0", 0), ent1("1", 1), ent2("2", 2),
ent3("3", 3), ent4("4", 4);
ent1.m_location.m_loc = &tlve;
ent1.m_location.m_pos = Point3D(-1, 1, 0);
ent1.m_location.m_orientation = WFMath::Quaternion(2, M_PI / 2.f);
ent2.m_location.m_loc = &tlve;
ent2.m_location.m_pos = Point3D(1, 1, 0);
ent2.m_location.m_orientation = WFMath::Quaternion().identity();
ent3.m_location.m_loc = &ent1;
ent3.m_location.m_pos = Point3D(-1, 1, 0);
ent3.m_location.m_orientation = WFMath::Quaternion(2, M_PI / 2.f);
ent4.m_location.m_loc = &ent2;
ent4.m_location.m_pos = Point3D(1, 1, 0);
ent4.m_location.m_orientation = WFMath::Quaternion().identity();
Point3D relPos = relativePos(ent3.m_location, ent4.m_location);
Vector3D distance = distanceTo(ent3.m_location, ent4.m_location);
float d = squareDistance(ent3.m_location, ent4.m_location);
float hd = squareHorizontalDistance(ent3.m_location, ent4.m_location);
std::cout << "RelPos ent3 -> ent4: " << relPos
<< " Distance ent3 -> ent4: " << distance
<< " square distance ent3 -> ent4: " << d
<< " square horizontal distance ent3 -> ent4: " << hd
<< std::endl << std::flush;
ent1.m_location.m_loc = 0;
ent2.m_location.m_loc = 0;
ent3.m_location.m_loc = 0;
ent4.m_location.m_loc = 0;
}
{
Entity tlve("0", 0), ent1("1", 1), ent2("2", 2);
ent1.m_location.m_loc = &tlve;
ent1.m_location.m_pos = Point3D(1, 1, 0);
ent1.m_location.m_orientation = WFMath::Quaternion().identity();
ent2.m_location.m_loc = &ent1;
ent2.m_location.m_pos = Point3D(0, 0, 0);
ent2.m_location.m_orientation = WFMath::Quaternion().identity();
Vector3D distance = distanceTo(ent1.m_location, ent2.m_location);
std::cout << "Distance ent1 -> ent2: "
<< distance << "," << distance.isValid()
<< std::endl << std::flush;
assert(distance.isValid());
assert(distance == Vector3D(0,0,0));
ent1.m_location.m_loc = 0;
ent2.m_location.m_loc = 0;
}
}
int main()
{
{
Location testloc;
assert(testloc.m_loc == 0);
assert(!testloc.pos().isValid());
assert(!testloc.velocity().isValid());
assert(!testloc.orientation().isValid());
testloc.modifyBBox();
}
{
Location testloc(0);
assert(testloc.m_loc == 0);
assert(!testloc.pos().isValid());
assert(!testloc.velocity().isValid());
assert(!testloc.orientation().isValid());
}
{
Point3D testPos;
Location testloc(0, testPos);
assert(!testPos.isValid());
assert(testloc.m_loc == 0);
assert(!testloc.pos().isValid());
assert(!testloc.velocity().isValid());
assert(!testloc.orientation().isValid());
}
{
Point3D testPos(0,0,0);
Location testloc(0, testPos);
assert(testPos.isValid());
assert(testloc.m_loc == 0);
assert(testloc.pos().isValid());
assert(!testloc.velocity().isValid());
assert(!testloc.orientation().isValid());
}
{
Point3D testPos(0,0,0);
Vector3D testVel;
Location testloc(0, testPos, testVel);
assert(testPos.isValid());
assert(!testVel.isValid());
assert(testloc.m_loc == 0);
assert(testloc.pos().isValid());
assert(!testloc.velocity().isValid());
assert(!testloc.orientation().isValid());
}
{
Point3D testPos(0,0,0);
Vector3D testVel(0,0,0);
Location testloc(0, testPos, testVel);
assert(testPos.isValid());
assert(testVel.isValid());
assert(testloc.m_loc == 0);
assert(testloc.pos().isValid());
assert(testloc.velocity().isValid());
assert(!testloc.orientation().isValid());
Quaternion testOrientation(1, 0, 0, 0);
assert(testOrientation.isValid());
testloc.m_orientation = testOrientation;
assert(testloc.orientation().isValid());
}
{
Location testloc;
testloc.m_bBox = BBox(Point3D(0,0,0), Point3D(1,1,1));
assert(testloc.m_loc == 0);
assert(!testloc.pos().isValid());
assert(!testloc.velocity().isValid());
assert(!testloc.orientation().isValid());
assert(testloc.bBox().isValid());
testloc.setBBox(BBox(Point3D(1,1,1), Point3D(2,2,2)));
assert(testloc.squareRadius() == 12.f);
2012-03-15 21:26:05 +00:00
assert(WFMath::Equal(testloc.radius(), std::sqrt(12.f)));
// Check cached values have been changed
}
// Coverage for addToFoo()
{
Location testLoc;
Atlas::Message::MapType msg;
Atlas::Objects::Entity::Anonymous ent;
testLoc.addToMessage(msg);
testLoc.addToEntity(ent);
Entity le1("1", 1);
testLoc.m_loc = &le1;
testLoc.m_pos = Point3D(0,0,0);
testLoc.m_velocity = Vector3D(1,0,0);
testLoc.m_orientation = Quaternion(1, 0, 0, 0);
testLoc.m_bBox = BBox(Point3D(-1,-1,-1), Point3D(1,1,1));
testLoc.addToMessage(msg);
testLoc.addToEntity(ent);
(void)testLoc.asEntity();
{
Location readLocFromMessage;
readLocFromMessage.readFromMessage(msg);
assert(msg["pos"].isList());
assert(msg["pos"].asList().size() == 3);
// Make the list too long
msg["pos"].asList().push_back(1);
assert(msg["pos"].asList().size() == 4);
readLocFromMessage.readFromMessage(msg);
msg["pos"].asList().pop_back();
assert(msg["pos"].asList().size() == 3);
// Now it is back to the right size
// Make the first item in the list a string
msg["pos"].asList().front() = "string";
assert(msg["pos"].asList().front().isString());
readLocFromMessage.readFromMessage(msg);
msg["pos"].asList().front() = 0.f;
assert(msg["pos"].asList().front().isNum());
// Now it is back to the right type
// Make the list too long
msg["orientation"].asList().push_back(1);
assert(msg["orientation"].asList().size() == 5);
readLocFromMessage.readFromMessage(msg);
msg["orientation"].asList().pop_back();
assert(msg["orientation"].asList().size() == 4);
// Now it is back to the right size
// Make the first item in the list a string
msg["orientation"].asList().front() = "string";
assert(msg["orientation"].asList().front().isString());
readLocFromMessage.readFromMessage(msg);
msg["orientation"].asList().front() = 1.f;
assert(msg["orientation"].asList().front().isNum());
// Now it is back to the right type
// Make it not a list
msg["pos"] = "string";
assert(msg["pos"].isString());
msg["orientation"] = "string";
assert(msg["orientation"].isString());
readLocFromMessage.readFromMessage(msg);
}
{
Location readLocFromEntity;
readLocFromEntity.readFromEntity(ent);
assert(!ent->isDefaultPos());
assert(ent->getPos().size() == 3);
assert(!ent->isDefaultVelocity());
assert(ent->getVelocity().size() == 3);
readLocFromEntity.readFromEntity(ent);
Atlas::Message::Element orientation;
2009-05-07 02:02:24 +01:00
bool res = ent->copyAttr("orientation", orientation);
assert(res == 0);
// Make the list too long
orientation.asList().push_back(1);
assert(orientation.asList().size() == 5);
ent->setAttr("orientation", orientation);
readLocFromEntity.readFromEntity(ent);
orientation.asList().pop_back();
assert(orientation.asList().size() == 4);
// Now it is back to the right size
// Make the first item in the list a string
orientation.asList().front() = "string";
assert(orientation.asList().front().isString());
ent->setAttr("orientation", orientation);
readLocFromEntity.readFromEntity(ent);
orientation.asList().front() = 1.f;
assert(orientation.asList().front().isNum());
// Now it is back to the right type
// Make it not a list
orientation = "string";
assert(orientation.isString());
ent->setAttr("orientation", orientation);
readLocFromEntity.readFromEntity(ent);
}
}
testDistanceFunctions();
return 0;
}
// stubs
2010-03-26 01:26:16 +00:00
void log(LogLevel lvl, const std::string & msg)
{
}