Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed MathLibraryInterface #32

Merged
merged 2 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 9 additions & 17 deletions include/Collisions/CheckCollisionVisitorInterface.h
Original file line number Diff line number Diff line change
@@ -1,25 +1,17 @@
#pragma once
#include "../pch.h"
#include "../Dynamics/TimerInterface.h"
#include "../Geometrics/Math/MathLibraryInterface.h"
#include "../pch.h"
#include <Collisions/CollisionTestResult/CollisionTestResult.h>
#include <Collisions/CollisionTestResult/CollisionTestResultBuilder.h>

namespace Barta{
class CheckCollisionVisitorInterface{
public:
CheckCollisionVisitorInterface() = default;
virtual ~CheckCollisionVisitorInterface() = default;
namespace Barta {
class CheckCollisionVisitorInterface {
public:
CheckCollisionVisitorInterface() = default;
virtual ~CheckCollisionVisitorInterface() = default;

virtual CollisionTestResult checkStaticCollision(
const MathLibraryInterface& mathLib,
CollisionTestResultBuilder& collisionTestResultBuilder
) const = 0;
virtual CollisionTestResult checkStaticCollision(CollisionTestResultBuilder& collisionTestResultBuilder) const = 0;

virtual CollisionTestResult checkDynamicCollision(
const MathLibraryInterface& mathLib,
const float delta_time,
CollisionTestResultBuilder& collisionTestResultBuilder
) const = 0;
};
virtual CollisionTestResult checkDynamicCollision(const float delta_time, CollisionTestResultBuilder& collisionTestResultBuilder) const = 0;
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,9 @@ class AABB_AABBCheckCollisionVisitor: public CheckCollisionVisitorInterface {
public:
AABB_AABBCheckCollisionVisitor(const AABB& aabb1, const AABB& aabb2, const DynamicsDifference& dynamicsDifference) noexcept;

CollisionTestResult checkStaticCollision(const MathLibraryInterface& mathLib, CollisionTestResultBuilder& collisionTestResultBuilder)
const override;
CollisionTestResult checkStaticCollision(CollisionTestResultBuilder& collisionTestResultBuilder) const override;

CollisionTestResult checkDynamicCollision(
const MathLibraryInterface& mathLib,
float delta_time,
CollisionTestResultBuilder& collisionTestResultBuilder
) const override;
CollisionTestResult checkDynamicCollision(float delta_time, CollisionTestResultBuilder& collisionTestResultBuilder) const override;

private:
const AABB aabb1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,9 @@ class CircleAABBCheckCollisionVisitor: public CheckCollisionVisitorInterface {
CircleAABBCheckCollisionVisitor(const Circle& circle, const AABB& aabb, const DynamicsDifference& dynamicsDifference);
virtual ~CircleAABBCheckCollisionVisitor();

CollisionTestResult checkStaticCollision(const MathLibraryInterface& mathLib, CollisionTestResultBuilder& collisionTestResultBuilder)
const override;
CollisionTestResult checkStaticCollision(CollisionTestResultBuilder& collisionTestResultBuilder) const override;

CollisionTestResult checkDynamicCollision(
const MathLibraryInterface& mathLib,
float delta_time,
CollisionTestResultBuilder& collisionTestResultBuilder
) const override;
CollisionTestResult checkDynamicCollision(float delta_time, CollisionTestResultBuilder& collisionTestResultBuilder) const override;

private:
const Circle circle;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,9 @@ class CircleCircleCheckCollisionVisitor: public CheckCollisionVisitorInterface {
CircleCircleCheckCollisionVisitor(const Circle& circle1, const Circle& circle2, const DynamicsDifference& dynamicsDifference);
virtual ~CircleCircleCheckCollisionVisitor();

CollisionTestResult checkStaticCollision(const MathLibraryInterface& mathLib, CollisionTestResultBuilder& collisionTestResultBuilder)
const override;
CollisionTestResult checkStaticCollision(CollisionTestResultBuilder& collisionTestResultBuilder) const override;

CollisionTestResult checkDynamicCollision(
const MathLibraryInterface& mathLib,
float delta_time,
CollisionTestResultBuilder& collisionTestResultBuilder
) const override;
CollisionTestResult checkDynamicCollision(float delta_time, CollisionTestResultBuilder& collisionTestResultBuilder) const override;

private:
const Circle circle1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,9 @@ class OBB_AABBCheckCollisionVisitor: public CheckCollisionVisitorInterface {
public:
OBB_AABBCheckCollisionVisitor(const OBB& obb, const AABB& aabb, const DynamicsDifference& dynamicsDifference) noexcept;

CollisionTestResult checkStaticCollision(const MathLibraryInterface& mathLib, CollisionTestResultBuilder& collisionTestResultBuilder)
const override;
CollisionTestResult checkStaticCollision(CollisionTestResultBuilder& collisionTestResultBuilder) const override;

CollisionTestResult checkDynamicCollision(
const MathLibraryInterface& mathLib,
float deltaTime,
CollisionTestResultBuilder& collisionTestResultBuilder
) const override;
CollisionTestResult checkDynamicCollision(float deltaTime, CollisionTestResultBuilder& collisionTestResultBuilder) const override;
Vector2f calculateCollisionPoint() const;

private:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
#pragma once
#include "../../Dynamics/TimerInterface.h"
#include "../../pch.h"
#include"../CollisionDetectionStrategyInterface.h"
#include"../../Dynamics/TimerInterface.h"
#include "../../Geometrics/Math/MathLibraryInterface.h"
#include "../CollisionDetectionStrategyInterface.h"

namespace Barta{
class DynamicCollisionDetectionStrategy : public CollisionDetectionStrategyInterface{
public:
DynamicCollisionDetectionStrategy(std::unique_ptr<MathLibraryInterface> mathLibrary, const TimerInterface& timer);
virtual ~DynamicCollisionDetectionStrategy() noexcept = default;
namespace Barta {
class DynamicCollisionDetectionStrategy: public CollisionDetectionStrategyInterface {
public:
DynamicCollisionDetectionStrategy(const TimerInterface& timer);
virtual ~DynamicCollisionDetectionStrategy() noexcept = default;

virtual CollisionTestResult acceptCheckCollisionVisitor( const CheckCollisionVisitorInterface& checkCollisionVisitor ) const override;
private:
const TimerInterface& timer;
virtual CollisionTestResult acceptCheckCollisionVisitor(const CheckCollisionVisitorInterface& checkCollisionVisitor) const override;

std::unique_ptr<MathLibraryInterface> mathLibrary;
};
private:
const TimerInterface& timer;
};
}

Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
#pragma once

#include <Collisions/CollisionTestResult/CollisionTestResult.h>
#include "../../pch.h"
#include"../CollisionDetectionStrategyInterface.h"
#include "../../Geometrics/Math/MathLibraryInterface.h"

namespace Barta{
class StaticCollisionDetectionStrategy : public CollisionDetectionStrategyInterface{

public:
StaticCollisionDetectionStrategy(std::unique_ptr<MathLibraryInterface>);
virtual ~StaticCollisionDetectionStrategy() noexcept = default;
#include "../CollisionDetectionStrategyInterface.h"
#include <Collisions/CollisionTestResult/CollisionTestResult.h>

virtual CollisionTestResult acceptCheckCollisionVisitor( const CheckCollisionVisitorInterface& checkCollisionVisitor ) const override;
namespace Barta {
class StaticCollisionDetectionStrategy: public CollisionDetectionStrategyInterface {
public:
StaticCollisionDetectionStrategy();
virtual ~StaticCollisionDetectionStrategy() noexcept = default;

private:
std::unique_ptr<MathLibraryInterface> mathLibrary;
};
virtual CollisionTestResult acceptCheckCollisionVisitor(const CheckCollisionVisitorInterface& checkCollisionVisitor) const override;
};
}

12 changes: 0 additions & 12 deletions include/Geometrics/Math/BartaMathLibrary.h

This file was deleted.

15 changes: 0 additions & 15 deletions include/Geometrics/Math/MathLibraryInterface.h

This file was deleted.

14 changes: 14 additions & 0 deletions include/Utilities/MathUtilities.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#pragma once
#include "../Geometrics/Math/EquationInterface.h"
#include "../Geometrics/Math/QuadraticEquation.h"
#include "../pch.h"

namespace Barta::Utils {
std::unique_ptr<EquationInterface> createQuadraticEquation(
float A,
float B,
float C
) {
return std::unique_ptr<EquationInterface>(new QuadraticEquation(A, B, C));
tkz789 marked this conversation as resolved.
Show resolved Hide resolved
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ Barta::AABB_AABBCheckCollisionVisitor::AABB_AABBCheckCollisionVisitor(
dynamicsDifference(dynamicsDifference) {}

Barta::CollisionTestResult Barta::AABB_AABBCheckCollisionVisitor::checkStaticCollision(
const MathLibraryInterface& mathLib,
CollisionTestResultBuilder& collisionTestResultBuilder
) const {
std::stringstream ss;
Expand All @@ -30,11 +29,10 @@ Barta::CollisionTestResult Barta::AABB_AABBCheckCollisionVisitor::checkStaticCol
}

Barta::CollisionTestResult Barta::AABB_AABBCheckCollisionVisitor::checkDynamicCollision(
const MathLibraryInterface& mathLib,
const float delta_time,
CollisionTestResultBuilder& collisionTestResultBuilder
) const {
auto staticCollisionResult = this->checkStaticCollision(mathLib, collisionTestResultBuilder);
auto staticCollisionResult = this->checkStaticCollision(collisionTestResultBuilder);
if (staticCollisionResult.collisionDetected) {
return staticCollisionResult;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ Barta::Vector2f Barta::CircleAABBCheckCollisionVisitor::calculateCollisionPoint(
}

Barta::CollisionTestResult Barta::CircleAABBCheckCollisionVisitor::checkStaticCollision(
const MathLibraryInterface& mathLib,
CollisionTestResultBuilder& collisionTestResultBuilder
) const {
std::stringstream ss;
Expand Down Expand Up @@ -73,11 +72,10 @@ Barta::CollisionTestResult Barta::CircleAABBCheckCollisionVisitor::checkStaticCo
#pragma GCC diagnostic pop

Barta::CollisionTestResult Barta::CircleAABBCheckCollisionVisitor::checkDynamicCollision(
const MathLibraryInterface& mathLib,
const float delta_time,
CollisionTestResultBuilder& collisionTestResultBuilder
) const {
auto staticResult = this->checkStaticCollision(mathLib, collisionTestResultBuilder);
auto staticResult = this->checkStaticCollision(collisionTestResultBuilder);
if (staticResult.collisionDetected) {
return staticResult;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <Collisions/CheckCollisionVisitors/CircleCircleCheckCollisionVisitor.h>
#include "pch.h"
#include <Utilities/MathUtilities.h>

Barta::CircleCircleCheckCollisionVisitor::CircleCircleCheckCollisionVisitor(
const Circle& circle1,
Expand All @@ -16,7 +17,6 @@ Barta::CircleCircleCheckCollisionVisitor::~CircleCircleCheckCollisionVisitor() {
#pragma GCC diagnostic ignored "-Wunused-parameter"

Barta::CollisionTestResult Barta::CircleCircleCheckCollisionVisitor::checkStaticCollision(
const MathLibraryInterface& mathLib,
CollisionTestResultBuilder& collisionTestResultBuilder
) const {
std::stringstream ss;
Expand All @@ -38,11 +38,10 @@ Barta::CollisionTestResult Barta::CircleCircleCheckCollisionVisitor::checkStatic
#pragma GCC diagnostic pop

Barta::CollisionTestResult Barta::CircleCircleCheckCollisionVisitor::checkDynamicCollision(
const MathLibraryInterface& mathLib,
const float delta_time,
CollisionTestResultBuilder& collisionTestResultBuilder
) const {
auto staticResult = this->checkStaticCollision(mathLib, collisionTestResultBuilder);
auto staticResult = this->checkStaticCollision(collisionTestResultBuilder);
if (staticResult.collisionDetected) {
return staticResult;
}
Expand All @@ -52,7 +51,7 @@ Barta::CollisionTestResult Barta::CircleCircleCheckCollisionVisitor::checkDynami
auto v = dynamicsDifference.velocity + 0.5f * dynamicsDifference.acceleration * delta_time;
auto r = circle1.getRadius() + circle2.getRadius();

auto eq = mathLib.createQuadraticEquation(v * v, v * s * 2.f, s * s - r * r);
auto eq = Barta::Utils::createQuadraticEquation(v * v, v * s * 2.f, s * s - r * r);
tkz789 marked this conversation as resolved.
Show resolved Hide resolved
eq->solve();

if (eq->getState() != EquationInterface::State::FINITE_NO_SOLTIONS) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ bool Barta::OBB_AABBCheckCollisionVisitor::checkStaticOneWay(
}

Barta::CollisionTestResult Barta::OBB_AABBCheckCollisionVisitor::checkStaticCollision(
const MathLibraryInterface& mathLib,
CollisionTestResultBuilder& collisionTestResultBuilder
) const {
std::stringstream ss;
Expand All @@ -80,7 +79,6 @@ Barta::CollisionTestResult Barta::OBB_AABBCheckCollisionVisitor::checkStaticColl
}

Barta::CollisionTestResult Barta::OBB_AABBCheckCollisionVisitor::checkDynamicCollision(
const MathLibraryInterface& mathLib,
float deltaTime,
CollisionTestResultBuilder& collisionTestResultBuilder
) const {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
#include "pch.h"
#include <Collisions/CollisionDetectionStrategies/DynamicCollisionDetectionStrategy.h>
#include "pch.h"

Barta::DynamicCollisionDetectionStrategy::DynamicCollisionDetectionStrategy(
std::unique_ptr<MathLibraryInterface> mathLibrary,
const TimerInterface& timer
) :
timer( timer ),
mathLibrary(std::move(mathLibrary))
{}
):
timer(timer) {}

Barta::CollisionTestResult Barta::DynamicCollisionDetectionStrategy::acceptCheckCollisionVisitor( const CheckCollisionVisitorInterface& checkCollisionVisitor ) const{
Barta::CollisionTestResult Barta::DynamicCollisionDetectionStrategy::acceptCheckCollisionVisitor(
const CheckCollisionVisitorInterface& checkCollisionVisitor
) const {
auto builder = CollisionTestResultBuilder();

return checkCollisionVisitor.checkDynamicCollision(*this->mathLibrary, this->timer.getCurrentDeltaTime(), builder);
return checkCollisionVisitor.checkDynamicCollision(this->timer.getCurrentDeltaTime(), builder);
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#include "pch.h"
#include <Collisions/CollisionDetectionStrategies/StaticCollisionDetectionStrategy.h>
#include "pch.h"
#include <Collisions/CollisionTestResult/CollisionTestResultBuilder.h>

Barta::StaticCollisionDetectionStrategy::StaticCollisionDetectionStrategy( std::unique_ptr<MathLibraryInterface> mathLibrary ) :
mathLibrary(std::move(mathLibrary))
{}
Barta::StaticCollisionDetectionStrategy::StaticCollisionDetectionStrategy() {}

Barta::CollisionTestResult Barta::StaticCollisionDetectionStrategy::acceptCheckCollisionVisitor( const CheckCollisionVisitorInterface& checkCollisionVisitor ) const{
Barta::CollisionTestResult Barta::StaticCollisionDetectionStrategy::acceptCheckCollisionVisitor(
const CheckCollisionVisitorInterface& checkCollisionVisitor
) const {
auto builder = CollisionTestResultBuilder();

return checkCollisionVisitor.checkStaticCollision(*this->mathLibrary, builder);
return checkCollisionVisitor.checkStaticCollision(builder);
}
6 changes: 0 additions & 6 deletions lib/Geometrics/Math/BartaMathLibrary.cpp

This file was deleted.

7 changes: 3 additions & 4 deletions lib/Geometrics/Math/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
target_sources(${LIBRARY_NAME} PUBLIC
BartaMathLibrary.cpp
QuadraticEquation.cpp
)
target_sources(
${LIBRARY_NAME} PUBLIC QuadraticEquation.cpp
tkz789 marked this conversation as resolved.
Show resolved Hide resolved
)
Loading