Compare commits

...

1 Commits

Author SHA1 Message Date
724a663a34 wip: bound for refactoring 2021-03-13 13:38:25 +01:00
3 changed files with 83 additions and 18 deletions

View File

@ -286,6 +286,7 @@ int dijkstra_path_intersect(struct dijkstra_solver *solver,
struct dijkstra_node *disconnected_node; struct dijkstra_node *disconnected_node;
struct dijkstra_path *access_path = NULL; struct dijkstra_path *access_path = NULL;
struct dijkstra_path *target_path = NULL; struct dijkstra_path *target_path = NULL;
struct dijkstra_net_meta_access *net_meta_access = NULL;
float p0_x, p0_y, p1_x, p1_y; float p0_x, p0_y, p1_x, p1_y;
float p2_x, p2_y, p3_x, p3_y; float p2_x, p2_y, p3_x, p3_y;
@ -308,8 +309,9 @@ int dijkstra_path_intersect(struct dijkstra_solver *solver,
} }
if (access_path) { if (access_path) {
net_meta_access = (struct dijkstra_net_meta_access *) access_path->net_meta->type_data;
if (target_path->net_meta->type != STREET && if (target_path->net_meta->type != STREET &&
!strstr(access_path->net_meta->access, target_path->name)) { !strstr(net_meta_access->access, target_path->name)) {
return 0; // Don't intersect if access != name of target return 0; // Don't intersect if access != name of target
} }
} else { } else {
@ -464,6 +466,42 @@ struct dijkstra_solver *dijkstra_solver_new()
return solver; return solver;
} }
struct dijkstra_net_meta_access *dijkstra_net_meta_access_new(char *access) {
struct dijkstra_net_meta_access *nma;
nma = malloc(sizeof(nma));
nma->access = strdup(access);
return nma;
}
void dijkstra_netmeta_free(struct dijkstra_net_meta *net_meta)
{
struct dijkstra_net_meta_access *nma;
struct dijkstra_net_meta_trainline *nmt;
nma = (struct dijkstra_net_meta_access *) net_meta->type_data;
nmt = (struct dijkstra_net_meta_trainline *) net_meta->type_data;
switch (net_meta->type) {
case ACCESS:
if (nma->access)
free(nma->access);
break;
case TRAINLINE:
if (nmt->start)
free(nmt->start);
if (nmt->end)
free(nmt->end);
break;
default:
break; // Nothing to do for other types
}
free(net_meta);
}
void dijkstra_solver_free(struct dijkstra_solver *solver) void dijkstra_solver_free(struct dijkstra_solver *solver)
{ {
GList *l; GList *l;
@ -491,9 +529,7 @@ void dijkstra_solver_free(struct dijkstra_solver *solver)
for (l = solver->net_metas; l != NULL; l = l->next) { for (l = solver->net_metas; l != NULL; l = l->next) {
net_meta = (struct dijkstra_net_meta*) l->data; net_meta = (struct dijkstra_net_meta*) l->data;
free(net_meta->name); free(net_meta->name);
if (net_meta->access) dijkstra_netmeta_free(net_meta);
free(net_meta->access);
free(net_meta);
} }
} }
@ -546,7 +582,7 @@ struct dijkstra_node *dijkstra_node_find_closest_node(struct dijkstra_solver *so
struct dijkstra_net_meta *dijkstra_net_meta_new(enum dijkstra_net_type net_type, struct dijkstra_net_meta *dijkstra_net_meta_new(enum dijkstra_net_type net_type,
char *name, char *name,
char *access) void *type_data)
{ {
struct dijkstra_net_meta *net_meta; struct dijkstra_net_meta *net_meta;
@ -554,10 +590,7 @@ struct dijkstra_net_meta *dijkstra_net_meta_new(enum dijkstra_net_type net_type,
if (net_meta) { if (net_meta) {
net_meta->type = net_type; net_meta->type = net_type;
net_meta->name = strdup(name); net_meta->name = strdup(name);
if (access) net_meta->type_data = type_data;
net_meta->access = strdup(access);
else
net_meta->access = NULL;
} }
return net_meta; return net_meta;
@ -576,10 +609,16 @@ struct dijkstra_net_meta *dijkstra_net_meta_new_to_list(struct dijkstra_solver *
for (l = solver->net_metas; l != NULL; l = l->next) { for (l = solver->net_metas; l != NULL; l = l->next) {
net_meta = l->data; net_meta = l->data;
if (net_meta->type == net_type && if (net_meta->type == net_type && !strcmp(net_meta->name, name)) {
!strcmp(net_meta->name, name) && switch (net_meta->type) {
(net_meta->access && (!strcmp(net_meta->access, access)))) { case ACCESS:
return net_meta; if (!strcmp(((struct dijkstra_net_meta_access *)net_meta->type_data)->access, access))
return net_meta;
break;
default:
return net_meta;
break;
}
} }
} }

View File

@ -23,10 +23,19 @@ struct position {
enum dijkstra_net_type {STREET, TRAINLINE, ACCESS}; enum dijkstra_net_type {STREET, TRAINLINE, ACCESS};
struct dijkstra_net_meta_access {
char *access;
};
struct dijkstra_net_meta_trainline {
char *start;
char *end;
};
struct dijkstra_net_meta { struct dijkstra_net_meta {
char *name; char *name;
enum dijkstra_net_type type; enum dijkstra_net_type type;
char *access; void *type_data;
}; };
struct dijkstra_path { struct dijkstra_path {

View File

@ -27,6 +27,8 @@ int add_geojson_to_dijkstra(struct dijkstra_solver *solver,
enum dijkstra_net_type net_type; enum dijkstra_net_type net_type;
struct dijkstra_net_meta *net_meta; struct dijkstra_net_meta *net_meta;
void *type_data = NULL;
struct dijkstra_net_meta_access *net_meta_access = NULL;
struct _stats { struct _stats {
int nodes; int nodes;
@ -77,14 +79,23 @@ int add_geojson_to_dijkstra(struct dijkstra_solver *solver,
json_reader_read_member(reader, "name"); json_reader_read_member(reader, "name");
name = strdup(json_reader_get_string_value(reader)); name = strdup(json_reader_get_string_value(reader));
json_reader_end_member(reader); // name json_reader_end_member(reader); // name
json_reader_end_member(reader); // properties
if (net_type == ACCESS) { switch (net_type) {
case TRAINLINE:
json_reader_read_member(reader, "start");
name = strdup(json_reader_get_string_value(reader));
json_reader_end_member(reader); // name
break;
case ACCESS:
net_meta_access = netmeta;
// TODO: problem, I only know whether to alloc this when I have called new_to_list.....
// I'll deal with this some other day.
access = name; access = name;
name = strchr(name, ':'); name = strchr(name, ':');
if (name == NULL) { if (name == NULL) {
report(LL_ERROR, report(LL_ERROR,
"Invalid name for accesss. '%s'", "Invalid name for access. '%s'",
access); access);
g_object_unref(reader); g_object_unref(reader);
continue; continue;
@ -93,12 +104,18 @@ int add_geojson_to_dijkstra(struct dijkstra_solver *solver,
do do
name++; name++;
while (*name == ' ' && *name != '\0'); while (*name == ' ' && *name != '\0');
break;
default:
break; // Other types have no special fields
} }
json_reader_end_member(reader); // properties
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); net_meta = dijkstra_net_meta_new_to_list(solver, net_type, name, type_data);
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++) {