Skip to content

ForceDirectedの配置不具合 #2

@agehama

Description

@agehama

以下のコードで0番目と2番目のノードが重なって配置される

#include <Siv3D.hpp> // OpenSiv3D v0.6

#include "GraphDrawing.hpp"

class LabelGraphVisualizer : public BasicGraphVisualizer
{
public:

	explicit LabelGraphVisualizer(const Font& font)
		: BasicGraphVisualizer{}
		, m_labelFont(font)
	{}

	virtual ~LabelGraphVisualizer() = default;

	virtual void drawNode(const Vec2& pos, GraphEdge::IndexType nodeIndex) const override
	{
		m_labelFont(nodeIndex).drawAt(pos);
	}

	Font m_labelFont;
};

void Main()
{
	const ConnectedGraph graph = { {
		{0, 1},
		{1, 2},
		{2, 0},
		{1, 3},
		{3, 4},
	} };

	const LayoutForceDirected layout{ graph, ForceDirectedConfig{.startImmediately = StartImmediately::Yes } };

	LabelGraphVisualizer visualizer{ Font{ 24 } };

	while (System::Update())
	{
		layout.draw(visualizer);
	}
}

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions