2024-05-02 00:32:58 -04:00
|
|
|
#pragma once
|
|
|
|
/*
|
|
|
|
* Copyright (C) 2024 Brett Terpstra
|
|
|
|
*
|
|
|
|
* 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 3 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, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef GRAPHS_GRAPH_BASE_H
|
|
|
|
#define GRAPHS_GRAPH_BASE_H
|
|
|
|
|
|
|
|
#include <blt/gfx/renderer/batch_2d_renderer.h>
|
|
|
|
#include <blt/std/types.h>
|
|
|
|
#include <blt/std/assert.h>
|
2024-07-26 22:08:00 -04:00
|
|
|
#include <config.h>
|
2024-05-14 21:58:05 -04:00
|
|
|
|
2024-07-28 22:07:19 -04:00
|
|
|
inline blt::size_t last_node = 0;
|
|
|
|
|
|
|
|
inline std::string get_name()
|
|
|
|
{
|
|
|
|
return "unnamed" + std::to_string(last_node++);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct node_t
|
2024-05-02 00:32:58 -04:00
|
|
|
{
|
2024-07-26 22:08:00 -04:00
|
|
|
float repulsiveness = 24.0f;
|
2024-07-28 22:07:19 -04:00
|
|
|
std::string name;
|
2024-07-28 20:02:35 -04:00
|
|
|
std::string description;
|
2024-07-28 14:01:19 -04:00
|
|
|
std::string texture = conf::DEFAULT_IMAGE;
|
2024-07-27 20:53:47 -04:00
|
|
|
|
2024-07-26 22:08:00 -04:00
|
|
|
blt::gfx::point2d_t point;
|
|
|
|
blt::vec2 velocity;
|
2024-07-30 21:35:59 -04:00
|
|
|
float outline_scale = conf::OUTLINE_SCALE;
|
2024-07-26 22:08:00 -04:00
|
|
|
blt::color4 outline_color = conf::POINT_OUTLINE_COLOR;
|
|
|
|
|
2024-07-28 22:07:19 -04:00
|
|
|
explicit node_t(const blt::gfx::point2d_t& point): name(get_name()), point(point)
|
2024-07-26 22:08:00 -04:00
|
|
|
{}
|
|
|
|
|
2024-07-28 22:07:19 -04:00
|
|
|
explicit node_t(const blt::gfx::point2d_t& point, std::string name): name(std::move(name)), point(point)
|
|
|
|
{
|
|
|
|
BLT_ASSERT(!this->name.empty() && "Name should not be empty!");
|
|
|
|
}
|
|
|
|
|
2024-07-26 22:08:00 -04:00
|
|
|
blt::vec2& getVelocityRef()
|
|
|
|
{
|
|
|
|
return velocity;
|
|
|
|
}
|
|
|
|
|
|
|
|
blt::vec2& getPositionRef()
|
|
|
|
{
|
|
|
|
return point.pos;
|
|
|
|
}
|
|
|
|
|
|
|
|
[[nodiscard]] const blt::vec2& getPosition() const
|
|
|
|
{
|
|
|
|
return point.pos;
|
|
|
|
}
|
|
|
|
|
|
|
|
[[nodiscard]] auto& getRenderObj() const
|
|
|
|
{
|
|
|
|
return point;
|
|
|
|
}
|
2024-05-02 00:32:58 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2024-07-28 22:07:19 -04:00
|
|
|
struct edge_t
|
2024-05-02 00:32:58 -04:00
|
|
|
{
|
2024-07-30 02:38:47 -04:00
|
|
|
// fuck you too :3
|
|
|
|
friend selector_t;
|
2024-07-26 22:08:00 -04:00
|
|
|
float ideal_spring_length = conf::DEFAULT_SPRING_LENGTH;
|
2024-07-28 14:01:19 -04:00
|
|
|
float thickness = conf::DEFAULT_THICKNESS;
|
2024-07-26 22:08:00 -04:00
|
|
|
blt::color4 color = conf::EDGE_COLOR;
|
2024-07-28 20:02:35 -04:00
|
|
|
std::string description;
|
2024-07-26 22:08:00 -04:00
|
|
|
|
2024-07-28 22:07:19 -04:00
|
|
|
edge_t(blt::u64 i1, blt::u64 i2): i1(i1), i2(i2)
|
2024-05-02 00:32:58 -04:00
|
|
|
{
|
|
|
|
BLT_ASSERT(i1 != i2 && "Indices cannot be equal!");
|
|
|
|
}
|
|
|
|
|
2024-07-28 22:07:19 -04:00
|
|
|
inline friend bool operator==(edge_t e1, edge_t e2)
|
2024-05-02 00:32:58 -04:00
|
|
|
{
|
|
|
|
return (e1.i1 == e2.i1 || e1.i1 == e2.i2) && (e1.i2 == e2.i1 || e1.i2 == e2.i2);
|
|
|
|
}
|
|
|
|
|
|
|
|
[[nodiscard]] size_t getFirst() const
|
|
|
|
{
|
|
|
|
return i1;
|
|
|
|
}
|
|
|
|
|
|
|
|
[[nodiscard]] size_t getSecond() const
|
|
|
|
{
|
|
|
|
return i2;
|
|
|
|
}
|
2024-07-26 22:08:00 -04:00
|
|
|
|
|
|
|
private:
|
|
|
|
// we are trying to maintain this as an invariant.
|
|
|
|
blt::u64 i1, i2;
|
2024-05-02 00:32:58 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
struct edge_hash
|
|
|
|
{
|
2024-07-28 22:07:19 -04:00
|
|
|
blt::u64 operator()(const edge_t& e) const
|
2024-05-02 00:32:58 -04:00
|
|
|
{
|
|
|
|
return e.getFirst() * e.getSecond();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2024-07-28 14:01:19 -04:00
|
|
|
struct edge_eq
|
|
|
|
{
|
2024-07-28 22:07:19 -04:00
|
|
|
bool operator()(const edge_t& e1, const edge_t& e2) const
|
2024-07-28 14:01:19 -04:00
|
|
|
{
|
|
|
|
return e1 == e2;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2024-05-02 00:32:58 -04:00
|
|
|
#endif //GRAPHS_GRAPH_BASE_H
|