40 float **rgb_r,
float **rgb_g,
float **rgb_b){
52 double *colors =
NULL;
54 const size_t n = A0->
m;
57 bool weightedQ =
true;
69 int lightness[] = {0, 100};
73 const double accuracy = 0.01;
89 for (
size_t i = 0; i < n; i++){
90 (*rgb_r)[i + 1] = (float)colors[cdim * i];
91 (*rgb_g)[i + 1] = (float)colors[cdim * i + 1];
92 (*rgb_b)[i + 1] = (float)colors[cdim * i + 2];
99 const size_t n =
A->m;
103 rgb_r++; rgb_b++; rgb_g++;
105 for (
size_t i = 0; i < n; i++) rgb_r[i] = u[i];
107 for (
size_t i = 0; i < n; i++) rgb_g[i] = u[i];
109 for (
size_t i = 0; i < n; i++) rgb_b[i] = u[i];
115 return point_poly_map->
ja[point_poly_map->
ia[ip]];
126 int i, j, *ia, *ja, u, v;
134 assert(
graph->m == (
size_t)n);
135 ia =
D->ia; ja =
D->ja;
141 for (i = 0; i < n; i++){
143 for (j = ia[i]; j < ia[i+1]; j++){
146 if (grouping[u] != grouping[v]){
158 GV_INFO(
"ratio (edges among discontiguous regions vs total edges)=%f", (
double)nbad / ia[n]);
196 double xy[2], yz[2], nxy[2], nyz[2], ymx[2], ymz[2], beta, bot;
199 for (i = 0; i < 2; i++) ymx[i] = y[i] - x[i];
200 for (i = 0; i < 2; i++) ymz[i] = y[i] -
z[i];
201 for (i = 0; i < 2; i++) xy[i] = 0.5*(x[i] + y[i]);
202 for (i = 0; i < 2; i++) yz[i] = 0.5*(y[i] +
z[i]);
207 bot = nyz[0]*(x[0]-y[0])+nyz[1]*(x[1]-y[1]);
209 c[0] = xy[0]; c[1] = xy[1];
212 beta = ((x[0] - y[0])*(xy[0] - yz[0])+(x[1] - y[1])*(xy[1] - yz[1]))/bot;
213 c[0] = yz[0] + beta*nyz[0];
214 c[1] = yz[1] + beta*nyz[1];
228static void dot_polygon(
agxbuf *sbuff, doubles_t xp, doubles_t yp,
229 double line_width,
bool fill,
const char *cstring) {
236 strlen(cstring), cstring, strlen(cstring), cstring,
240 size_t len_swidth = (size_t)snprintf(
NULL, 0,
"%f", line_width);
242 " -setlinewidth(%f) L %" PRISIZE_T " ", strlen(cstring), cstring,
243 len_swidth + 14, line_width,
LIST_SIZE(&xp));
249 for (
size_t i = 0; i <
LIST_SIZE(&xp); i++) {
257 double *x_poly,
int *polys_groups,
float *r,
258 float *g,
float *b,
const char *opacity) {
259 int j, *ia = polys->
ia, *ja = polys->
ja, *a = polys->
a, nverts = polys->
n, ipoly,first;
260 const size_t npolys = polys->
m;
261 const bool fill =
false;
262 const bool use_line = line_width >= 0;
264 agxbuf cstring_buffer = {0};
265 const char *cstring =
"#aaaaaaff";
271 first = abs(a[0]); ipoly = first + 1;
272 for (
size_t i = 0; i < npolys; i++){
273 for (j = ia[i]; j < ia[i+1]; j++){
274 assert(ja[j] < nverts && ja[j] >= 0);
276 if (abs(a[j]) != ipoly){
279 rgb2hex(r[polys_groups[i]], g[polys_groups[i]], b[polys_groups[i]],
280 &cstring_buffer, opacity);
281 cstring =
agxbuse(&cstring_buffer);
283 dot_polygon(sbuff, xp, yp, line_width, fill, cstring);
292 dot_polygon(sbuff, xp, yp, line_width, fill, line_color);
295 dot_polygon(sbuff, xp, yp, -1,
true, cstring);
305 const char *line_color,
double *x_poly,
int *polys_groups,
306 float *r,
float *g,
float *b,
310 bool plot_polyQ =
true;
313 if (!r || !g || !b) plot_polyQ =
false;
331 if (line_width >= 0){
356 int i, j, i0, i1, i2, ntri;
360 if (trilist ==
NULL) {
367 for (i = 0; i < ntri; i++) {
368 for (j = 0; j < 3; j++) {
369 (*T)[i].vertices[j] = trilist[i * 3 + j];
371 i0 = (*T)[i].vertices[0]; i1 = (*T)[i].vertices[1]; i2 = (*T)[i].vertices[2];
394 int one = 1, jj, i, j, ig1, ig2;
399 for (i = 0; i < n; i++) {
400 max_grp =
MAX(groups[i], max_grp);
408 for (i = 0; i < n; i++){
411 for (j = ia[i]; j < ia[i+1]; j++){
413 if (i != jj && groups[i] != groups[jj] && groups[jj] !=
GRP_RANDOM && groups[jj] !=
GRP_BBOX){
414 ig1 = groups[i]-1; ig2 = groups[jj]-1;
427 int one = 1, jj, i, j;
435 for (i = 0; i < n; i++){
436 for (j = ia[i]; j < ia[i+1]; j++){
438 if (i != jj && groups[i] == groups[jj]){
450 free((*poly_point_map)->ia);
451 free((*poly_point_map)->ja);
452 (*poly_point_map)->ia = comps_ptr;
453 (*poly_point_map)->ja = comps;
454 (*poly_point_map)->nz = (size_t)n;
460 int **polys_groups) {
466 int i, *tlist, nz, ipoly, nnt, ii, jj, t1, t2, t, cur, next, nn, j, nlink, sta;
467 int *
elist, edim = 3;
470 int *ie =
E->ia, *je =
E->ja, *e =
E->a;
474 for (i = 0; i < nt; i++) mask[i] = -1;
479 *polys_groups =
gv_calloc(ncomps,
sizeof(
int));
481 for (i = 0; i < nt; i++)
elist[i*edim + 2] = 0;
482 nz = ie[
E->m] - ie[0];
486 for (i = 0; (size_t)i < ncomps; i++) {
488 for (j = comps_ptr[i]; j < comps_ptr[i+1]; j++){
491 (*polys_groups)[i] = groups[ii];
496 for (jj = ie[ii]; jj < ie[ii+1]; jj++){
497 if (groups[je[jj]] != groups[ii] && jj < nz - 1 && je[jj] == je[jj+1]){
501 nlink =
elist[t1*edim + 2]%2;
502 elist[t1*edim + nlink] = t2;
503 elist[t1*edim + 2]++;
505 nlink =
elist[t2*edim + 2]%2;
506 elist[t2*edim + nlink] = t1;
507 elist[t2*edim + 2]++;
509 tlist[nnt++] = t1; tlist[nnt++] = t2;
516 for (j = 0; j < nnt; j++){
519 cur = sta = t; mask[cur] = i;
558 fprintf(stderr,
"cycle (edges): {");
560 fprintf(stderr,
"%d,",cur);
563 fprintf(stderr,
"%d}\n",cur);
566 fprintf(stderr,
"cycle (vertices): ");
574static int same_edge(
int ecur,
int elast,
int *edge_table){
596 int *ie =
E->
ia, *je =
E->ja, *e =
E->a, ne, j, t1, t2, jj, ii;
597 const size_t n =
E->m;
598 int *cycle, cycle_head = 0;
601 int *edge_cycle_map, NOT_ON_CYCLE = -1;
603 enum {NO_DUPLICATE = -1};
604 int *
elist, edim = 3;
608 int k, duplicate, ee = 0, ecur, enext, eprev, cur, next, nn, nlink,
head, elast = 0, etail, tail, ehead, efirst;
613 edge_table =
gv_calloc(
E->nz * 2,
sizeof(
int));
618 for (
size_t i = 0; i < n; i++){
619 for (j = ie[i]; j < ie[i+1]; j++){
620 if (j < ie[n] - ie[0] - 1 && (
int)i > je[j] && je[j] == je[j+1]){
625 edge_table[ne*2] = t1;
626 edge_table[ne*2+1] = t2;
631 edge_table[ne*2] = t2;
632 edge_table[ne*2+1] = t1;
642 assert(
E->nz >= (
size_t)ne);
648 edge_cycle_map =
gv_calloc(ne,
sizeof(
int));
650 for (
int i = 0; i < ne; i++) edge_cycle_map[i] = NOT_ON_CYCLE;
651 for (
int i = 0; i < ne; i++) emask[i] = -1;
657 for (
int i = 0; i < nt; i++)
elist[i*edim + 2] = 0;
661 for (
int i = 0; (size_t)i < ncomps; i++){
662 if (DEBUG_CYCLE) fprintf(stderr,
"\n ============ comp %d has %d members\n",i, comps_ptr[i+1]-comps_ptr[i]);
663 for (k = comps_ptr[i]; k < comps_ptr[i+1]; k++){
665 duplicate = NO_DUPLICATE;
666 if (DEBUG_CYCLE) fprintf(stderr,
"member = %d has %d neighbors\n",ii, ie[ii+1]-ie[ii]);
667 for (j = ie[ii]; j < ie[ii+1]; j++){
671 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));
672 nlink =
elist[t1*edim + 2]%2;
673 elist[t1*edim + nlink] = ee;
674 elist[t1*edim + 2]++;
676 if (edge_cycle_map[ee] != NOT_ON_CYCLE) duplicate = ee;
680 if (duplicate == NO_DUPLICATE){
686 edge_cycle_map[ecur] = 1;
689 if (DEBUG_CYCLE) fprintf(stderr,
"NEW CYCLE\n starting with edge %d, {head,tail}={%d,%d}\n", ee,
head, next);
690 while (next !=
head){
696 if (DEBUG_CYCLE) fprintf(stderr,
"cur edge = %d, next edge %d, {head,tail}={%d,%d},\n",ecur, enext,
edge_head(enext),
edge_tail(enext));
703 edge_cycle_map[enext] = 1;
709 if (DEBUG_CYCLE)
cycle_print(ee, cycle,edge_table);
713 ecur = ee = duplicate;
714 while (emask[ecur] == ii){
721 if (DEBUG_CYCLE) fprintf(stderr,
" duplicating edge = %d, starting from the a non-duplicating edge %d, search backwards\n",ee, ecur);
725 while (emask[ecur] == ii){
726 if (DEBUG_CYCLE) fprintf(stderr,
" remove edge %d (%d--%d)\n",ecur,
edge_head(ecur),
edge_tail(ecur));
728 edge_cycle_map[ecur] = NOT_ON_CYCLE;
740 fprintf(stderr,
"remaining (broken) cycle = ");
760 if (DEBUG_CYCLE) fprintf(stderr,
"forwarding now from edge %d = {%d, %d}, try to reach vtx %d, first edge from voro = %d\n",
768 if (
same_edge(ecur, efirst, edge_table)){
769 if (DEBUG_CYCLE) fprintf(stderr,
"this voro cell fill in a hole completely!!!!\n");
772 edge_cycle_map[ecur] = 1;
775 if (DEBUG_CYCLE) fprintf(stderr,
"starting with edge %d, {head,tail}={%d,%d}\n", ecur,
head, next);
776 while (next != tail){
782 if (DEBUG_CYCLE) fprintf(stderr,
"cur edge = %d, next edge %d, {head,tail}={%d,%d},\n",ecur, enext,
edge_head(enext),
edge_tail(enext));
791 edge_cycle_map[enext] = 1;
804 while ((enext =
cycle_next(ecur)) != cycle_head){
805 edge_cycle_map[ecur] = NOT_ON_CYCLE;
810 edge_cycle_map[ecur] = NOT_ON_CYCLE;
825 free(edge_cycle_map);
839 int *comps =
NULL, *comps_ptr =
NULL;
844 groups =
gv_calloc(n + nrandom,
sizeof(
int));
845 for (
int i = 0; i < n; i++) {
846 groups[i] = grouping[i];
849 for (
int i = n; i < n + nrandom - 4; i++) {
852 for (
int i = n + nrandom - 4; i < n + nrandom; i++) {
857 conn_comp(n + nrandom,
E, groups, poly_point_map);
859 size_t ncomps = (*poly_point_map)->m;
860 comps = (*poly_point_map)->ja;
861 comps_ptr = (*poly_point_map)->ia;
865 for (; ncomps > 0; ncomps--) {
866 if (groups[comps[comps_ptr[ncomps - 1]]] !=
GRP_RANDOM &&
867 groups[comps[comps_ptr[ncomps - 1]]] !=
GRP_BBOX)
break;
872 for (
int i2 = 0; i2 < nt; i2++){
873 for (j = 0; j <
dim; j++){
900 double bounding_box_margin,
int nrandom,
901 int nedgep,
double shore_depth_tol,
int *nverts,
908 double xmax[2],
xmin[2], area, *x = x0;
911 int dim2 = 2, nn = 0;
912 int max_qtree_level = 10;
914 int imin, nzok = 0, nzok0 = 0, nt;
915 double *xran,
point[2];
919 bool INCLUDE_OK_POINTS = include_OK_points;
921 int *grouping = grouping0;
923 int HIGHLIGHT_SET = highlight_cluster;
925 for (j = 0; j < dim2; j++) {
930 for (
int i = 0; i < n; i++){
931 for (j = 0; j < dim2; j++) {
938 area = boxsize[0]*boxsize[1];
942 }
else if (nrandom < 0){
943 nrandom = -nrandom * n;
944 }
else if (nrandom < 4) {
950 if (shore_depth_tol < 0) shore_depth_tol = sqrt(area/(
double) n);
951 GV_INFO(
"nrandom=%d shore_depth_tol=%.08f", nrandom, shore_depth_tol);
961 fprintf(stderr,
"add art np = %d\n",np);
962 assert(
graph->nz <= INT_MAX);
965 for (
int i = 0; i < n*
dim; i++) y[i] = x[i];
966 grouping =
gv_calloc(n + nz * np,
sizeof(
int));
967 for (
int i = 0; i < n; i++) grouping[i] = grouping0[i];
969 for (
size_t i = 0; i <
graph->m; i++){
971 for (j =
graph->ia[i]; j <
graph->ia[i+1]; j++){
972 if (!HIGHLIGHT_SET || (grouping[i] == grouping[
graph->ja[j]] && grouping[i] == HIGHLIGHT_SET)){
973 for (t = 0; t < np; t++){
974 for (k = 0; k <
dim; k++){
975 y[nz*
dim+k] = t/((double) np)*x[(int)i*
dim+k] + (1-t/((
double) np))*x[(
graph->ja[j])*
dim + k];
977 assert(n + (nz-n)*np + t < n + nz*np && n + (nz-n)*np + t >= 0);
978 if (t/((
double) np) > 0.5){
979 grouping[nz] = grouping[i];
981 grouping[nz] = grouping[
graph->ja[j]];
988 fprintf(stderr,
"after adding edge points, n:%d->%d\n",n, nz);
999 for (
int i = 0; i < dim2; i++) {
1000 if (bounding_box_margin > 0){
1001 xmin[i] -= bounding_box_margin;
1002 xmax[i] += bounding_box_margin;
1003 }
else if (bounding_box_margin < 0) {
1004 xmin[i] -= boxsize[i]*(-bounding_box_margin);
1005 xmax[i] += boxsize[i]*(-bounding_box_margin);
1007 xmin[i] -= fmax(boxsize[i] * 0.2, 2.* shore_depth_tol);
1008 xmax[i] += fmax(boxsize[i] * 0.2, 2 * shore_depth_tol);
1012 double bbm = bounding_box_margin;
1014 fprintf (stderr,
"bounding box margin: %.06f", bbm);
1016 fprintf (stderr,
"bounding box margin: (%.06f * %.06f)", boxsize[0], -bbm);
1018 fprintf(stderr,
"bounding box margin: %.06f",
1019 fmax(boxsize[0] * 0.2, 2 * shore_depth_tol));
1023 const double n1 = floor(
area2 / (shore_depth_tol * shore_depth_tol));
1024 const double n2 = n * floor(
area2 / area);
1025 nrandom = fmax(n1, n2);
1028 xran =
gv_calloc((nrandom + 4) * dim2,
sizeof(
double));
1030 if (INCLUDE_OK_POINTS){
1031 nzok0 = nzok = nrandom - 1;
1032 if (grouping == grouping0) {
1033 int *grouping2 =
gv_calloc(n + nrandom,
sizeof(
int));
1034 memcpy(grouping2, grouping,
sizeof(
int)*n);
1035 grouping = grouping2;
1037 grouping =
gv_recalloc(grouping, n, n + nrandom,
sizeof(
int));
1042 for (
int i = 0; i < nrandom; i++){
1044 for (j = 0; j < dim2; j++){
1050 if (min > shore_depth_tol){
1051 for (j = 0; j < dim2; j++){
1052 xran[nz*dim2+j] =
point[j];
1055 }
else if (INCLUDE_OK_POINTS && min > shore_depth_tol/10){
1056 for (j = 0; j < dim2; j++){
1057 xran[nzok*dim2+j] =
point[j];
1059 grouping[nn++] = grouping[
imin];
1066 if (
Verbose) fprintf(stderr,
"nn nrandom=%d\n", nrandom);
1068 xran =
gv_calloc(4 * dim2,
sizeof(
double));
1074 for (
int i = 0; i < dim2; i++)
xmin[i] -= 0.2*(
xmax[i]-
xmin[i]);
1075 for (
int i = 0; i < dim2; i++)
xmax[i] += 0.2*(
xmax[i]-
xmin[i]);
1077 for (j = 0; j < dim2; j++) xran[i*dim2+j] =
xmin[j];
1079 for (j = 0; j < dim2; j++) xran[i*dim2+j] =
xmax[j];
1081 xran[i*dim2] =
xmin[0]; xran[i*dim2+1] =
xmax[1];
1083 xran[i*dim2] =
xmax[0]; xran[i*dim2+1] =
xmin[1];
1088 if (INCLUDE_OK_POINTS){
1089 xcombined =
gv_calloc((nn + nrandom) * dim2,
sizeof(
double));
1091 xcombined =
gv_calloc((n + nrandom) * dim2,
sizeof(
double));
1093 for (i = 0; i < n; i++) {
1094 for (j = 0; j < dim2; j++) xcombined[i*dim2+j] = x[i*
dim+j];
1096 for (i = 0; i < nrandom; i++) {
1097 for (j = 0; j < dim2; j++) xcombined[(i + nn)*dim2+j] = xran[i*
dim+j];
1100 if (INCLUDE_OK_POINTS){
1101 for (i = 0; i < nn - n; i++) {
1102 for (j = 0; j < dim2; j++) xcombined[(i + n)*dim2+j] = xran[(nzok0 - i)*
dim+j];
1111 if (
Verbose) fprintf(stderr,
" highlight cluster %d, n = %d\n",HIGHLIGHT_SET, n);
1114 for (i = 0; i < n; i++){
1115 if (grouping[i] == HIGHLIGHT_SET){
1117 for (j = 0; j <
dim; j++){
1118 xcombined[nz++] = x[i*
dim+j];
1122 for (i = 0; i < n; i++){
1123 if (grouping[i] != HIGHLIGHT_SET){
1124 for (j = 0; j <
dim; j++){
1125 xcombined[nz++] = x[i*
dim+j];
1129 assert(nz == n*
dim);
1130 for (i = 0; i < nh; i++){
1133 for (i = nh; i < n; i++){
1138 if (
Verbose) fprintf(stderr,
"nh = %d\n",nh);
1143 if (
get_tri(n + nrandom, dim2, xcombined, &nt, &Tp, &
E) != 0) {
1147 get_polygons(n, nrandom, dim2, grouping, nt, Tp,
E, nverts, x_poly,
1148 poly_lines, polys, polys_groups, poly_point_map, country_graph);
1155 if (grouping != grouping0)
free(grouping);
1157 if (x != x0)
free(x);
1161static void add_point(
int *n,
int igrp,
double **x,
int *nmax,
double point[],
int **groups){
1164 int old_nmax = *nmax;
1166 *x =
gv_recalloc(*x, 2 * old_nmax, 2 * *nmax,
sizeof(
double));
1167 *groups =
gv_recalloc(*groups, old_nmax, *nmax,
sizeof(
int));
1170 (*x)[(*n)*2] =
point[0];
1171 (*x)[(*n)*2+1] =
point[1];
1172 (*groups)[*n] = igrp;
1181 for (i = 0; i < n; i++){
1190 int n,
double *x,
double *sizes,
1191 int *grouping,
SparseMatrix graph,
double bounding_box_margin,
int nrandom,
int *nart,
int nedgep,
1192 double shore_depth_tol,
1193 int *nverts,
double **x_poly,
1254 int N, nmax, i, j, igrp;
1258 double avgsize[2], avgsz, h[2], p1, p0;
1263 K = round(10 / (1 + n / 400.0));
1267 int maxgp = grouping[0];
1268 int mingp = grouping[0];
1269 for (i = 0; i < n; i++) {
1270 maxgp =
MAX(maxgp, grouping[i]);
1271 mingp =
MIN(mingp, grouping[i]);
1273 fprintf(stderr,
"max grouping - min grouping + 1 = %d\n",maxgp - mingp + 1);
1279 bounding_box_margin, nrandom, nedgep,
1280 shore_depth_tol, nverts, x_poly, poly_lines, polys,
1281 polys_groups, poly_point_map, country_graph,
1288 for (i = 0; i < n; i++){
1289 for (j = 0; j < 2; j++) {
1290 avgsize[j] += sizes[i*
dim+j];
1293 for (i = 0; i < 2; i++) avgsize[i] /= n;
1294 avgsz = 0.5*(avgsize[0] + avgsize[1]);
1295 GV_INFO(
"avgsize = {%f, %f}", avgsize[0], avgsize[1]);
1299 groups =
gv_calloc(n + nmax,
sizeof(
int));
1300 for (i = 0; i < n; i++) {
1301 groups[i] = grouping[i];
1302 for (j = 0; j < 2; j++){
1303 X[i*2+j] = x[i*
dim+j];
1308 if (shore_depth_tol < 0) {
1309 shore_depth_tol = -(shore_depth_tol)*avgsz;
1310 }
else if (shore_depth_tol == 0){
1313 shore_depth_tol = sqrt(area / n);
1314 GV_INFO(
"setting shore length ======%f", shore_depth_tol);
1319 double delta[2] = {0};
1321 delta[0] = .5*avgsize[0]/K;
delta[1] = .5*avgsize[1]/K;
1323 for (i = 0; i < n; i++){
1325 double nadded[2] = {0};
1326 for (j = 0; j < 2; j++) {
1328 nadded[j] = round(K * sizes[i *
dim + j] / avgsz);
1334 h[0] = sizes[i*
dim]/nadded[0];
1338 for (
double k = 0; k < nadded[0] - 1; k++){
1348 for (
double k = 0; k < nadded[0] - 1; k++){
1357 h[1] = sizes[i*
dim + 1]/nadded[1];
1361 for (
double k = 0; k < nadded[1] - 1; k++){
1371 for (
double k = 0; k < nadded[1] - 1; k++){
1382 bounding_box_margin, nrandom, nedgep,
1383 shore_depth_tol, nverts, x_poly, poly_lines, polys,
1384 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)
PATHUTIL_API COORD area2(Ppoint_t, Ppoint_t, Ppoint_t)
int stress_model(SparseMatrix B, double *x, int maxit_sm)
static point center(point vertex[], size_t n)