Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
NetWorld
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Fatus
NetWorld
Commits
cc1ed4d1
Commit
cc1ed4d1
authored
Oct 20, 2020
by
guillaume
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
colored edges
parent
200074e4
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
47 additions
and
16 deletions
+47
-16
controlpanel.c
src/controlpanel.c
+2
-1
networld.c
src/networld.c
+23
-13
networld.h
src/networld.h
+22
-2
No files found.
src/controlpanel.c
View file @
cc1ed4d1
...
...
@@ -86,6 +86,7 @@ void Panel_drawNode(Panel * self, Node * n)
Vector2
screenPosition
=
Panel_pixelFromPosition
(
self
,
&
(
n
->
position
)
);
DrawCircleV
(
screenPosition
,
24
,
n
->
color
);
DrawCircleV
(
screenPosition
,
20
,
RAYWHITE
);
DrawText
(
n
->
name
,
(
int
)(
screenPosition
.
x
),
(
int
)(
screenPosition
.
y
),
20
,
n
->
color
);
}
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
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
)
...
...
src/networld.c
View file @
cc1ed4d1
...
...
@@ -3,19 +3,26 @@
#include <stdlib.h>
#include <assert.h>
#include <math.h>
#include <string.h>
//-----------------------------------//
//-- Node --//
//-----------------------------------//
// 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
*
p
=
malloc
(
sizeof
(
Node
)
);
Node_set
(
p
,
(
Vector2
){
0
.
f
,
0
.
f
},
GRAY
);
p
->
card
=
0
;
p
->
edges
=
Edge_newArray
(
0
);
Node_construct
(
p
);
return
p
;
}
...
...
@@ -25,9 +32,7 @@ Node * Node_newArray(int size)
Node
*
p
=
malloc
(
sizeof
(
Node
)
*
size
);
for
(
int
i
=
0
;
i
<
size
;
++
i
)
{
Node_set
(
p
,
(
Vector2
){
0
.
f
,
0
.
f
},
GRAY
);
p
[
i
].
edges
=
Edge_newArray
(
0
);
p
[
i
].
card
=
0
;
Node_construct
(
&
(
p
[
i
])
);
}
return
p
;
}
...
...
@@ -89,6 +94,7 @@ int Node_connect( Node * self, Node * target )
Node_resize
(
self
,
i
+
1
);
self
->
edges
[
i
].
_source
=
self
;
self
->
edges
[
i
].
_target
=
target
;
self
->
edges
[
i
].
color
=
self
->
color
;
self
->
edges
[
i
].
_twin
=
NULL
;
return
i
;
}
...
...
@@ -110,12 +116,18 @@ int Node_biconnect( Node * node1, Node * node2 )
//-----------------------------------//
// 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
*
p
=
malloc
(
sizeof
(
Edge
)
);
p
->
_source
=
source
;
p
->
_target
=
target
;
p
->
_twin
=
NULL
;
Edge_construct
(
p
,
source
,
target
);
return
p
;
}
...
...
@@ -137,9 +149,7 @@ Edge * Edge_newArray(int size)
Edge
*
p
=
malloc
(
sizeof
(
Edge
)
*
size
);
for
(
int
i
=
0
;
i
<
size
;
++
i
)
{
p
[
i
].
_source
=
NULL
;
p
[
i
].
_target
=
NULL
;
p
[
i
].
_twin
=
NULL
;
Edge_construct
(
&
(
p
[
i
]),
NULL
,
NULL
);
}
return
p
;
}
...
...
src/networld.h
View file @
cc1ed4d1
...
...
@@ -14,9 +14,12 @@ struct Str_Node {
Vector2
position
;
//! color (r, g, b, a) of the node
Color
color
;
struct
Str_Edge
*
edges
;
//! cardinality of the node (i.e. number of edges)
int
card
;
struct
Str_Edge
*
edges
;
// Content:
//! name of the node
char
*
name
;
};
/**
...
...
@@ -24,8 +27,14 @@ struct Str_Node {
*/
typedef
struct
Str_Node
Node
;
// 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
* @return The pointer to the new NetWorld.
...
...
@@ -126,6 +135,8 @@ struct Str_Edge {
Node
*
_target
;
//! pointer to the twin edge in case of bidirectional edge.
struct
Str_Edge
*
_twin
;
//! color (r, g, b, a) of the node
Color
color
;
};
/**
...
...
@@ -134,6 +145,15 @@ struct Str_Edge {
typedef
struct
Str_Edge
Edge
;
// 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.
* @return The pointer to the new NetWorld.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment