Compare commits
1 Commits
master
...
wip/bound-
Author | SHA1 | Date | |
---|---|---|---|
724a663a34 |
@ -286,6 +286,7 @@ int dijkstra_path_intersect(struct dijkstra_solver *solver,
|
||||
struct dijkstra_node *disconnected_node;
|
||||
struct dijkstra_path *access_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 p2_x, p2_y, p3_x, p3_y;
|
||||
@ -308,8 +309,9 @@ int dijkstra_path_intersect(struct dijkstra_solver *solver,
|
||||
}
|
||||
|
||||
if (access_path) {
|
||||
net_meta_access = (struct dijkstra_net_meta_access *) access_path->net_meta->type_data;
|
||||
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
|
||||
}
|
||||
} else {
|
||||
@ -464,6 +466,42 @@ struct dijkstra_solver *dijkstra_solver_new()
|
||||
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)
|
||||
{
|
||||
GList *l;
|
||||
@ -491,9 +529,7 @@ void dijkstra_solver_free(struct dijkstra_solver *solver)
|
||||
for (l = solver->net_metas; l != NULL; l = l->next) {
|
||||
net_meta = (struct dijkstra_net_meta*) l->data;
|
||||
free(net_meta->name);
|
||||
if (net_meta->access)
|
||||
free(net_meta->access);
|
||||
free(net_meta);
|
||||
dijkstra_netmeta_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,
|
||||
char *name,
|
||||
char *access)
|
||||
void *type_data)
|
||||
{
|
||||
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) {
|
||||
net_meta->type = net_type;
|
||||
net_meta->name = strdup(name);
|
||||
if (access)
|
||||
net_meta->access = strdup(access);
|
||||
else
|
||||
net_meta->access = NULL;
|
||||
net_meta->type_data = type_data;
|
||||
}
|
||||
|
||||
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) {
|
||||
net_meta = l->data;
|
||||
if (net_meta->type == net_type &&
|
||||
!strcmp(net_meta->name, name) &&
|
||||
(net_meta->access && (!strcmp(net_meta->access, access)))) {
|
||||
return net_meta;
|
||||
if (net_meta->type == net_type && !strcmp(net_meta->name, name)) {
|
||||
switch (net_meta->type) {
|
||||
case ACCESS:
|
||||
if (!strcmp(((struct dijkstra_net_meta_access *)net_meta->type_data)->access, access))
|
||||
return net_meta;
|
||||
break;
|
||||
default:
|
||||
return net_meta;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -23,10 +23,19 @@ struct position {
|
||||
|
||||
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 {
|
||||
char *name;
|
||||
enum dijkstra_net_type type;
|
||||
char *access;
|
||||
void *type_data;
|
||||
};
|
||||
|
||||
struct dijkstra_path {
|
||||
|
@ -27,6 +27,8 @@ int add_geojson_to_dijkstra(struct dijkstra_solver *solver,
|
||||
|
||||
enum dijkstra_net_type net_type;
|
||||
struct dijkstra_net_meta *net_meta;
|
||||
void *type_data = NULL;
|
||||
struct dijkstra_net_meta_access *net_meta_access = NULL;
|
||||
|
||||
struct _stats {
|
||||
int nodes;
|
||||
@ -77,14 +79,23 @@ int add_geojson_to_dijkstra(struct dijkstra_solver *solver,
|
||||
json_reader_read_member(reader, "name");
|
||||
name = strdup(json_reader_get_string_value(reader));
|
||||
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;
|
||||
name = strchr(name, ':');
|
||||
if (name == NULL) {
|
||||
report(LL_ERROR,
|
||||
"Invalid name for accesss. '%s'",
|
||||
"Invalid name for access. '%s'",
|
||||
access);
|
||||
g_object_unref(reader);
|
||||
continue;
|
||||
@ -93,12 +104,18 @@ int add_geojson_to_dijkstra(struct dijkstra_solver *solver,
|
||||
do
|
||||
name++;
|
||||
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, "coordinates");
|
||||
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)) {
|
||||
j_max = json_reader_count_elements(reader);
|
||||
for (j = 0; j < j_max; j++) {
|
||||
|
Loading…
Reference in New Issue
Block a user