Compare commits

...

3 Commits

3 changed files with 30 additions and 11 deletions

View File

@ -12,6 +12,7 @@ int dijkstra_node_same (struct dijkstra_node *node_a,
int same = 1; int same = 1;
// Not the proper way to do it, but it works for now. // 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.x - node_b->position.x) < FP_THRESHOLD);
same &= (fabs(node_a->position.y - node_b->position.y) < FP_THRESHOLD); same &= (fabs(node_a->position.y - node_b->position.y) < FP_THRESHOLD);
same &= (node_a->position.z == node_b->position.z); 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, struct dijkstra_node *dijkstra_node_new(float x,
float y, float y,
int z, int z,
int uid) int uid,
struct dijkstra_net_meta *net_meta)
{ {
struct dijkstra_node *node; struct dijkstra_node *node;
@ -38,6 +40,7 @@ struct dijkstra_node *dijkstra_node_new(float x,
node->position.y = y; node->position.y = y;
node->position.z = z; node->position.z = z;
node->uid = uid; node->uid = uid;
node->net_meta = net_meta;
node->paths = NULL; 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, struct dijkstra_node *dijkstra_node_new_to_list(GList **list,
float x, float x,
float y, float y,
int z) int z,
struct dijkstra_net_meta *net_meta)
{ {
struct dijkstra_node *node; struct dijkstra_node *node;
struct dijkstra_node *found; struct dijkstra_node *found;
@ -79,7 +83,7 @@ struct dijkstra_node *dijkstra_node_new_to_list(GList **list,
uid = g_list_length(*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) if (!node)
return NULL; return NULL;
@ -320,6 +324,9 @@ int dijkstra_path_intersect(struct dijkstra_solver *solver,
return 0; // Never intersect trainlines (apart from with access types) 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 // Check height
p0_z = path_a->source->position.z; p0_z = path_a->source->position.z;
p1_z = path_a->destination->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_y = p0_y + (t * s1_y);
i_z = p0_z; // They must all on the same height when intersecting, so we can pick whichever. 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) { if (node_new != path_a->source && node_new != path_a->destination) {
path_new = dijkstra_path_dup_shallow(path_a); path_new = dijkstra_path_dup_shallow(path_a);
solver->paths = g_list_append(solver->paths, (gpointer) path_new); solver->paths = g_list_append(solver->paths, (gpointer) path_new);
@ -374,8 +381,7 @@ int dijkstra_path_intersect(struct dijkstra_solver *solver,
path_new->destination, path_new->destination,
path_new->net_meta->type); path_new->net_meta->type);
// TODO: I don't have to iterate over the *entire* array here, it should be enough to only iterate over the entries after path_b. dijkstra_path_intersect_all(solver, path_b, path_new); // Since straight paths can only cross once, we don't need to check any newly created entries.
dijkstra_path_intersect_all(solver, path_new, path_new); // Since straight paths can only cross once, we don't need to check any newly created entries.
} }
// Now do the same thing for path b // Now do the same thing for path b
@ -394,6 +400,8 @@ int dijkstra_path_intersect(struct dijkstra_solver *solver,
path_new->weight = dijkstra_get_weight_from_distance(path_new->source, path_new->weight = dijkstra_get_weight_from_distance(path_new->source,
path_new->destination, path_new->destination,
path_new->net_meta->type); path_new->net_meta->type);
dijkstra_path_intersect_all(solver, path_a, path_new);
} }
// In case neither if matches that means we are on the corner where two paths intersect at their ends. // In case neither if matches that means we are on the corner where two paths intersect at their ends.
@ -436,8 +444,8 @@ struct dijkstra_path *dijkstra_path_new_to_list(struct dijkstra_solver *solver,
GList *l_last; GList *l_last;
struct dijkstra_path *path_last = NULL; struct dijkstra_path *path_last = NULL;
n1 = dijkstra_node_new_to_list(&solver->nodes, x1, y1, z1); n1 = dijkstra_node_new_to_list(&solver->nodes, x1, y1, z1, net_meta);
n2 = dijkstra_node_new_to_list(&solver->nodes, x2, y2, z2); n2 = dijkstra_node_new_to_list(&solver->nodes, x2, y2, z2, net_meta);
path = dijkstra_path_new(name, n1, n2, weight, net_meta); path = dijkstra_path_new(name, n1, n2, weight, net_meta);
l_last = g_list_last(solver->paths); l_last = g_list_last(solver->paths);

View File

@ -39,6 +39,7 @@ struct dijkstra_path {
struct dijkstra_node { struct dijkstra_node {
struct position position; struct position position;
struct dijkstra_net_meta *net_meta;
GList *paths; 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, struct dijkstra_node *dijkstra_node_new_to_list(GList **list,
float x, float x,
float y, float y,
int z); int z,
struct dijkstra_net_meta *net_meta);
#endif // DIJKSTRAGRAPH_H #endif // DIJKSTRAGRAPH_H

View File

@ -63,6 +63,7 @@ int add_geojson_to_dijkstra(struct dijkstra_solver *solver,
arr = json_node_get_array(root); arr = json_node_get_array(root);
if (arr) { if (arr) {
i_max = json_array_get_length(arr); i_max = json_array_get_length(arr);
net_meta = NULL;
for (i = 0; i < i_max; i++) for (i = 0; i < i_max; i++)
{ {
node = json_array_get_element(arr, 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); // name
json_reader_end_member(reader); // properties 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; access = name;
name = strchr(name, ':'); name = strchr(name, ':');
if (name == NULL) { if (name == NULL) {
@ -93,12 +99,15 @@ int add_geojson_to_dijkstra(struct dijkstra_solver *solver,
do do
name++; name++;
while (*name == ' ' && *name != '\0'); 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, "geometry");
json_reader_read_member(reader, "coordinates"); json_reader_read_member(reader, "coordinates");
z_last = 0; // By default, let's assume height 0 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)) { if (json_reader_is_array(reader)) {
j_max = json_reader_count_elements(reader); j_max = json_reader_count_elements(reader);
for (j = 0; j < j_max; j++) { for (j = 0; j < j_max; j++) {