From 2bfb17da997c8f7eb67233a9b769d6e5e0e1073c Mon Sep 17 00:00:00 2001 From: SlyVTT Date: Wed, 24 May 2023 20:28:55 +0200 Subject: [PATCH] simplification of Vector2D class --- src/level.cpp | 8 ++++---- src/vector2D.cpp | 2 +- src/vector2D.h | 30 +++--------------------------- 3 files changed, 8 insertions(+), 32 deletions(-) diff --git a/src/level.cpp b/src/level.cpp index 33d5796..e156802 100644 --- a/src/level.cpp +++ b/src/level.cpp @@ -189,7 +189,7 @@ int Level::GetTileForeground( uint16_t x, uint16_t y ) // Compute the intersection Point between segments [AB] and [CD] // if there is an intersection, return true and store the result into Point R -bool CollisionSegSeg( Point2D A, Point2D B, Vector2D N, Point2D C, Point2D D, Point2D *R ) +bool CollisionSegSeg( Vector2D A, Vector2D B, Vector2D N, Vector2D C, Vector2D D, Vector2D *R ) { Vector2D I, J; @@ -231,7 +231,7 @@ bool CollisionSegSeg( Point2D A, Point2D B, Vector2D N, Point2D C, Point2D D, Po } -libnum::num32 ClosestPointOnSegment( Point2D A, Point2D B, Point2D P, Point2D *R ) +libnum::num32 ClosestPointOnSegment( Vector2D A, Vector2D B, Vector2D P, Vector2D *R ) { Vector2D AB; AB.x = B.x - A.x; @@ -269,7 +269,7 @@ libnum::num32 ClosestPointOnSegment( Point2D A, Point2D B, Point2D P, Point2D *R /*RETURN true if the player can go in the target position*/ bool Level::CanGo( void ) { - Point2D PlayerOrigin, PlayerTarget; + Vector2D PlayerOrigin, PlayerTarget; PlayerOrigin.x = MyPlayer.currx; PlayerOrigin.y = MyPlayer.curry; @@ -282,7 +282,7 @@ bool Level::CanGo( void ) for (unsigned int i=0; iA, MyLevelBorders[i]->B, MyLevelBorders[i]->N, PlayerOrigin, PlayerTarget, &I )) diff --git a/src/vector2D.cpp b/src/vector2D.cpp index 4aded69..a1d2b88 100644 --- a/src/vector2D.cpp +++ b/src/vector2D.cpp @@ -56,7 +56,7 @@ Vector2D Vector2D::Clone( void ) return NewVector; } -Vector2D Vector2D::MakeVector( Point2D A, Point2D B) +Vector2D Vector2D::MakeVector( Vector2D A, Vector2D B) { Vector2D NewVector( B.x-A.x, B.y-A.y ); return NewVector; diff --git a/src/vector2D.h b/src/vector2D.h index 5ba9af0..1be881e 100644 --- a/src/vector2D.h +++ b/src/vector2D.h @@ -7,30 +7,6 @@ libnum::num32 sqrt_num32(libnum::num32 v); -class Point2D -{ - public: - Point2D() {}; - ~Point2D() {}; - - libnum::num32 x; - libnum::num32 y; -}; - -class Circle -{ - public: - Circle() {}; - ~Circle() {}; - - libnum::num32 x; - libnum::num32 y; - libnum::num32 r; -}; - - - - class Vector2D { @@ -42,7 +18,7 @@ class Vector2D ~Vector2D(); Vector2D Clone( void ); - Vector2D MakeVector( Point2D A, Point2D B); + Vector2D MakeVector( Vector2D A, Vector2D B); void AddVectors( Vector2D a, Vector2D b ); void Add( Vector2D v, libnum::num32 scale ); @@ -117,8 +93,8 @@ class Border Border(); ~Border(); - Point2D A; - Point2D B; + Vector2D A; + Vector2D B; Vector2D N; uint16_t color; };