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
LAIRD Timothy
NetWorld
Commits
5063ae63
Commit
5063ae63
authored
Apr 13, 2021
by
ewen.madec
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Gabriel Graph + minimum distance btw nodes
parent
f6ac9d3d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
77 additions
and
38 deletions
+77
-38
controlpanel.c
src/controlpanel.c
+1
-1
random-map.c
src/random-map.c
+74
-36
random-map.h
src/random-map.h
+2
-1
No files found.
src/controlpanel.c
View file @
5063ae63
...
...
@@ -87,7 +87,7 @@ void Panel_drawNode(Panel * self, Node * n)
Vector2
screenPosition
=
Panel_pixelFromPosition
(
self
,
&
(
n
->
position
)
);
DrawCircleV
(
screenPosition
,
24
,
n
->
color
);
DrawCircleV
(
screenPosition
,
20
,
RAYWHITE
);
char
*
soldierText
=
malloc
(
sizeof
(
int
));
char
*
soldierText
=
malloc
(
20
*
sizeof
(
char
));
sprintf
(
soldierText
,
"%d"
,
n
->
soldiers
+
n
->
soldiersToAdd
);
DrawText
(
soldierText
,
(
int
)
screenPosition
.
x
-
MeasureText
(
soldierText
,
20
)
/
2
,
(
int
)
screenPosition
.
y
,
20
,
n
->
color
);
}
...
...
src/random-map.c
View file @
5063ae63
...
...
@@ -11,57 +11,95 @@
#include "raylib.h"
double
randfrom
(
double
min
,
double
max
)
double
randfrom
(
double
min
,
double
max
)
{
double
range
=
(
max
-
min
);
double
range
=
(
max
-
min
);
double
div
=
RAND_MAX
/
range
;
return
min
+
(
rand
()
/
div
);
}
double
dist
(
Node
node1
,
Node
node2
){
return
(
sqrt
(
(
node2
.
position
.
x
-
node1
.
position
.
x
)
*
(
node2
.
position
.
x
-
node1
.
position
.
x
)
+
(
node2
.
position
.
y
-
node1
.
position
.
y
)
*
(
node2
.
position
.
y
-
node1
.
position
.
y
)
));
double
dist
(
Vector2
vector1
,
Vector2
vector2
)
{
return
(
sqrt
((
vector2
.
x
-
vector1
.
x
)
*
(
vector2
.
x
-
vector1
.
x
)
+
(
vector2
.
y
-
vector1
.
y
)
*
(
vector2
.
y
-
vector1
.
y
)));
}
double
distNode
(
Node
node1
,
Node
node2
)
{
return
(
dist
(
node1
.
position
,
node2
.
position
));
}
void
Random_map
(
NetWorld
*
world
)
void
Random_map
(
NetWorld
*
world
)
{
int
nbNode
=
world
->
size
;
float
randomX
,
randomY
;
/* Intializes random number generator */
/* Intializes random number generator */
srand
(
time
(
NULL
));
/* Print 5 random numbers from -15.00 to 15.00 */
for
(
int
i
=
0
;
i
<
nbNode
;
i
++
)
{
double
randomX
=
randfrom
(
-
15
.
0
,
15
.
0
);
double
randomY
=
randfrom
(
-
15
.
0
,
15
.
0
);
char
*
name
;
name
=
malloc
(
sizeof
(
int
));
sprintf
(
name
,
"name : %d"
,
i
);
Node_set
(
&
(
world
->
nodes
[
i
]),
(
Vector2
){
randomX
,
randomY
},
RED
,
name
);
printf
(
"%f
\n
"
,
randomX
);
printf
(
"%f
\n
"
,
randomY
);
}
/* Generate nbNode*2 random numbers from -15.00 to 15.00 */
for
(
int
i
=
0
;
i
<
nbNode
;
i
++
)
{
if
(
i
>
0
)
{
bool
continueLoop
=
true
;
while
(
continueLoop
)
{
continueLoop
=
false
;
randomX
=
randfrom
(
-
30
.
0
,
30
.
0
);
randomY
=
randfrom
(
-
30
.
0
,
30
.
0
);
Vector2
newPosition
=
(
Vector2
){
randomX
,
randomY
};
for
(
int
j
=
0
;
j
<
i
;
j
++
)
{
printf
(
"positionComparee %d %f
\n
"
,
j
,
dist
(
world
->
nodes
[
j
].
position
,
newPosition
));
if
(
dist
(
world
->
nodes
[
j
].
position
,
newPosition
)
<
8
.
0
)
{
continueLoop
=
true
;
}
}
}
//randomX = randfrom(-15.0, 15.0);
//randomY = randfrom(-15.0, 15.0);
char
*
name
;
name
=
malloc
(
20
*
sizeof
(
char
));
sprintf
(
name
,
"name : %d"
,
i
);
Node_set
(
&
(
world
->
nodes
[
i
]),
(
Vector2
){
randomX
,
randomY
},
RED
,
name
);
}
else
{
randomX
=
randfrom
(
-
15
.
0
,
15
.
0
);
randomY
=
randfrom
(
-
15
.
0
,
15
.
0
);
char
*
name
;
name
=
malloc
(
20
*
sizeof
(
char
));
sprintf
(
name
,
"name : %d"
,
i
);
Node_set
(
&
(
world
->
nodes
[
i
]),
(
Vector2
){
randomX
,
randomY
},
RED
,
name
);
printf
(
"%f
\n
"
,
randomX
);
printf
(
"%f
\n
"
,
randomY
);
}
}
//Gabriel graph sort
for
(
int
i
=
0
;
i
<
nbNode
-
1
;
i
++
){
for
(
int
j
=
i
+
1
;
j
<
nbNode
;
j
++
){
for
(
int
i
=
0
;
i
<
nbNode
-
1
;
i
++
)
{
for
(
int
j
=
i
+
1
;
j
<
nbNode
;
j
++
)
{
int
compteurPointDansLeCercle
=
0
;
float
xm
=
0
.
5
*
(
world
->
nodes
[
i
].
position
.
x
+
world
->
nodes
[
j
].
position
.
x
);
float
ym
=
0
.
5
*
(
world
->
nodes
[
i
].
position
.
y
+
world
->
nodes
[
j
].
position
.
y
);
float
distCenterOfij
=
sqrt
((
xm
-
world
->
nodes
[
i
].
position
.
x
)
*
(
xm
-
world
->
nodes
[
i
].
position
.
x
)
+
(
ym
-
world
->
nodes
[
i
].
position
.
y
)
*
(
ym
-
world
->
nodes
[
i
].
position
.
y
));
printf
(
"xm : %f
\n
"
,
xm
);
printf
(
"ym : %f
\n
"
,
ym
);
printf
(
"distCenterOfij : %f
\n
"
,
distCenterOfij
);
printf
(
"dist %d%d : %f
\n
"
,
i
,
j
,
dist
((
world
->
nodes
[
i
]),
world
->
nodes
[
j
]));
for
(
int
k
=
0
;
k
<
nbNode
;
k
++
){
printf
(
" dist center - Node k %f
\n
"
,
sqrt
((
world
->
nodes
[
k
].
position
.
x
-
xm
)
*
(
world
->
nodes
[
k
].
position
.
x
-
xm
)
+
(
world
->
nodes
[
k
].
position
.
y
-
ym
)
*
(
world
->
nodes
[
k
].
position
.
y
-
ym
)));
if
(
sqrt
((
world
->
nodes
[
k
].
position
.
x
-
xm
)
*
(
world
->
nodes
[
k
].
position
.
x
-
xm
)
+
(
world
->
nodes
[
k
].
position
.
y
-
ym
)
*
(
world
->
nodes
[
k
].
position
.
y
-
ym
))
<
distCenterOfij
-
0
.
05
){
compteurPointDansLeCercle
++
;
float
xm
=
0
.
5
*
(
world
->
nodes
[
i
].
position
.
x
+
world
->
nodes
[
j
].
position
.
x
);
float
ym
=
0
.
5
*
(
world
->
nodes
[
i
].
position
.
y
+
world
->
nodes
[
j
].
position
.
y
);
Vector2
M
=
{
xm
,
ym
};
float
distNodeCenterOfij
=
dist
(
world
->
nodes
[
i
].
position
,
M
);
//printf("xm : %f\n", xm);
//printf("ym : %f\n", ym);
//printf("distNodeCenterOfij : %f\n", distNodeCenterOfij);
printf
(
"distNode %d%d : %f
\n
"
,
i
,
j
,
distNode
((
world
->
nodes
[
i
]),
world
->
nodes
[
j
]));
for
(
int
k
=
0
;
k
<
nbNode
;
k
++
)
{
//printf(" distNode center - Node k %f\n", dist(world->nodes[k].position, M));
if
(
dist
(
world
->
nodes
[
k
].
position
,
M
)
<
distNodeCenterOfij
-
0
.
05
)
{
compteurPointDansLeCercle
++
;
}
}
printf
(
"compteurPointDansLeCercle : %i
\n
"
,
compteurPointDansLeCercle
);
if
(
compteurPointDansLeCercle
==
0
){
//printf("compteurPointDansLeCercle : %i\n", compteurPointDansLeCercle);
if
(
compteurPointDansLeCercle
==
0
)
{
NetWorld_biconnect
(
world
,
i
,
j
);
}
}
}
}
}
\ No newline at end of file
src/random-map.h
View file @
5063ae63
...
...
@@ -8,6 +8,7 @@ void Random_map(NetWorld * world);
double
randfrom
(
double
min
,
double
max
);
double
dist
(
Node
node1
,
Node
node2
);
double
dist
(
Vector2
vector1
,
Vector2
vector2
);
double
distNode
(
Node
node1
,
Node
node2
);
#endif
\ No newline at end of file
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