Implement net_meta info for nodes

This fixes #6.
This commit is contained in:
Markus Koch 2021-06-20 14:48:38 +02:00
parent ff214722a8
commit f1868aba04
3 changed files with 27 additions and 9 deletions

View File

@ -12,6 +12,7 @@ int dijkstra_node_same (struct dijkstra_node *node_a,
int same = 1;
// Not the proper way to do it, but it works for now.
same &= (node_a->net_meta == node_b->net_meta);
same &= (fabs(node_a->position.x - node_b->position.x) < FP_THRESHOLD);
same &= (fabs(node_a->position.y - node_b->position.y) < FP_THRESHOLD);
same &= (node_a->position.z == node_b->position.z);
@ -28,7 +29,8 @@ int dijkstra_node_same (struct dijkstra_node *node_a,
struct dijkstra_node *dijkstra_node_new(float x,
float y,
int z,
int uid)
int uid,
struct dijkstra_net_meta *net_meta)
{
struct dijkstra_node *node;
@ -38,6 +40,7 @@ struct dijkstra_node *dijkstra_node_new(float x,
node->position.y = y;
node->position.z = z;
node->uid = uid;
node->net_meta = net_meta;
node->paths = NULL;
}
@ -71,7 +74,8 @@ struct dijkstra_node *dijkstra_node_exists(GList *list,
struct dijkstra_node *dijkstra_node_new_to_list(GList **list,
float x,
float y,
int z)
int z,
struct dijkstra_net_meta *net_meta)
{
struct dijkstra_node *node;
struct dijkstra_node *found;
@ -79,7 +83,7 @@ struct dijkstra_node *dijkstra_node_new_to_list(GList **list,
uid = g_list_length(*list);
node = dijkstra_node_new(x, y, z, uid);
node = dijkstra_node_new(x, y, z, uid, net_meta);
if (!node)
return NULL;
@ -320,6 +324,9 @@ int dijkstra_path_intersect(struct dijkstra_solver *solver,
return 0; // Never intersect trainlines (apart from with access types)
}
if (!target_path)
target_path = path_b; // Needed for net_meta selection below
// Check height
p0_z = path_a->source->position.z;
p1_z = path_a->destination->position.z;
@ -356,7 +363,7 @@ int dijkstra_path_intersect(struct dijkstra_solver *solver,
i_y = p0_y + (t * s1_y);
i_z = p0_z; // They must all on the same height when intersecting, so we can pick whichever.
node_new = dijkstra_node_new_to_list(&solver->nodes, i_x, i_y, i_z);
node_new = dijkstra_node_new_to_list(&solver->nodes, i_x, i_y, i_z, target_path->source->net_meta);
if (node_new != path_a->source && node_new != path_a->destination) {
path_new = dijkstra_path_dup_shallow(path_a);
solver->paths = g_list_append(solver->paths, (gpointer) path_new);
@ -437,8 +444,8 @@ struct dijkstra_path *dijkstra_path_new_to_list(struct dijkstra_solver *solver,
GList *l_last;
struct dijkstra_path *path_last = NULL;
n1 = dijkstra_node_new_to_list(&solver->nodes, x1, y1, z1);
n2 = dijkstra_node_new_to_list(&solver->nodes, x2, y2, z2);
n1 = dijkstra_node_new_to_list(&solver->nodes, x1, y1, z1, net_meta);
n2 = dijkstra_node_new_to_list(&solver->nodes, x2, y2, z2, net_meta);
path = dijkstra_path_new(name, n1, n2, weight, net_meta);
l_last = g_list_last(solver->paths);

View File

@ -39,6 +39,7 @@ struct dijkstra_path {
struct dijkstra_node {
struct position position;
struct dijkstra_net_meta *net_meta;
GList *paths;
@ -77,6 +78,7 @@ struct dijkstra_net_meta *dijkstra_net_meta_new_to_list(struct dijkstra_solver *
struct dijkstra_node *dijkstra_node_new_to_list(GList **list,
float x,
float y,
int z);
int z,
struct dijkstra_net_meta *net_meta);
#endif // DIJKSTRAGRAPH_H

View File

@ -63,6 +63,7 @@ int add_geojson_to_dijkstra(struct dijkstra_solver *solver,
arr = json_node_get_array(root);
if (arr) {
i_max = json_array_get_length(arr);
net_meta = NULL;
for (i = 0; i < i_max; i++)
{
node = json_array_get_element(arr, i);
@ -79,7 +80,12 @@ int add_geojson_to_dijkstra(struct dijkstra_solver *solver,
json_reader_end_member(reader); // name
json_reader_end_member(reader); // properties
if (net_type == ACCESS) {
switch (net_type) {
case STREET:
if (!net_meta)
net_meta = dijkstra_net_meta_new_to_list(solver, net_type, NULL, NULL);
break;
case ACCESS:
access = name;
name = strchr(name, ':');
if (name == NULL) {
@ -93,12 +99,15 @@ int add_geojson_to_dijkstra(struct dijkstra_solver *solver,
do
name++;
while (*name == ' ' && *name != '\0');
G_GNUC_FALLTHROUGH;
case TRAINLINE:
net_meta = dijkstra_net_meta_new_to_list(solver, net_type, name, access);
break;
}
json_reader_read_member(reader, "geometry");
json_reader_read_member(reader, "coordinates");
z_last = 0; // By default, let's assume height 0
net_meta = dijkstra_net_meta_new_to_list(solver, net_type, name, access);
if (json_reader_is_array(reader)) {
j_max = json_reader_count_elements(reader);
for (j = 0; j < j_max; j++) {