41 float **rgb_r,
float **rgb_g,
float **rgb_b){
53 double *colors =
NULL;
55 const size_t n = A0->
m;
58 bool weightedQ =
true;
70 int lightness[] = {0, 100};
74 const double accuracy = 0.01;
90 for (
size_t i = 0; i < n; i++){
91 (*rgb_r)[i + 1] = (float)colors[cdim * i];
92 (*rgb_g)[i + 1] = (float)colors[cdim * i + 1];
93 (*rgb_b)[i + 1] = (float)colors[cdim * i + 2];
100 const size_t n =
A->m;
104 rgb_r++; rgb_b++; rgb_g++;
106 for (
size_t i = 0; i < n; i++) rgb_r[i] = u[i];
108 for (
size_t i = 0; i < n; i++) rgb_g[i] = u[i];
110 for (
size_t i = 0; i < n; i++) rgb_b[i] = u[i];
116 return point_poly_map->
ja[point_poly_map->
ia[ip]];
127 int i, j, *ia, *ja, u, v;
135 assert(
graph->m == (
size_t)n);
136 ia =
D->ia; ja =
D->ja;
142 for (i = 0; i < n; i++){
144 for (j = ia[i]; j < ia[i+1]; j++){
147 if (grouping[u] != grouping[v]){
159 GV_INFO(
"ratio (edges among discontiguous regions vs total edges)=%f", (
double)nbad / ia[n]);
197 double xy[2], yz[2], nxy[2], nyz[2], ymx[2], ymz[2], beta, bot;
200 for (i = 0; i < 2; i++) ymx[i] = y[i] - x[i];
201 for (i = 0; i < 2; i++) ymz[i] = y[i] -
z[i];
202 for (i = 0; i < 2; i++) xy[i] = 0.5*(x[i] + y[i]);
203 for (i = 0; i < 2; i++) yz[i] = 0.5*(y[i] +
z[i]);
208 bot = nyz[0]*(x[0]-y[0])+nyz[1]*(x[1]-y[1]);
210 c[0] = xy[0]; c[1] = xy[1];
213 beta = ((x[0] - y[0])*(xy[0] - yz[0])+(x[1] - y[1])*(xy[1] - yz[1]))/bot;
214 c[0] = yz[0] + beta*nyz[0];
215 c[1] = yz[1] + beta*nyz[1];
229static void dot_polygon(
agxbuf *sbuff, doubles_t xp, doubles_t yp,
230 double line_width,
bool fill,
const char *cstring) {
237 strlen(cstring), cstring, strlen(cstring), cstring,
241 size_t len_swidth = (size_t)snprintf(
NULL, 0,
"%f", line_width);
243 " -setlinewidth(%f) L %" PRISIZE_T " ", strlen(cstring), cstring,
244 len_swidth + 14, line_width,
LIST_SIZE(&xp));
250 for (
size_t i = 0; i <
LIST_SIZE(&xp); i++) {
258 double *x_poly,
int *polys_groups,
float *r,
259 float *g,
float *b,
const char *opacity) {
260 int j, *ia = polys->
ia, *ja = polys->
ja, *a = polys->
a, nverts = polys->
n, ipoly,first;
261 const size_t npolys = polys->
m;
262 const bool fill =
false;
263 const bool use_line = line_width >= 0;
265 agxbuf cstring_buffer = {0};
266 const char *cstring =
"#aaaaaaff";
272 first = abs(a[0]); ipoly = first + 1;
273 for (
size_t i = 0; i < npolys; i++){
274 for (j = ia[i]; j < ia[i+1]; j++){
275 assert(ja[j] < nverts && ja[j] >= 0);
277 if (abs(a[j]) != ipoly){
280 rgb2hex(r[polys_groups[i]], g[polys_groups[i]], b[polys_groups[i]],
281 &cstring_buffer, opacity);
282 cstring =
agxbuse(&cstring_buffer);
284 dot_polygon(sbuff, xp, yp, line_width, fill, cstring);
293 dot_polygon(sbuff, xp, yp, line_width, fill, line_color);
296 dot_polygon(sbuff, xp, yp, -1,
true, cstring);
306 const char *line_color,
double *x_poly,
int *polys_groups,
307 float *r,
float *g,
float *b,
311 bool plot_polyQ =
true;
314 if (!r || !g || !b) plot_polyQ =
false;
332 if (line_width >= 0){
357 int i, j, i0, i1, i2, ntri;
361 if (trilist ==
NULL) {
368 for (i = 0; i < ntri; i++) {
369 for (j = 0; j < 3; j++) {
370 (*T)[i].vertices[j] = trilist[i * 3 + j];
372 i0 = (*T)[i].vertices[0]; i1 = (*T)[i].vertices[1]; i2 = (*T)[i].vertices[2];
395 int one = 1, jj, i, j, ig1, ig2;
400 for (i = 0; i < n; i++) {
401 max_grp =
MAX(groups[i], max_grp);
409 for (i = 0; i < n; i++){
412 for (j = ia[i]; j < ia[i+1]; j++){
414 if (i != jj && groups[i] != groups[jj] && groups[jj] !=
GRP_RANDOM && groups[jj] !=
GRP_BBOX){
415 ig1 = groups[i]-1; ig2 = groups[jj]-1;
428 int one = 1, jj, i, j;
436 for (i = 0; i < n; i++){
437 for (j = ia[i]; j < ia[i+1]; j++){
439 if (i != jj && groups[i] == groups[jj]){
451 free((*poly_point_map)->ia);
452 free((*poly_point_map)->ja);
453 (*poly_point_map)->ia = comps_ptr;
454 (*poly_point_map)->ja = comps;
455 (*poly_point_map)->nz = (size_t)n;
461 int **polys_groups) {
467 int i, *tlist, nz, ipoly, nnt, ii, jj, t1, t2, t, cur, next, nn, j, nlink, sta;
468 int *
elist, edim = 3;
471 int *ie =
E->ia, *je =
E->ja, *e =
E->a;
475 for (i = 0; i < nt; i++) mask[i] = -1;
480 *polys_groups =
gv_calloc(ncomps,
sizeof(
int));
482 for (i = 0; i < nt; i++)
elist[i*edim + 2] = 0;
483 nz = ie[
E->m] - ie[0];
487 for (i = 0; (size_t)i < ncomps; i++) {
489 for (j = comps_ptr[i]; j < comps_ptr[i+1]; j++){
492 (*polys_groups)[i] = groups[ii];
497 for (jj = ie[ii]; jj < ie[ii+1]; jj++){
498 if (groups[je[jj]] != groups[ii] && jj < nz - 1 && je[jj] == je[jj+1]){
502 nlink =
elist[t1*edim + 2]%2;
503 elist[t1*edim + nlink] = t2;
504 elist[t1*edim + 2]++;
506 nlink =
elist[t2*edim + 2]%2;
507 elist[t2*edim + nlink] = t1;
508 elist[t2*edim + 2]++;
510 tlist[nnt++] = t1; tlist[nnt++] = t2;
517 for (j = 0; j < nnt; j++){
520 cur = sta = t; mask[cur] = i;
559 fprintf(stderr,
"cycle (edges): {");
561 fprintf(stderr,
"%d,",cur);
564 fprintf(stderr,
"%d}\n",cur);
567 fprintf(stderr,
"cycle (vertices): ");
575static int same_edge(
int ecur,
int elast,
int *edge_table){
597 int *ie =
E->
ia, *je =
E->ja, *e =
E->a, ne, j, t1, t2, jj, ii;
598 const size_t n =
E->m;
599 int *cycle, cycle_head = 0;
602 int *edge_cycle_map, NOT_ON_CYCLE = -1;
604 enum {NO_DUPLICATE = -1};
605 int *
elist, edim = 3;
609 int k, duplicate, ee = 0, ecur, enext, eprev, cur, next, nn, nlink,
head, elast = 0, etail, tail, ehead, efirst;
614 edge_table =
gv_calloc(
E->nz * 2,
sizeof(
int));
619 for (
size_t i = 0; i < n; i++){
620 for (j = ie[i]; j < ie[i+1]; j++){
621 if (j < ie[n] - ie[0] - 1 && (
int)i > je[j] && je[j] == je[j+1]){
626 edge_table[ne*2] = t1;
627 edge_table[ne*2+1] = t2;
632 edge_table[ne*2] = t2;
633 edge_table[ne*2+1] = t1;
643 assert(
E->nz >= (
size_t)ne);
649 edge_cycle_map =
gv_calloc(ne,
sizeof(
int));
651 for (
int i = 0; i < ne; i++) edge_cycle_map[i] = NOT_ON_CYCLE;
652 for (
int i = 0; i < ne; i++) emask[i] = -1;
658 for (
int i = 0; i < nt; i++)
elist[i*edim + 2] = 0;
662 for (
int i = 0; (size_t)i < ncomps; i++){
663 if (DEBUG_CYCLE) fprintf(stderr,
"\n ============ comp %d has %d members\n",i, comps_ptr[i+1]-comps_ptr[i]);
664 for (k = comps_ptr[i]; k < comps_ptr[i+1]; k++){
666 duplicate = NO_DUPLICATE;
667 if (DEBUG_CYCLE) fprintf(stderr,
"member = %d has %d neighbors\n",ii, ie[ii+1]-ie[ii]);
668 for (j = ie[ii]; j < ie[ii+1]; j++){
672 if (DEBUG_CYCLE) fprintf(stderr,
" linked with %d using half-edge %d, {head,tail} of the edge = {%d, %d}\n",jj, ee, t1,
edge_tail(ee));
673 nlink =
elist[t1*edim + 2]%2;
674 elist[t1*edim + nlink] = ee;
675 elist[t1*edim + 2]++;
677 if (edge_cycle_map[ee] != NOT_ON_CYCLE) duplicate = ee;
681 if (duplicate == NO_DUPLICATE){
687 edge_cycle_map[ecur] = 1;
690 if (DEBUG_CYCLE) fprintf(stderr,
"NEW CYCLE\n starting with edge %d, {head,tail}={%d,%d}\n", ee,
head, next);
691 while (next !=
head){
697 if (DEBUG_CYCLE) fprintf(stderr,
"cur edge = %d, next edge %d, {head,tail}={%d,%d},\n",ecur, enext,
edge_head(enext),
edge_tail(enext));
704 edge_cycle_map[enext] = 1;
710 if (DEBUG_CYCLE)
cycle_print(ee, cycle,edge_table);
714 ecur = ee = duplicate;
715 while (emask[ecur] == ii){
722 if (DEBUG_CYCLE) fprintf(stderr,
" duplicating edge = %d, starting from the a non-duplicating edge %d, search backwards\n",ee, ecur);
726 while (emask[ecur] == ii){
727 if (DEBUG_CYCLE) fprintf(stderr,
" remove edge %d (%d--%d)\n",ecur,
edge_head(ecur),
edge_tail(ecur));
729 edge_cycle_map[ecur] = NOT_ON_CYCLE;
741 fprintf(stderr,
"remaining (broken) cycle = ");
761 if (DEBUG_CYCLE) fprintf(stderr,
"forwarding now from edge %d = {%d, %d}, try to reach vtx %d, first edge from voro = %d\n",
769 if (
same_edge(ecur, efirst, edge_table)){
770 if (DEBUG_CYCLE) fprintf(stderr,
"this voro cell fill in a hole completely!!!!\n");
773 edge_cycle_map[ecur] = 1;
776 if (DEBUG_CYCLE) fprintf(stderr,
"starting with edge %d, {head,tail}={%d,%d}\n", ecur,
head, next);
777 while (next != tail){
783 if (DEBUG_CYCLE) fprintf(stderr,
"cur edge = %d, next edge %d, {head,tail}={%d,%d},\n",ecur, enext,
edge_head(enext),
edge_tail(enext));
792 edge_cycle_map[enext] = 1;
805 while ((enext =
cycle_next(ecur)) != cycle_head){
806 edge_cycle_map[ecur] = NOT_ON_CYCLE;
811 edge_cycle_map[ecur] = NOT_ON_CYCLE;
826 free(edge_cycle_map);
840 int *comps =
NULL, *comps_ptr =
NULL;
845 groups =
gv_calloc(n + nrandom,
sizeof(
int));
846 for (
int i = 0; i < n; i++) {
847 groups[i] = grouping[i];
850 for (
int i = n; i < n + nrandom - 4; i++) {
853 for (
int i = n + nrandom - 4; i < n + nrandom; i++) {
858 conn_comp(n + nrandom,
E, groups, poly_point_map);
860 size_t ncomps = (*poly_point_map)->m;
861 comps = (*poly_point_map)->ja;
862 comps_ptr = (*poly_point_map)->ia;
866 for (; ncomps > 0; ncomps--) {
867 if (groups[comps[comps_ptr[ncomps - 1]]] !=
GRP_RANDOM &&
868 groups[comps[comps_ptr[ncomps - 1]]] !=
GRP_BBOX)
break;
873 for (
int i2 = 0; i2 < nt; i2++){
874 for (j = 0; j <
dim; j++){
901 double bounding_box_margin,
int nrandom,
902 int nedgep,
double shore_depth_tol,
int *nverts,
909 double xmax[2],
xmin[2], area, *x = x0;
912 int dim2 = 2, nn = 0;
913 int max_qtree_level = 10;
915 int imin, nzok = 0, nzok0 = 0, nt;
916 double *xran,
point[2];
920 bool INCLUDE_OK_POINTS = include_OK_points;
922 int *grouping = grouping0;
924 int HIGHLIGHT_SET = highlight_cluster;
926 for (j = 0; j < dim2; j++) {
931 for (
int i = 0; i < n; i++){
932 for (j = 0; j < dim2; j++) {
939 area = boxsize[0]*boxsize[1];
943 }
else if (nrandom < 0){
944 nrandom = -nrandom * n;
945 }
else if (nrandom < 4) {
950 assert(nrandom >= 0);
952 if (shore_depth_tol < 0) shore_depth_tol = sqrt(area/(
double) n);
953 GV_INFO(
"nrandom=%d shore_depth_tol=%.08f", nrandom, shore_depth_tol);
963 fprintf(stderr,
"add art np = %d\n",np);
964 assert(
graph->nz <= INT_MAX);
967 for (
int i = 0; i < n*
dim; i++) y[i] = x[i];
968 grouping =
gv_calloc(n + nz * np,
sizeof(
int));
969 for (
int i = 0; i < n; i++) grouping[i] = grouping0[i];
971 for (
size_t i = 0; i <
graph->m; i++){
973 for (j =
graph->ia[i]; j <
graph->ia[i+1]; j++){
974 if (!HIGHLIGHT_SET || (grouping[i] == grouping[
graph->ja[j]] && grouping[i] == HIGHLIGHT_SET)){
975 for (t = 0; t < np; t++){
976 for (k = 0; k <
dim; k++){
977 y[nz*
dim+k] = t/((double) np)*x[(int)i*
dim+k] + (1-t/((
double) np))*x[(
graph->ja[j])*
dim + k];
979 assert(n + (nz-n)*np + t < n + nz*np && n + (nz-n)*np + t >= 0);
980 if (t/((
double) np) > 0.5){
981 grouping[nz] = grouping[i];
983 grouping[nz] = grouping[
graph->ja[j]];
990 fprintf(stderr,
"after adding edge points, n:%d->%d\n",n, nz);
1001 for (
int i = 0; i < dim2; i++) {
1002 if (bounding_box_margin > 0){
1003 xmin[i] -= bounding_box_margin;
1004 xmax[i] += bounding_box_margin;
1005 }
else if (bounding_box_margin < 0) {
1006 xmin[i] -= boxsize[i]*(-bounding_box_margin);
1007 xmax[i] += boxsize[i]*(-bounding_box_margin);
1009 xmin[i] -= fmax(boxsize[i] * 0.2, 2.* shore_depth_tol);
1010 xmax[i] += fmax(boxsize[i] * 0.2, 2 * shore_depth_tol);
1014 double bbm = bounding_box_margin;
1016 fprintf (stderr,
"bounding box margin: %.06f", bbm);
1018 fprintf (stderr,
"bounding box margin: (%.06f * %.06f)", boxsize[0], -bbm);
1020 fprintf(stderr,
"bounding box margin: %.06f",
1021 fmax(boxsize[0] * 0.2, 2 * shore_depth_tol));
1024 xran =
gv_calloc((nrandom + 4) * dim2,
sizeof(
double));
1026 if (INCLUDE_OK_POINTS){
1027 nzok0 = nzok = nrandom - 1;
1028 if (grouping == grouping0) {
1029 int *grouping2 =
gv_calloc(n + nrandom,
sizeof(
int));
1030 memcpy(grouping2, grouping,
sizeof(
int)*n);
1031 grouping = grouping2;
1033 grouping =
gv_recalloc(grouping, n, n + nrandom,
sizeof(
int));
1038 for (
int i = 0; i < nrandom; i++){
1040 for (j = 0; j < dim2; j++){
1046 if (min > shore_depth_tol){
1047 for (j = 0; j < dim2; j++){
1048 xran[nz*dim2+j] =
point[j];
1051 }
else if (INCLUDE_OK_POINTS && min > shore_depth_tol/10){
1052 for (j = 0; j < dim2; j++){
1053 xran[nzok*dim2+j] =
point[j];
1055 grouping[nn++] = grouping[
imin];
1062 if (
Verbose) fprintf(stderr,
"nn nrandom=%d\n", nrandom);
1064 xran =
gv_calloc(4 * dim2,
sizeof(
double));
1070 for (
int i = 0; i < dim2; i++)
xmin[i] -= 0.2*(
xmax[i]-
xmin[i]);
1071 for (
int i = 0; i < dim2; i++)
xmax[i] += 0.2*(
xmax[i]-
xmin[i]);
1073 for (j = 0; j < dim2; j++) xran[i*dim2+j] =
xmin[j];
1075 for (j = 0; j < dim2; j++) xran[i*dim2+j] =
xmax[j];
1077 xran[i*dim2] =
xmin[0]; xran[i*dim2+1] =
xmax[1];
1079 xran[i*dim2] =
xmax[0]; xran[i*dim2+1] =
xmin[1];
1084 if (INCLUDE_OK_POINTS){
1085 xcombined =
gv_calloc((nn + nrandom) * dim2,
sizeof(
double));
1087 xcombined =
gv_calloc((n + nrandom) * dim2,
sizeof(
double));
1089 for (i = 0; i < n; i++) {
1090 for (j = 0; j < dim2; j++) xcombined[i*dim2+j] = x[i*
dim+j];
1092 for (i = 0; i < nrandom; i++) {
1093 for (j = 0; j < dim2; j++) xcombined[(i + nn)*dim2+j] = xran[i*
dim+j];
1096 if (INCLUDE_OK_POINTS){
1097 for (i = 0; i < nn - n; i++) {
1098 for (j = 0; j < dim2; j++) xcombined[(i + n)*dim2+j] = xran[(nzok0 - i)*
dim+j];
1107 if (
Verbose) fprintf(stderr,
" highlight cluster %d, n = %d\n",HIGHLIGHT_SET, n);
1110 for (i = 0; i < n; i++){
1111 if (grouping[i] == HIGHLIGHT_SET){
1113 for (j = 0; j <
dim; j++){
1114 xcombined[nz++] = x[i*
dim+j];
1118 for (i = 0; i < n; i++){
1119 if (grouping[i] != HIGHLIGHT_SET){
1120 for (j = 0; j <
dim; j++){
1121 xcombined[nz++] = x[i*
dim+j];
1125 assert(nz == n*
dim);
1126 for (i = 0; i < nh; i++){
1129 for (i = nh; i < n; i++){
1134 if (
Verbose) fprintf(stderr,
"nh = %d\n",nh);
1139 if (
get_tri(n + nrandom, dim2, xcombined, &nt, &Tp, &
E) != 0) {
1143 get_polygons(n, nrandom, dim2, grouping, nt, Tp,
E, nverts, x_poly,
1144 poly_lines, polys, polys_groups, poly_point_map, country_graph);
1151 if (grouping != grouping0)
free(grouping);
1153 if (x != x0)
free(x);
1157static void add_point(
int *n,
int igrp,
double **x,
int *nmax,
double point[],
int **groups){
1160 int old_nmax = *nmax;
1162 *x =
gv_recalloc(*x, 2 * old_nmax, 2 * *nmax,
sizeof(
double));
1163 *groups =
gv_recalloc(*groups, old_nmax, *nmax,
sizeof(
int));
1166 (*x)[(*n)*2] =
point[0];
1167 (*x)[(*n)*2+1] =
point[1];
1168 (*groups)[*n] = igrp;
1177 for (i = 0; i < n; i++){
1186 int n,
double *x,
double *sizes,
1187 int *grouping,
SparseMatrix graph,
double bounding_box_margin,
int nrandom,
int *nart,
int nedgep,
1188 double shore_depth_tol,
1189 int *nverts,
double **x_poly,
1250 int N, nmax, i, j, igrp;
1254 double avgsize[2], avgsz, h[2], p1, p0;
1259 K = round(10 / (1 + n / 400.0));
1263 int maxgp = grouping[0];
1264 int mingp = grouping[0];
1265 for (i = 0; i < n; i++) {
1266 maxgp =
MAX(maxgp, grouping[i]);
1267 mingp =
MIN(mingp, grouping[i]);
1269 fprintf(stderr,
"max grouping - min grouping + 1 = %d\n",maxgp - mingp + 1);
1275 bounding_box_margin, nrandom, nedgep,
1276 shore_depth_tol, nverts, x_poly, poly_lines, polys,
1277 polys_groups, poly_point_map, country_graph,
1284 for (i = 0; i < n; i++){
1285 for (j = 0; j < 2; j++) {
1286 avgsize[j] += sizes[i*
dim+j];
1289 for (i = 0; i < 2; i++) avgsize[i] /= n;
1290 avgsz = 0.5*(avgsize[0] + avgsize[1]);
1291 GV_INFO(
"avgsize = {%f, %f}", avgsize[0], avgsize[1]);
1295 groups =
gv_calloc(n + nmax,
sizeof(
int));
1296 for (i = 0; i < n; i++) {
1297 groups[i] = grouping[i];
1298 for (j = 0; j < 2; j++){
1299 X[i*2+j] = x[i*
dim+j];
1304 if (shore_depth_tol < 0) {
1305 shore_depth_tol = -(shore_depth_tol)*avgsz;
1306 }
else if (shore_depth_tol == 0){
1309 shore_depth_tol = sqrt(area / n);
1310 GV_INFO(
"setting shore length ======%f", shore_depth_tol);
1315 double delta[2] = {0};
1317 delta[0] = .5*avgsize[0]/K;
delta[1] = .5*avgsize[1]/K;
1319 for (i = 0; i < n; i++){
1321 double nadded[2] = {0};
1322 for (j = 0; j < 2; j++) {
1324 nadded[j] = round(K * sizes[i *
dim + j] / avgsz);
1330 h[0] = sizes[i*
dim]/nadded[0];
1334 for (
double k = 0; k < nadded[0] - 1; k++){
1344 for (
double k = 0; k < nadded[0] - 1; k++){
1353 h[1] = sizes[i*
dim + 1]/nadded[1];
1357 for (
double k = 0; k < nadded[1] - 1; k++){
1367 for (
double k = 0; k < nadded[1] - 1; k++){
1378 bounding_box_margin, nrandom, nedgep,
1379 shore_depth_tol, nverts, x_poly, poly_lines, polys,
1380 polys_groups, poly_point_map, country_graph,
@ NO_GROUP
inherited the default (invalid) group
@ GRP_RANDOM
randomize assignment of a node
@ GRP_BBOX
last 4 randomized points that form a bounding box
@ INVALID_GROUP
group was never assigned
void QuadTree_get_nearest(QuadTree qt, double *x, double *ymin, int *imin, double *min)
QuadTree QuadTree_new_from_point_list(int dim, int n, int max_level, double *coord)
void QuadTree_delete(QuadTree q)
SparseMatrix SparseMatrix_new(size_t m, int n, size_t nz, int type, int format)
SparseMatrix SparseMatrix_distance_matrix(SparseMatrix D0)
SparseMatrix SparseMatrix_from_coordinate_format(SparseMatrix A)
int * SparseMatrix_weakly_connected_components(SparseMatrix A0, size_t *ncomp, int **comps)
SparseMatrix SparseMatrix_transpose(SparseMatrix A)
SparseMatrix SparseMatrix_symmetrize(SparseMatrix A, bool pattern_symmetric_only)
void SparseMatrix_export(FILE *f, SparseMatrix A)
void SparseMatrix_delete(SparseMatrix A)
SparseMatrix SparseMatrix_get_real_adjacency_matrix_symmetrized(SparseMatrix A)
SparseMatrix SparseMatrix_sort(SparseMatrix A)
SparseMatrix SparseMatrix_from_coordinate_format_not_compacted(SparseMatrix A)
SparseMatrix SparseMatrix_remove_diagonal(SparseMatrix A)
#define SparseMatrix_coordinate_form_add_entry(A, irn, jcn, val)
wrap SparseMatrix_coordinate_form_add_entry_ for type safety
Dynamically expanding string buffers.
static void agxbfree(agxbuf *xb)
free any malloced resources
static int agxbprint(agxbuf *xb, const char *fmt,...)
Printf-style output to an agxbuf.
static WUR char * agxbuse(agxbuf *xb)
Memory allocation wrappers that exit on failure.
static void * gv_recalloc(void *ptr, size_t old_nmemb, size_t new_nmemb, size_t size)
static void * gv_calloc(size_t nmemb, size_t size)
abstract graph C library, Cgraph API
void rgb2hex(float r, float g, float b, agxbuf *cstring, const char *opacity)
size_t * country_graph_coloring(int seed, SparseMatrix A)
helpers for verbose/debug printing
int * get_triangles(double *x, int n, int *tris)
static double dist(int dim, double *x, double *y)
#define X(prefix, name, str, type, subtype,...)
void vector_float_take(size_t n, float *v, size_t m, size_t *p, float **u)
double distance_cropped(double *x, int dim, int i, int j)
Agsym_t * agattr_text(Agraph_t *g, int kind, char *name, const char *value)
creates or looks up text attributes of a graph
int agwrite(Agraph_t *g, void *chan)
Return 0 on success, EOF on failure.
Agraph_t * graph(char *name)
static int imin(int a, int b)
minimum of two integers
type-generic dynamically expanding list
#define LIST_APPEND(list,...)
#define LIST_IS_EMPTY(list)
#define LIST_GET(list, index)
static SparseMatrix get_country_graph(int n, SparseMatrix A, int *groups)
static int make_map_internal(bool include_OK_points, int n, int dim, double *x0, int *grouping0, SparseMatrix graph, double bounding_box_margin, int nrandom, int nedgep, double shore_depth_tol, int *nverts, double **x_poly, SparseMatrix *poly_lines, SparseMatrix *polys, int **polys_groups, SparseMatrix *poly_point_map, SparseMatrix *country_graph, int highlight_cluster)
static void get_polygon_solids(int nt, SparseMatrix E, size_t ncomps, int *comps_ptr, int *comps, SparseMatrix *polys)
static void triangle_center(double x[], double y[], double z[], double c[])
void map_palette_optimal_coloring(char *color_scheme, SparseMatrix A0, float **rgb_r, float **rgb_g, float **rgb_b)
void plot_dot_map(Agraph_t *gr, SparseMatrix polys, SparseMatrix poly_lines, double line_width, const char *line_color, double *x_poly, int *polys_groups, float *r, float *g, float *b, const char *opacity, SparseMatrix A, FILE *f)
static void get_polygons(int n, int nrandom, int dim, int *grouping, int nt, struct Triangle *Tp, SparseMatrix E, int *nverts, double **x_poly, SparseMatrix *poly_lines, SparseMatrix *polys, int **polys_groups, SparseMatrix *poly_point_map, SparseMatrix *country_graph)
static void add_point(int *n, int igrp, double **x, int *nmax, double point[], int **groups)
static int same_edge(int ecur, int elast, int *edge_table)
int make_map_from_rectangle_groups(bool include_OK_points, int n, double *x, double *sizes, int *grouping, SparseMatrix graph, double bounding_box_margin, int nrandom, int *nart, int nedgep, double shore_depth_tol, int *nverts, double **x_poly, SparseMatrix *poly_lines, SparseMatrix *polys, int **polys_groups, SparseMatrix *poly_point_map, SparseMatrix *country_graph, int highlight_cluster)
static void get_boundingbox(int n, int dim, double *x, double *width, double *bbox)
static int get_tri(int n, int dim, double *x, int *nt, struct Triangle **T, SparseMatrix *E)
static SparseMatrix matrix_add_entry(SparseMatrix A, int i, int j, int val)
static void get_poly_lines(int nt, SparseMatrix E, size_t ncomps, int *comps_ptr, int *comps, int *groups, SparseMatrix *poly_lines, int **polys_groups)
void improve_contiguity(int n, int *grouping, SparseMatrix poly_point_map, double *x, SparseMatrix graph)
static void normal(double v[], double normal[])
static void cycle_print(int head, int *cycle, int *edge_table)
void map_optimal_coloring(int seed, SparseMatrix A, float *rgb_r, float *rgb_g, float *rgb_b)
static int get_poly_id(int ip, SparseMatrix point_poly_map)
static void plot_dot_polygons(agxbuf *sbuff, double line_width, const char *line_color, SparseMatrix polys, double *x_poly, int *polys_groups, float *r, float *g, float *b, const char *opacity)
static void conn_comp(int n, SparseMatrix A, int *groups, SparseMatrix *poly_point_map)
#define neighbor(t, i, edim, elist)
static boxf bbox(Ppoly_t **obsp, int npoly, int *np)
int node_distinct_coloring(const char *color_scheme, int *lightness, bool weightedQ, SparseMatrix A0, double accuracy, int seed, size_t *cdim0, double **colors)
int stress_model(SparseMatrix B, double *x, int maxit_sm)
static point center(point vertex[], size_t n)
abstraction for squashing compiler warnings for unused symbols