#pragma once #include #include #include #include namespace nodesoup { /** Simple adjaceny list graph structure */ using vertex_id_t = std::size_t; using adj_list_t = std::vector>; /** Algebra types */ struct Vector2D; struct Point2D { double x; double y; explicit operator Vector2D() const; Point2D& operator+=(const Vector2D& vector); Point2D& operator-=(const Vector2D& vector); std::pair toPair() { return std::make_pair((int)x, (int)y); } }; struct Vector2D { double dx; double dy; double norm() const { return sqrt(dx * dx + dy * dy); } explicit operator Point2D() const; Vector2D& operator+=(const Vector2D& other); Vector2D& operator-=(const Vector2D& other); Vector2D& operator*=(double scalar); Vector2D& operator/=(double scalar); Vector2D& operator*(const Vector2D& other); }; /** Main library functions */ using iter_callback_t = std::function&, int)>; /** Applies the Freuchterman Reingold algorithm to layout graph @p in a frame of dimensions @p width and @p height, in @p iter-count iterations */ std::vector fruchterman_reingold( const adj_list_t& g, unsigned int width, unsigned int height, unsigned int iters_count = 300, double k = 15.0, iter_callback_t iter_cb = nullptr); std::vector kamada_kawai( const adj_list_t& g, unsigned int width, unsigned int height, double k = 300.0, double energy_threshold = 1e-2); /** Assigns diameters to vertices based on their degree */ std::vector size_radiuses(const adj_list_t& g, double min_radius = 4.0, double k = 300.0); }