Commit cc1ed4d1 authored by guillaume's avatar guillaume

colored edges

parent 200074e4
...@@ -86,6 +86,7 @@ void Panel_drawNode(Panel * self, Node * n) ...@@ -86,6 +86,7 @@ void Panel_drawNode(Panel * self, Node * n)
Vector2 screenPosition= Panel_pixelFromPosition(self, &(n->position) ); Vector2 screenPosition= Panel_pixelFromPosition(self, &(n->position) );
DrawCircleV(screenPosition, 24, n->color); DrawCircleV(screenPosition, 24, n->color);
DrawCircleV(screenPosition, 20, RAYWHITE); DrawCircleV(screenPosition, 20, RAYWHITE);
DrawText(n->name, (int)(screenPosition.x), (int)(screenPosition.y), 20, n->color);
} }
void Panel_drawEdge(Panel * self, Edge * e) void Panel_drawEdge(Panel * self, Edge * e)
...@@ -101,7 +102,7 @@ void Panel_drawEdge(Panel * self, Edge * e) ...@@ -101,7 +102,7 @@ void Panel_drawEdge(Panel * self, Edge * e)
Vector2 source1= (Vector2){source.x-ortho.x, source.y-ortho.y}; Vector2 source1= (Vector2){source.x-ortho.x, source.y-ortho.y};
Vector2 source2= (Vector2){source.x+ortho.x, source.y+ortho.y}; Vector2 source2= (Vector2){source.x+ortho.x, source.y+ortho.y};
DrawTriangle(source1, source2, target, BLUE); DrawTriangle(source1, source2, target, e->color);
} }
Vector2 Panel_pixelFromPosition(Panel * self, Vector2 * p) Vector2 Panel_pixelFromPosition(Panel * self, Vector2 * p)
......
...@@ -3,19 +3,26 @@ ...@@ -3,19 +3,26 @@
#include <stdlib.h> #include <stdlib.h>
#include <assert.h> #include <assert.h>
#include <math.h> #include <math.h>
#include <string.h>
//-----------------------------------// //-----------------------------------//
//-- Node --// //-- Node --//
//-----------------------------------// //-----------------------------------//
// Constructor / Destructor // Constructor / Destructor
void Node_construct(Node * self)
{
Node_set( self, (Vector2){0.f, 0.f}, GRAY );
self->card= 0;
self->edges= Edge_newArray( 0 );
self->name= malloc( sizeof(char)*32 );
strcpy( self->name, "Node" );
}
Node * Node_new() Node * Node_new()
{ {
Node * p= malloc( sizeof(Node) ); Node * p= malloc( sizeof(Node) );
Node_set( p, (Vector2){0.f, 0.f}, GRAY ); Node_construct(p);
p->card= 0;
p->edges= Edge_newArray( 0 );
return p; return p;
} }
...@@ -25,9 +32,7 @@ Node * Node_newArray(int size) ...@@ -25,9 +32,7 @@ Node * Node_newArray(int size)
Node * p= malloc( sizeof(Node)*size ); Node * p= malloc( sizeof(Node)*size );
for(int i=0 ; i < size ; ++i ) for(int i=0 ; i < size ; ++i )
{ {
Node_set( p, (Vector2){0.f, 0.f}, GRAY ); Node_construct( &(p[i]) );
p[i].edges= Edge_newArray( 0 );
p[i].card= 0;
} }
return p; return p;
} }
...@@ -89,6 +94,7 @@ int Node_connect( Node * self, Node * target ) ...@@ -89,6 +94,7 @@ int Node_connect( Node * self, Node * target )
Node_resize( self, i+1 ); Node_resize( self, i+1 );
self->edges[i]._source= self; self->edges[i]._source= self;
self->edges[i]._target= target; self->edges[i]._target= target;
self->edges[i].color= self->color;
self->edges[i]._twin= NULL; self->edges[i]._twin= NULL;
return i; return i;
} }
...@@ -110,12 +116,18 @@ int Node_biconnect( Node * node1, Node * node2 ) ...@@ -110,12 +116,18 @@ int Node_biconnect( Node * node1, Node * node2 )
//-----------------------------------// //-----------------------------------//
// Constructor / Destructor // Constructor / Destructor
void Edge_construct( Edge * self, Node * source, Node * target )
{
self->_source= source;
self->_target= target;
self->_twin= NULL;
self->color= GRAY;
}
Edge * Edge_new( Node * source, Node * target ) Edge * Edge_new( Node * source, Node * target )
{ {
Edge * p = malloc( sizeof(Edge) ); Edge * p = malloc( sizeof(Edge) );
p->_source= source; Edge_construct( p, source, target );
p->_target= target;
p->_twin= NULL;
return p; return p;
} }
...@@ -137,9 +149,7 @@ Edge * Edge_newArray(int size) ...@@ -137,9 +149,7 @@ Edge * Edge_newArray(int size)
Edge * p = malloc( sizeof(Edge)*size ); Edge * p = malloc( sizeof(Edge)*size );
for( int i = 0 ; i < size ; ++i ) for( int i = 0 ; i < size ; ++i )
{ {
p[i]._source= NULL; Edge_construct( &(p[i]), NULL, NULL );
p[i]._target= NULL;
p[i]._twin= NULL;
} }
return p; return p;
} }
......
...@@ -14,9 +14,12 @@ struct Str_Node { ...@@ -14,9 +14,12 @@ struct Str_Node {
Vector2 position; Vector2 position;
//! color (r, g, b, a) of the node //! color (r, g, b, a) of the node
Color color; Color color;
struct Str_Edge * edges;
//! cardinality of the node (i.e. number of edges) //! cardinality of the node (i.e. number of edges)
int card; int card;
struct Str_Edge * edges; // Content:
//! name of the node
char* name;
}; };
/** /**
...@@ -24,8 +27,14 @@ struct Str_Node { ...@@ -24,8 +27,14 @@ struct Str_Node {
*/ */
typedef struct Str_Node Node; typedef struct Str_Node Node;
// Constructor / Destructor // Constructor / Destructor
/**
* @brief Construc all the element of an empty Node.
* @param self an empty Node ot yet constructed.
* @return The pointer to the new NetWorld.
*/
void Node_construct(Node * self);
/** /**
* @brief Allocate the memory to store a Node * @brief Allocate the memory to store a Node
* @return The pointer to the new NetWorld. * @return The pointer to the new NetWorld.
...@@ -126,6 +135,8 @@ struct Str_Edge { ...@@ -126,6 +135,8 @@ struct Str_Edge {
Node * _target; Node * _target;
//! pointer to the twin edge in case of bidirectional edge. //! pointer to the twin edge in case of bidirectional edge.
struct Str_Edge * _twin; struct Str_Edge * _twin;
//! color (r, g, b, a) of the node
Color color;
}; };
/** /**
...@@ -134,6 +145,15 @@ struct Str_Edge { ...@@ -134,6 +145,15 @@ struct Str_Edge {
typedef struct Str_Edge Edge; typedef struct Str_Edge Edge;
// Constructor / Destructor // Constructor / Destructor
/**
* @brief Construc all the element of an empty Edge.
* @param self an empty Edge ot yet constructed.
* @param source the source Node the edge start from (default NULL)
* @param target the target Node to connect (default NULL)
* @return The pointer to the new NetWorld.
*/
void Edge_construct( Edge * self, Node * source, Node * target );
/** /**
* @brief Allocate the memory to store a NetWorld. * @brief Allocate the memory to store a NetWorld.
* @return The pointer to the new NetWorld. * @return The pointer to the new NetWorld.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment