// Create a new collision shape in the world.
/// First, this methods checks that the new collision shape does not exist yet in the
/// world. If it already exists, we do not allocate memory for a new one but instead
/// we reuse the existing one. The goal is to only allocate memory for a single
/// collision shape if this one is used for several bodies in the world. To allocate
/// memory for a new collision shape, we use the memory allocator.
CollisionShape* CollisionWorld::createCollisionShape(const CollisionShape& collisionShape) {

    // Check if there is already a similar collision shape in the world
    std::list<CollisionShape*>::iterator it;
    for (it = mCollisionShapes.begin(); it != mCollisionShapes.end(); ++it) {

        if (collisionShape == (*(*it))) {

            // Increment the number of similar created shapes
            (*it)->incrementNbSimilarCreatedShapes();

            // A similar collision shape already exists in the world, so we do not
            // create a new one but we simply return a pointer to the existing one
            return (*it);
        }
    }

    // A similar collision shape does not already exist in the world, so we create a
    // new one and add it to the world
    void* allocatedMemory = mMemoryAllocator.allocate(collisionShape.getSizeInBytes());
    CollisionShape* newCollisionShape = collisionShape.clone(allocatedMemory);
    mCollisionShapes.push_back(newCollisionShape);

    newCollisionShape->incrementNbSimilarCreatedShapes();

    // Return a pointer to the new collision shape
    return newCollisionShape;
}