Compare commits
No commits in common. "f1868aba04117f2c5d0cdc1d5f3e80b4f823bd6b" and "6ffee116c7a651205c1699a96e354f48f8b0a699" have entirely different histories.
f1868aba04
...
6ffee116c7
@ -12,7 +12,6 @@ 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);
|
||||||
@ -29,8 +28,7 @@ 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;
|
||||||
|
|
||||||
@ -40,7 +38,6 @@ 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -74,8 +71,7 @@ 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;
|
||||||
@ -83,7 +79,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, net_meta);
|
node = dijkstra_node_new(x, y, z, uid);
|
||||||
if (!node)
|
if (!node)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
@ -324,9 +320,6 @@ 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;
|
||||||
@ -363,7 +356,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, target_path->source->net_meta);
|
node_new = dijkstra_node_new_to_list(&solver->nodes, i_x, i_y, i_z);
|
||||||
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);
|
||||||
@ -381,7 +374,8 @@ int dijkstra_path_intersect(struct dijkstra_solver *solver,
|
|||||||
path_new->destination,
|
path_new->destination,
|
||||||
path_new->net_meta->type);
|
path_new->net_meta->type);
|
||||||
|
|
||||||
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.
|
// 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_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
|
||||||
@ -400,8 +394,6 @@ 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.
|
||||||
@ -444,8 +436,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, net_meta);
|
n1 = dijkstra_node_new_to_list(&solver->nodes, x1, y1, z1);
|
||||||
n2 = dijkstra_node_new_to_list(&solver->nodes, x2, y2, z2, net_meta);
|
n2 = dijkstra_node_new_to_list(&solver->nodes, x2, y2, z2);
|
||||||
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);
|
||||||
|
@ -39,7 +39,6 @@ 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;
|
||||||
|
|
||||||
@ -78,7 +77,6 @@ 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
|
||||||
|
@ -63,7 +63,6 @@ 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);
|
||||||
@ -80,12 +79,7 @@ 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
|
||||||
|
|
||||||
switch (net_type) {
|
if (net_type == ACCESS) {
|
||||||
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) {
|
||||||
@ -99,15 +93,12 @@ 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++) {
|
||||||
|
Loading…
Reference in New Issue
Block a user