////////////////////////////////////////////////////////////////////////////////
// BoundingBox.h
// Copyright Bjoern Ganster
// Developed since 2021
////////////////////////////////////////////////////////////////////////////////

#pragma once

#include "BGBase.h"
#include "Point3D.h"

#include <algorithm>

struct BoundingBox: public VirtualClass {
public:
	// Default constructor
	BoundingBox();

	// Construct with single point
	BoundingBox(const Point3D& initVal);

	// Construct with known min/max
	BoundingBox(const Point3D& min, const Point3D& max);

	// Destructor
	~BoundingBox() OVERRIDE;

	// Update
	void update(const Point3D& newP);

	// Check if two bounding boxes intersect
	bool intersects(const BoundingBox& other) const;

	// Update bounding box to reflect movement
	// Should be set once after all points have been processed
	bool applyMovement(const Point3D& v);

	// Getters
	const Point3D& min() const;
	const Point3D& max() const;
	bool valid() const;

	// Compute distance to point (approx. from corners)
	double getDistance(const Point3D& p) const;

	// Get center of this BondingBox
	Point3D getCenter() const;

private:
	Point3D mMin, mMax;
	bool mValid;
};
