| 1 |
/// @file |
| 2 |
/// @brief [node shapes](https://graphviz.org/doc/info/shapes.html) |
| 3 |
/// @ingroup common_render |
| 4 |
/************************************************************************* |
| 5 |
* Copyright (c) 2011 AT&T Intellectual Property |
| 6 |
* All rights reserved. This program and the accompanying materials |
| 7 |
* are made available under the terms of the Eclipse Public License v1.0 |
| 8 |
* which accompanies this distribution, and is available at |
| 9 |
* https://www.eclipse.org/legal/epl-v10.html |
| 10 |
* |
| 11 |
* Contributors: Details at https://graphviz.org |
| 12 |
*************************************************************************/ |
| 13 |
|
| 14 |
#include "config.h" |
| 15 |
|
| 16 |
#include <assert.h> |
| 17 |
#include <common/render.h> |
| 18 |
#include <common/htmltable.h> |
| 19 |
#include <float.h> |
| 20 |
#include <limits.h> |
| 21 |
#include <math.h> |
| 22 |
#include <stddef.h> |
| 23 |
#include <stdbool.h> |
| 24 |
#include <string.h> |
| 25 |
#include <util/alloc.h> |
| 26 |
#include <util/gv_math.h> |
| 27 |
#include <util/streq.h> |
| 28 |
#include <util/unreachable.h> |
| 29 |
|
| 30 |
#define RBCONST 12 |
| 31 |
#define RBCURVE .5 |
| 32 |
|
| 33 |
typedef struct { |
| 34 |
pointf (*size_gen) (pointf); |
| 35 |
void (*vertex_gen) (pointf*, pointf*); |
| 36 |
} poly_desc_t; |
| 37 |
|
| 38 |
static port Center = {.theta = -1, .clip = true}; |
| 39 |
|
| 40 |
#define ATTR_SET(a,n) ((a) && (*(agxget(n,a->index)) != '\0')) |
| 41 |
/* Default point size = 0.05 inches or 3.6 points */ |
| 42 |
#define DEF_POINT 0.05 |
| 43 |
/* Minimum point size = 0.0003 inches or 0.02 points |
| 44 |
* This will make the radius 0.01 points, which is the smallest |
| 45 |
* non-zero number output by gvprintdouble in gvdevice.c |
| 46 |
*/ |
| 47 |
#define MIN_POINT 0.0003 |
| 48 |
/* extra null character needed to avoid style emitter from thinking |
| 49 |
* there are arguments. |
| 50 |
*/ |
| 51 |
static char *point_style[3] = { "invis\0", "filled\0", 0 }; |
| 52 |
|
| 53 |
/* forward declarations of functions used in shapes tables */ |
| 54 |
|
| 55 |
static void poly_init(node_t * n); |
| 56 |
static void poly_free(node_t * n); |
| 57 |
static port poly_port(node_t * n, char *portname, char *); |
| 58 |
static bool poly_inside(inside_t * inside_context, pointf p); |
| 59 |
static int poly_path(node_t * n, port * p, int side, boxf rv[], int *kptr); |
| 60 |
static void poly_gencode(GVJ_t * job, node_t * n); |
| 61 |
|
| 62 |
static void record_init(node_t * n); |
| 63 |
static void record_free(node_t * n); |
| 64 |
static port record_port(node_t * n, char *portname, char *); |
| 65 |
static bool record_inside(inside_t * inside_context, pointf p); |
| 66 |
static int record_path(node_t * n, port * p, int side, boxf rv[], |
| 67 |
int *kptr); |
| 68 |
static void record_gencode(GVJ_t * job, node_t * n); |
| 69 |
|
| 70 |
static void point_init(node_t * n); |
| 71 |
static void point_gencode(GVJ_t * job, node_t * n); |
| 72 |
static bool point_inside(inside_t * inside_context, pointf p); |
| 73 |
|
| 74 |
static bool epsf_inside(inside_t * inside_context, pointf p); |
| 75 |
static void epsf_gencode(GVJ_t * job, node_t * n); |
| 76 |
|
| 77 |
static pointf star_size (pointf); |
| 78 |
static void star_vertices (pointf*, pointf*); |
| 79 |
static bool star_inside(inside_t * inside_context, pointf p); |
| 80 |
static poly_desc_t star_gen = { |
| 81 |
star_size, |
| 82 |
star_vertices, |
| 83 |
}; |
| 84 |
|
| 85 |
static pointf cylinder_size (pointf); |
| 86 |
static void cylinder_vertices (pointf*, pointf*); |
| 87 |
static void cylinder_draw(GVJ_t *job, pointf *AF, size_t sides, int filled); |
| 88 |
static poly_desc_t cylinder_gen = { |
| 89 |
cylinder_size, |
| 90 |
cylinder_vertices, |
| 91 |
}; |
| 92 |
|
| 93 |
/* polygon descriptions. "polygon" with 0 sides takes all user control */ |
| 94 |
|
| 95 |
/* regul perip sides orien disto skew */ |
| 96 |
static polygon_t p_polygon = {.peripheries = 1}; |
| 97 |
|
| 98 |
/* builtin polygon descriptions */ |
| 99 |
static polygon_t p_ellipse = {.peripheries = 1, .sides = 1}; |
| 100 |
static polygon_t p_circle = {.regular = true, .peripheries = 1, .sides = 1}; |
| 101 |
static polygon_t p_egg = {.peripheries = 1, .sides = 1, .distortion = -0.3}; |
| 102 |
static polygon_t p_triangle = {.peripheries = 1, .sides = 3}; |
| 103 |
static polygon_t p_box = {.peripheries = 1, .sides = 4}; |
| 104 |
static polygon_t p_square = {.regular = true, .peripheries = 1, .sides = 4}; |
| 105 |
static polygon_t p_plaintext = {.sides = 4}; |
| 106 |
static polygon_t p_plain = {.sides = 4}; |
| 107 |
static polygon_t p_diamond = {.peripheries = 1, .sides = 4, .orientation = 45.0}; |
| 108 |
static polygon_t p_trapezium = {.peripheries = 1, .sides = 4, .distortion = -0.4}; |
| 109 |
static polygon_t p_parallelogram = {.peripheries = 1, .sides = 4, .skew = 0.6}; |
| 110 |
static polygon_t p_house = {.peripheries = 1, .sides = 5, .distortion = -0.64}; |
| 111 |
static polygon_t p_pentagon = {.peripheries = 1, .sides = 5}; |
| 112 |
static polygon_t p_hexagon = {.peripheries = 1, .sides = 6}; |
| 113 |
static polygon_t p_septagon = {.peripheries = 1, .sides = 7}; |
| 114 |
static polygon_t p_octagon = {.peripheries = 1, .sides = 8}; |
| 115 |
static polygon_t p_note = { |
| 116 |
.peripheries = 1, .sides = 4, .option = {.shape = DOGEAR}}; |
| 117 |
static polygon_t p_tab = { |
| 118 |
.peripheries = 1, .sides = 4, .option = {.shape = TAB}}; |
| 119 |
static polygon_t p_folder = { |
| 120 |
.peripheries = 1, .sides = 4, .option = {.shape = FOLDER}}; |
| 121 |
static polygon_t p_box3d = { |
| 122 |
.peripheries = 1, .sides = 4, .option = {.shape = BOX3D}}; |
| 123 |
static polygon_t p_component = { |
| 124 |
.peripheries = 1, .sides = 4, .option = {.shape = COMPONENT}}; |
| 125 |
static polygon_t p_underline = { |
| 126 |
.peripheries = 1, .sides = 4, .option = {.underline = true}}; |
| 127 |
static polygon_t p_cylinder = {.peripheries = 1, |
| 128 |
.sides = 19, |
| 129 |
.option = {.shape = CYLINDER}, |
| 130 |
.vertices = (pointf *)&cylinder_gen}; |
| 131 |
|
| 132 |
/* redundant and undocumented builtin polygons */ |
| 133 |
static polygon_t p_doublecircle = { |
| 134 |
.regular = true, .peripheries = 2, .sides = 1}; |
| 135 |
static polygon_t p_invtriangle = { |
| 136 |
.peripheries = 1, .sides = 3, .orientation = 180.0}; |
| 137 |
static polygon_t p_invtrapezium = { |
| 138 |
.peripheries = 1, .sides = 4, .orientation = 180.0, .distortion = -0.4}; |
| 139 |
static polygon_t p_invhouse = { |
| 140 |
.peripheries = 1, .sides = 5, .orientation = 180.0, .distortion = -0.64}; |
| 141 |
static polygon_t p_doubleoctagon = {.peripheries = 2, .sides = 8}; |
| 142 |
static polygon_t p_tripleoctagon = {.peripheries = 3, .sides = 8}; |
| 143 |
static polygon_t p_Mdiamond = { |
| 144 |
.peripheries = 1, |
| 145 |
.sides = 4, |
| 146 |
.orientation = 45.0, |
| 147 |
.option = {.diagonals = true, .auxlabels = true}}; |
| 148 |
static polygon_t p_Msquare = {.regular = true, |
| 149 |
.peripheries = 1, |
| 150 |
.sides = 4, |
| 151 |
.option = {.diagonals = true}}; |
| 152 |
static polygon_t p_Mcircle = {.regular = true, |
| 153 |
.peripheries = 1, |
| 154 |
.sides = 1, |
| 155 |
.option = {.diagonals = true, .auxlabels = true}}; |
| 156 |
|
| 157 |
/* non-convex polygons */ |
| 158 |
static polygon_t p_star = { |
| 159 |
.peripheries = 1, .sides = 10, .vertices = (pointf *)&star_gen}; |
| 160 |
|
| 161 |
/* biological circuit shapes, as specified by SBOLv*/ |
| 162 |
/** gene expression symbols **/ |
| 163 |
static polygon_t p_promoter = { |
| 164 |
.peripheries = 1, .sides = 4, .option = {.shape = PROMOTER}}; |
| 165 |
static polygon_t p_cds = { |
| 166 |
.peripheries = 1, .sides = 4, .option = {.shape = CDS}}; |
| 167 |
static polygon_t p_terminator = { |
| 168 |
.peripheries = 1, .sides = 4, .option = {.shape = TERMINATOR}}; |
| 169 |
static polygon_t p_utr = { |
| 170 |
.peripheries = 1, .sides = 4, .option = {.shape = UTR}}; |
| 171 |
static polygon_t p_insulator = { |
| 172 |
.peripheries = 1, .sides = 4, .option = {.shape = INSULATOR}}; |
| 173 |
static polygon_t p_ribosite = { |
| 174 |
.peripheries = 1, .sides = 4, .option = {.shape = RIBOSITE}}; |
| 175 |
static polygon_t p_rnastab = { |
| 176 |
.peripheries = 1, .sides = 4, .option = {.shape = RNASTAB}}; |
| 177 |
static polygon_t p_proteasesite = { |
| 178 |
.peripheries = 1, .sides = 4, .option = {.shape = PROTEASESITE}}; |
| 179 |
static polygon_t p_proteinstab = { |
| 180 |
.peripheries = 1, .sides = 4, .option = {.shape = PROTEINSTAB}}; |
| 181 |
/** dna construction symbols **/ |
| 182 |
static polygon_t p_primersite = { |
| 183 |
.peripheries = 1, .sides = 4, .option = {.shape = PRIMERSITE}}; |
| 184 |
static polygon_t p_restrictionsite = { |
| 185 |
.peripheries = 1, .sides = 4, .option = {.shape = RESTRICTIONSITE}}; |
| 186 |
static polygon_t p_fivepoverhang = { |
| 187 |
.peripheries = 1, .sides = 4, .option = {.shape = FIVEPOVERHANG}}; |
| 188 |
static polygon_t p_threepoverhang = { |
| 189 |
.peripheries = 1, .sides = 4, .option = {.shape = THREEPOVERHANG}}; |
| 190 |
static polygon_t p_noverhang = { |
| 191 |
.peripheries = 1, .sides = 4, .option = {.shape = NOVERHANG}}; |
| 192 |
static polygon_t p_assembly = { |
| 193 |
.peripheries = 1, .sides = 4, .option = {.shape = ASSEMBLY}}; |
| 194 |
static polygon_t p_signature = { |
| 195 |
.peripheries = 1, .sides = 4, .option = {.shape = SIGNATURE}}; |
| 196 |
static polygon_t p_rpromoter = { |
| 197 |
.peripheries = 1, .sides = 4, .option = {.shape = RPROMOTER}}; |
| 198 |
static polygon_t p_rarrow = { |
| 199 |
.peripheries = 1, .sides = 4, .option = {.shape = RARROW}}; |
| 200 |
static polygon_t p_larrow = { |
| 201 |
.peripheries = 1, .sides = 4, .option = {.shape = LARROW}}; |
| 202 |
static polygon_t p_lpromoter = { |
| 203 |
.peripheries = 1, .sides = 4, .option = {.shape = LPROMOTER}}; |
| 204 |
|
| 205 |
static bool IS_BOX(node_t *n) { |
| 206 |
return ND_shape(n)->polygon == &p_box; |
| 207 |
} |
| 208 |
|
| 209 |
static bool IS_PLAIN(node_t *n) { |
| 210 |
return ND_shape(n)->polygon == &p_plain; |
| 211 |
} |
| 212 |
|
| 213 |
/// True if style requires processing through round_corners. |
| 214 |
static bool SPECIAL_CORNERS(graphviz_polygon_style_t style) { |
| 215 |
return style.rounded || style.diagonals || style.shape != 0; |
| 216 |
} |
| 217 |
|
| 218 |
/* |
| 219 |
* every shape has these functions: |
| 220 |
* |
| 221 |
* void SHAPE_init(node_t *n) |
| 222 |
* initialize the shape (usually at least its size). |
| 223 |
* void SHAPE_free(node_t *n) |
| 224 |
* free all memory used by the shape |
| 225 |
* port SHAPE_port(node_t *n, char *portname) |
| 226 |
* return the aiming point and slope (if constrained) |
| 227 |
* of a port. |
| 228 |
* int SHAPE_inside(inside_t *inside_context, pointf p, edge_t *e); |
| 229 |
* test if point is inside the node shape which is |
| 230 |
* assumed convex. |
| 231 |
* the point is relative to the node center. the edge |
| 232 |
* is passed in case the port affects spline clipping. |
| 233 |
* int SHAPE_path(node *n, edge_t *e, int pt, boxf path[], int *nbox) |
| 234 |
* create a path for the port of e that touches n, |
| 235 |
* return side |
| 236 |
* void SHAPE_gencode(GVJ_t *job, node_t *n) |
| 237 |
* generate graphics code for a node. |
| 238 |
* |
| 239 |
* some shapes, polygons in particular, use additional shape control data * |
| 240 |
* |
| 241 |
*/ |
| 242 |
|
| 243 |
static shape_functions poly_fns = { |
| 244 |
poly_init, |
| 245 |
poly_free, |
| 246 |
poly_port, |
| 247 |
poly_inside, |
| 248 |
poly_path, |
| 249 |
poly_gencode |
| 250 |
}; |
| 251 |
static shape_functions point_fns = { |
| 252 |
point_init, |
| 253 |
poly_free, |
| 254 |
poly_port, |
| 255 |
point_inside, |
| 256 |
NULL, |
| 257 |
point_gencode |
| 258 |
}; |
| 259 |
static shape_functions record_fns = { |
| 260 |
record_init, |
| 261 |
record_free, |
| 262 |
record_port, |
| 263 |
record_inside, |
| 264 |
record_path, |
| 265 |
record_gencode |
| 266 |
}; |
| 267 |
static shape_functions epsf_fns = { |
| 268 |
epsf_init, |
| 269 |
epsf_free, |
| 270 |
poly_port, |
| 271 |
epsf_inside, |
| 272 |
NULL, |
| 273 |
epsf_gencode |
| 274 |
}; |
| 275 |
static shape_functions star_fns = { |
| 276 |
poly_init, |
| 277 |
poly_free, |
| 278 |
poly_port, |
| 279 |
star_inside, |
| 280 |
poly_path, |
| 281 |
poly_gencode |
| 282 |
}; |
| 283 |
static shape_functions cylinder_fns = { |
| 284 |
poly_init, |
| 285 |
poly_free, |
| 286 |
poly_port, |
| 287 |
poly_inside, |
| 288 |
poly_path, |
| 289 |
poly_gencode |
| 290 |
}; |
| 291 |
|
| 292 |
static shape_desc Shapes[] = { /* first entry is default for no such shape */ |
| 293 |
{.name = "box", .fns = &poly_fns, .polygon = &p_box}, |
| 294 |
{.name = "polygon", .fns = &poly_fns, .polygon = &p_polygon}, |
| 295 |
{.name = "ellipse", .fns = &poly_fns, .polygon = &p_ellipse}, |
| 296 |
{.name = "oval", .fns = &poly_fns, .polygon = &p_ellipse}, |
| 297 |
{.name = "circle", .fns = &poly_fns, .polygon = &p_circle}, |
| 298 |
{.name = "point", .fns = &point_fns, .polygon = &p_circle}, |
| 299 |
{.name = "egg", .fns = &poly_fns, .polygon = &p_egg}, |
| 300 |
{.name = "triangle", .fns = &poly_fns, .polygon = &p_triangle}, |
| 301 |
{.name = "none", .fns = &poly_fns, .polygon = &p_plaintext}, |
| 302 |
{.name = "plaintext", .fns = &poly_fns, .polygon = &p_plaintext}, |
| 303 |
{.name = "plain", .fns = &poly_fns, .polygon = &p_plain}, |
| 304 |
{.name = "diamond", .fns = &poly_fns, .polygon = &p_diamond}, |
| 305 |
{.name = "trapezium", .fns = &poly_fns, .polygon = &p_trapezium}, |
| 306 |
{.name = "parallelogram", .fns = &poly_fns, .polygon = &p_parallelogram}, |
| 307 |
{.name = "house", .fns = &poly_fns, .polygon = &p_house}, |
| 308 |
{.name = "pentagon", .fns = &poly_fns, .polygon = &p_pentagon}, |
| 309 |
{.name = "hexagon", .fns = &poly_fns, .polygon = &p_hexagon}, |
| 310 |
{.name = "septagon", .fns = &poly_fns, .polygon = &p_septagon}, |
| 311 |
{.name = "octagon", .fns = &poly_fns, .polygon = &p_octagon}, |
| 312 |
{.name = "note", .fns = &poly_fns, .polygon = &p_note}, |
| 313 |
{.name = "tab", .fns = &poly_fns, .polygon = &p_tab}, |
| 314 |
{.name = "folder", .fns = &poly_fns, .polygon = &p_folder}, |
| 315 |
{.name = "box3d", .fns = &poly_fns, .polygon = &p_box3d}, |
| 316 |
{.name = "component", .fns = &poly_fns, .polygon = &p_component}, |
| 317 |
{.name = "cylinder", .fns = &cylinder_fns, .polygon = &p_cylinder}, |
| 318 |
{.name = "rect", .fns = &poly_fns, .polygon = &p_box}, |
| 319 |
{.name = "rectangle", .fns = &poly_fns, .polygon = &p_box}, |
| 320 |
{.name = "square", .fns = &poly_fns, .polygon = &p_square}, |
| 321 |
{.name = "doublecircle", .fns = &poly_fns, .polygon = &p_doublecircle}, |
| 322 |
{.name = "doubleoctagon", .fns = &poly_fns, .polygon = &p_doubleoctagon}, |
| 323 |
{.name = "tripleoctagon", .fns = &poly_fns, .polygon = &p_tripleoctagon}, |
| 324 |
{.name = "invtriangle", .fns = &poly_fns, .polygon = &p_invtriangle}, |
| 325 |
{.name = "invtrapezium", .fns = &poly_fns, .polygon = &p_invtrapezium}, |
| 326 |
{.name = "invhouse", .fns = &poly_fns, .polygon = &p_invhouse}, |
| 327 |
{.name = "underline", .fns = &poly_fns, .polygon = &p_underline}, |
| 328 |
{.name = "Mdiamond", .fns = &poly_fns, .polygon = &p_Mdiamond}, |
| 329 |
{.name = "Msquare", .fns = &poly_fns, .polygon = &p_Msquare}, |
| 330 |
{.name = "Mcircle", .fns = &poly_fns, .polygon = &p_Mcircle}, |
| 331 |
/* biological circuit shapes, as specified by SBOLv*/ |
| 332 |
/** gene expression symbols **/ |
| 333 |
{.name = "promoter", .fns = &poly_fns, .polygon = &p_promoter}, |
| 334 |
{.name = "cds", .fns = &poly_fns, .polygon = &p_cds}, |
| 335 |
{.name = "terminator", .fns = &poly_fns, .polygon = &p_terminator}, |
| 336 |
{.name = "utr", .fns = &poly_fns, .polygon = &p_utr}, |
| 337 |
{.name = "insulator", .fns = &poly_fns, .polygon = &p_insulator}, |
| 338 |
{.name = "ribosite", .fns = &poly_fns, .polygon = &p_ribosite}, |
| 339 |
{.name = "rnastab", .fns = &poly_fns, .polygon = &p_rnastab}, |
| 340 |
{.name = "proteasesite", .fns = &poly_fns, .polygon = &p_proteasesite}, |
| 341 |
{.name = "proteinstab", .fns = &poly_fns, .polygon = &p_proteinstab}, |
| 342 |
/** dna construction symbols **/ |
| 343 |
{.name = "primersite", .fns = &poly_fns, .polygon = &p_primersite}, |
| 344 |
{.name = "restrictionsite", .fns = &poly_fns, .polygon = &p_restrictionsite}, |
| 345 |
{.name = "fivepoverhang", .fns = &poly_fns, .polygon = &p_fivepoverhang}, |
| 346 |
{.name = "threepoverhang", .fns = &poly_fns, .polygon = &p_threepoverhang}, |
| 347 |
{.name = "noverhang", .fns = &poly_fns, .polygon = &p_noverhang}, |
| 348 |
{.name = "assembly", .fns = &poly_fns, .polygon = &p_assembly}, |
| 349 |
{.name = "signature", .fns = &poly_fns, .polygon = &p_signature}, |
| 350 |
{.name = "rpromoter", .fns = &poly_fns, .polygon = &p_rpromoter}, |
| 351 |
{.name = "larrow", .fns = &poly_fns, .polygon = &p_larrow}, |
| 352 |
{.name = "rarrow", .fns = &poly_fns, .polygon = &p_rarrow}, |
| 353 |
{.name = "lpromoter", .fns = &poly_fns, .polygon = &p_lpromoter}, |
| 354 |
/* *** shapes other than polygons *** */ |
| 355 |
{.name = "record", .fns = &record_fns, .polygon = NULL}, |
| 356 |
{.name = "Mrecord", .fns = &record_fns, .polygon = NULL}, |
| 357 |
{.name = "epsf", .fns = &epsf_fns, .polygon = NULL}, |
| 358 |
{.name = "star", .fns = &star_fns, .polygon = &p_star}, |
| 359 |
{0} |
| 360 |
}; |
| 361 |
|
| 362 |
static void unrecognized(node_t * n, char *p) |
| 363 |
{ |
| 364 |
agwarningf("node %s, port %s unrecognized\n", agnameof(n), p); |
| 365 |
} |
| 366 |
|
| 367 |
static double quant(double val, double q) |
| 368 |
{ |
| 369 |
return ceil(val / q) * q; |
| 370 |
} |
| 371 |
|
| 372 |
/* test if both p0 and p1 are on the same side of the line L0,L1 */ |
| 373 |
static int same_side(pointf p0, pointf p1, pointf L0, pointf L1) |
| 374 |
{ |
| 375 |
int s0, s1; |
| 376 |
double a, b, c; |
| 377 |
|
| 378 |
/* a x + b y = c */ |
| 379 |
a = -(L1.y - L0.y); |
| 380 |
b = L1.x - L0.x; |
| 381 |
c = a * L0.x + b * L0.y; |
| 382 |
|
| 383 |
s0 = a * p0.x + b * p0.y - c >= 0; |
| 384 |
s1 = a * p1.x + b * p1.y - c >= 0; |
| 385 |
return s0 == s1; |
| 386 |
} |
| 387 |
|
| 388 |
static |
| 389 |
char* penColor(GVJ_t * job, node_t * n) |
| 390 |
{ |
| 391 |
char *color; |
| 392 |
|
| 393 |
color = late_nnstring(n, N_color, ""); |
| 394 |
if (!color[0]) |
| 395 |
color = DEFAULT_COLOR; |
| 396 |
gvrender_set_pencolor(job, color); |
| 397 |
return color; |
| 398 |
} |
| 399 |
|
| 400 |
static |
| 401 |
char *findFillDflt(node_t * n, char *dflt) |
| 402 |
{ |
| 403 |
char *color; |
| 404 |
|
| 405 |
color = late_nnstring(n, N_fillcolor, ""); |
| 406 |
if (!color[0]) { |
| 407 |
/* for backward compatibility, default fill is same as pen */ |
| 408 |
color = late_nnstring(n, N_color, ""); |
| 409 |
if (!color[0]) { |
| 410 |
color = dflt; |
| 411 |
} |
| 412 |
} |
| 413 |
return color; |
| 414 |
} |
| 415 |
|
| 416 |
static |
| 417 |
char *findFill(node_t * n) |
| 418 |
{ |
| 419 |
return findFillDflt(n, DEFAULT_FILL); |
| 420 |
} |
| 421 |
|
| 422 |
static bool isBox(node_t *n) { |
| 423 |
polygon_t *p; |
| 424 |
|
| 425 |
if ((p = ND_shape(n)->polygon)) { |
| 426 |
return p->sides == 4 && fabs(fmod(p->orientation, 90)) < 0.5 && |
| 427 |
is_exactly_zero(p->distortion) && is_exactly_zero(p->skew); |
| 428 |
} |
| 429 |
return false; |
| 430 |
} |
| 431 |
|
| 432 |
static bool isEllipse(node_t *n) { |
| 433 |
polygon_t *p; |
| 434 |
|
| 435 |
if ((p = ND_shape(n)->polygon)) { |
| 436 |
return p->sides <= 2; |
| 437 |
} |
| 438 |
return false; |
| 439 |
} |
| 440 |
|
| 441 |
/// bitwise-OR styles |
| 442 |
static graphviz_polygon_style_t style_or(graphviz_polygon_style_t a, |
| 443 |
graphviz_polygon_style_t b) { |
| 444 |
|
| 445 |
// bitwise-or-ing the shape does not make sense, so there better only be one |
| 446 |
assert(a.shape == 0 || b.shape == 0); |
| 447 |
|
| 448 |
return (graphviz_polygon_style_t){ |
| 449 |
.filled = a.filled || b.filled, |
| 450 |
.radial = a.radial || b.radial, |
| 451 |
.rounded = a.rounded || b.rounded, |
| 452 |
.diagonals = a.diagonals || b.diagonals, |
| 453 |
.auxlabels = a.auxlabels || b.auxlabels, |
| 454 |
.invisible = a.invisible || b.invisible, |
| 455 |
.striped = a.striped || b.striped, |
| 456 |
.dotted = a.dotted || b.dotted, |
| 457 |
.dashed = a.dashed || b.dashed, |
| 458 |
.wedged = a.wedged || b.wedged, |
| 459 |
.underline = a.underline || b.underline, |
| 460 |
.fixedshape = a.fixedshape || b.fixedshape, |
| 461 |
.shape = a.shape | b.shape, |
| 462 |
}; |
| 463 |
} |
| 464 |
|
| 465 |
static char **checkStyle(node_t *n, graphviz_polygon_style_t *flagp) { |
| 466 |
char *style; |
| 467 |
char **pstyle = 0; |
| 468 |
graphviz_polygon_style_t istyle = {0}; |
| 469 |
polygon_t *poly; |
| 470 |
|
| 471 |
style = late_nnstring(n, N_style, ""); |
| 472 |
if (style[0]) { |
| 473 |
char **pp; |
| 474 |
char **qp; |
| 475 |
char *p; |
| 476 |
pp = pstyle = parse_style(style); |
| 477 |
while ((p = *pp)) { |
| 478 |
if (streq(p, "filled")) { |
| 479 |
istyle.filled = true; |
| 480 |
pp++; |
| 481 |
} else if (streq(p, "rounded")) { |
| 482 |
istyle.rounded = true; |
| 483 |
qp = pp; /* remove rounded from list passed to renderer */ |
| 484 |
do { |
| 485 |
qp++; |
| 486 |
*(qp - 1) = *qp; |
| 487 |
} while (*qp); |
| 488 |
} else if (streq(p, "diagonals")) { |
| 489 |
istyle.diagonals = true; |
| 490 |
qp = pp; /* remove diagonals from list passed to renderer */ |
| 491 |
do { |
| 492 |
qp++; |
| 493 |
*(qp - 1) = *qp; |
| 494 |
} while (*qp); |
| 495 |
} else if (streq(p, "invis")) { |
| 496 |
istyle.invisible = true; |
| 497 |
pp++; |
| 498 |
} else if (streq(p, "radial")) { |
| 499 |
istyle.radial = true; |
| 500 |
istyle.filled = true; |
| 501 |
qp = pp; /* remove radial from list passed to renderer */ |
| 502 |
do { |
| 503 |
qp++; |
| 504 |
*(qp - 1) = *qp; |
| 505 |
} while (*qp); |
| 506 |
} else if (streq(p, "striped") && isBox(n)) { |
| 507 |
istyle.striped = true; |
| 508 |
qp = pp; /* remove striped from list passed to renderer */ |
| 509 |
do { |
| 510 |
qp++; |
| 511 |
*(qp - 1) = *qp; |
| 512 |
} while (*qp); |
| 513 |
} else if (streq(p, "wedged") && isEllipse(n)) { |
| 514 |
istyle.wedged = true; |
| 515 |
qp = pp; /* remove wedged from list passed to renderer */ |
| 516 |
do { |
| 517 |
qp++; |
| 518 |
*(qp - 1) = *qp; |
| 519 |
} while (*qp); |
| 520 |
} else |
| 521 |
pp++; |
| 522 |
} |
| 523 |
} |
| 524 |
if ((poly = ND_shape(n)->polygon)) |
| 525 |
istyle = style_or(istyle, poly->option); |
| 526 |
|
| 527 |
*flagp = istyle; |
| 528 |
return pstyle; |
| 529 |
} |
| 530 |
|
| 531 |
static graphviz_polygon_style_t stylenode(GVJ_t *job, node_t *n) { |
| 532 |
char **pstyle, *s; |
| 533 |
graphviz_polygon_style_t istyle = {0}; |
| 534 |
double penwidth; |
| 535 |
|
| 536 |
if ((pstyle = checkStyle(n, &istyle))) |
| 537 |
gvrender_set_style(job, pstyle); |
| 538 |
|
| 539 |
if (N_penwidth && (s = agxget(n, N_penwidth)) && s[0]) { |
| 540 |
penwidth = late_double(n, N_penwidth, 1.0, 0.0); |
| 541 |
gvrender_set_penwidth(job, penwidth); |
| 542 |
} |
| 543 |
|
| 544 |
return istyle; |
| 545 |
} |
| 546 |
|
| 547 |
static void Mcircle_hack(GVJ_t * job, node_t * n) |
| 548 |
{ |
| 549 |
double x, y; |
| 550 |
pointf AF[2], p; |
| 551 |
|
| 552 |
y = .7500; |
| 553 |
x = .6614; /* x^2 + y^2 = 1.0 */ |
| 554 |
p.y = y * ND_ht(n) / 2.0; |
| 555 |
p.x = ND_rw(n) * x; /* assume node is symmetric */ |
| 556 |
|
| 557 |
AF[0] = add_pointf(p, ND_coord(n)); |
| 558 |
AF[1].y = AF[0].y; |
| 559 |
AF[1].x = AF[0].x - 2 * p.x; |
| 560 |
gvrender_polyline(job, AF, 2); |
| 561 |
AF[0].y -= 2 * p.y; |
| 562 |
AF[1].y = AF[0].y; |
| 563 |
gvrender_polyline(job, AF, 2); |
| 564 |
} |
| 565 |
|
| 566 |
static pointf * alloc_interpolation_points(pointf *AF, size_t sides, |
| 567 |
graphviz_polygon_style_t style, bool rounded) |
| 568 |
{ |
| 569 |
pointf *B = gv_calloc(4 * sides + 4, sizeof(pointf)); |
| 570 |
size_t i = 0; |
| 571 |
pointf p0, p1; |
| 572 |
double dx, dy, t; |
| 573 |
/* rbconst is distance offset from a corner of the polygon. |
| 574 |
* It should be the same for every corner, and also never |
| 575 |
* bigger than one-third the length of a side. |
| 576 |
*/ |
| 577 |
double rbconst = RBCONST; |
| 578 |
for (size_t seg = 0; seg < sides; seg++) { |
| 579 |
p0 = AF[seg]; |
| 580 |
if (seg + 1 < sides) |
| 581 |
p1 = AF[seg + 1]; |
| 582 |
else |
| 583 |
p1 = AF[0]; |
| 584 |
dx = p1.x - p0.x; |
| 585 |
dy = p1.y - p0.y; |
| 586 |
const double d = hypot(dx, dy); |
| 587 |
rbconst = fmin(rbconst, d / 3.0); |
| 588 |
} |
| 589 |
for (size_t seg = 0; seg < sides; seg++) { |
| 590 |
p0 = AF[seg]; |
| 591 |
if (seg + 1 < sides) |
| 592 |
p1 = AF[seg + 1]; |
| 593 |
else |
| 594 |
p1 = AF[0]; |
| 595 |
dx = p1.x - p0.x; |
| 596 |
dy = p1.y - p0.y; |
| 597 |
const double d = hypot(dx, dy); |
| 598 |
t = rbconst / d; |
| 599 |
if (style.shape == BOX3D || style.shape == COMPONENT) |
| 600 |
t /= 3; |
| 601 |
else if (style.shape == DOGEAR) |
| 602 |
t /= 2; |
| 603 |
if (!rounded) |
| 604 |
B[i++] = p0; |
| 605 |
else |
| 606 |
B[i++] = interpolate_pointf(RBCURVE * t, p0, p1); |
| 607 |
B[i++] = interpolate_pointf(t, p0, p1); |
| 608 |
B[i++] = interpolate_pointf(1.0 - t, p0, p1); |
| 609 |
if (rounded) |
| 610 |
B[i++] = interpolate_pointf(1.0 - RBCURVE * t, p0, p1); |
| 611 |
} |
| 612 |
B[i++] = B[0]; |
| 613 |
B[i++] = B[1]; |
| 614 |
B[i++] = B[2]; |
| 615 |
|
| 616 |
return B; |
| 617 |
} |
| 618 |
|
| 619 |
/** |
| 620 |
* @brief draws polygons with diagonals on corners |
| 621 |
* |
| 622 |
* Diagonals are weird. Rewrite someday. |
| 623 |
*/ |
| 624 |
static void diagonals_draw(GVJ_t *job, pointf *AF, size_t sides, |
| 625 |
graphviz_polygon_style_t style, int filled) |
| 626 |
{ |
| 627 |
pointf *B = alloc_interpolation_points(AF, sides, style, false); |
| 628 |
gvrender_polygon(job, AF, sides, filled); |
| 629 |
|
| 630 |
for (size_t seg = 0; seg < sides; seg++) { |
| 631 |
pointf C[] = {B[3 * seg + 2], B[3 * seg + 4]}; |
| 632 |
gvrender_polyline(job, C, 2); |
| 633 |
} |
| 634 |
free(B); |
| 635 |
} |
| 636 |
|
| 637 |
/** |
| 638 |
* @brief draws rounded polygons with |
| 639 |
* [Bézier curve](https://en.wikipedia.org/wiki/Bézier_curve) |
| 640 |
* |
| 641 |
* For example, a rounded star looks like a cartoon starfish. |
| 642 |
*/ |
| 643 |
static void rounded_draw(GVJ_t *job, pointf *AF, size_t sides, |
| 644 |
graphviz_polygon_style_t style, int filled) |
| 645 |
{ |
| 646 |
size_t i = 0; |
| 647 |
|
| 648 |
pointf *B = alloc_interpolation_points(AF, sides, style, true); |
| 649 |
pointf *pts = gv_calloc(6 * sides + 2, sizeof(pointf)); |
| 650 |
for (size_t seg = 0; seg < sides; seg++) { |
| 651 |
pts[i++] = B[4 * seg]; |
| 652 |
pts[i++] = B[4 * seg + 1]; |
| 653 |
pts[i++] = B[4 * seg + 1]; |
| 654 |
pts[i++] = B[4 * seg + 2]; |
| 655 |
pts[i++] = B[4 * seg + 2]; |
| 656 |
pts[i++] = B[4 * seg + 3]; |
| 657 |
} |
| 658 |
pts[i++] = pts[0]; |
| 659 |
pts[i++] = pts[1]; |
| 660 |
gvrender_beziercurve(job, pts + 1, i - 1, filled); |
| 661 |
free(pts); |
| 662 |
free(B); |
| 663 |
} |
| 664 |
|
| 665 |
/** |
| 666 |
* @file |
| 667 |
* ~~~~ |
| 668 |
* y |
| 669 |
* 🡑 |
| 670 |
* │ |
| 671 |
* │ |
| 672 |
* │ line[1] |
| 673 |
* │ ⟋ |
| 674 |
* mid_y ┤ middle |
| 675 |
* │ ⟋ |
| 676 |
* │line[0] x |
| 677 |
* ─┼─────┬───────────🡒 |
| 678 |
* mid_x |
| 679 |
* ~~~~ |
| 680 |
*/ |
| 681 |
|
| 682 |
/** |
| 683 |
* @brief X coordinate of line midpoint |
| 684 |
* @param line two points |
| 685 |
* @returns X coordinate of midpoint |
| 686 |
*/ |
| 687 |
static double mid_x(const pointf line[2]) { |
| 688 |
return (line[0].x + line[1].x) / 2; |
| 689 |
} |
| 690 |
|
| 691 |
/** |
| 692 |
* @brief Y coordinate of line midpoint |
| 693 |
* @param line two points |
| 694 |
* @returns Y coordinate of midpoint |
| 695 |
*/ |
| 696 |
static double mid_y(const pointf line[2]) { |
| 697 |
return (line[0].y + line[1].y) / 2; |
| 698 |
} |
| 699 |
|
| 700 |
/** |
| 701 |
* @brief Handle some special graphical cases, such as rounding the shape, |
| 702 |
* adding diagonals at corners, or drawing certain non-simple figures. |
| 703 |
* |
| 704 |
* Any drawing done here should assume fillcolors, pencolors, etc. |
| 705 |
* have been set by the calling routine. Normally, the drawing should |
| 706 |
* consist of a region, filled or unfilled, followed by additional line |
| 707 |
* segments. A single fill is necessary for gradient colors to work. |
| 708 |
*/ |
| 709 |
void round_corners(GVJ_t *job, pointf *AF, size_t sides, |
| 710 |
graphviz_polygon_style_t style, int filled) { |
| 711 |
assert(job != NULL); |
| 712 |
assert(AF != NULL); |
| 713 |
assert(sides > 0); |
| 714 |
assert(memcmp(&style, &(graphviz_polygon_style_t){0}, sizeof(style)) != 0); |
| 715 |
|
| 716 |
pointf *B, C[5], *D; |
| 717 |
|
| 718 |
struct { |
| 719 |
unsigned shape: 7; |
| 720 |
} mode = {0}; |
| 721 |
|
| 722 |
if (style.diagonals) { |
| 723 |
diagonals_draw(job, AF, sides, style, filled); |
| 724 |
return; |
| 725 |
} else if (style.shape != 0) { |
| 726 |
mode.shape = style.shape; |
| 727 |
} else if (style.rounded) { |
| 728 |
rounded_draw(job, AF, sides, style, filled); |
| 729 |
return; |
| 730 |
} else { |
| 731 |
UNREACHABLE(); |
| 732 |
} |
| 733 |
|
| 734 |
if (mode.shape == CYLINDER) { |
| 735 |
cylinder_draw(job, AF, sides, filled); |
| 736 |
return; |
| 737 |
} |
| 738 |
B = alloc_interpolation_points(AF, sides, style, false); |
| 739 |
switch (mode.shape) { |
| 740 |
case DOGEAR: |
| 741 |
/* Add the cutoff edge. */ |
| 742 |
D = gv_calloc(sides + 1, sizeof(pointf)); |
| 743 |
for (size_t seg = 1; seg < sides; seg++) |
| 744 |
D[seg] = AF[seg]; |
| 745 |
D[0] = B[3 * (sides - 1) + 4]; |
| 746 |
D[sides] = B[3 * (sides - 1) + 2]; |
| 747 |
gvrender_polygon(job, D, sides + 1, filled); |
| 748 |
free(D); |
| 749 |
|
| 750 |
/* Draw the inner edge. */ |
| 751 |
const size_t sseg = sides - 1; |
| 752 |
C[0] = B[3 * sseg + 2]; |
| 753 |
C[1] = B[3 * sseg + 4]; |
| 754 |
C[2].x = C[1].x + (C[0].x - B[3 * sseg + 3].x); |
| 755 |
C[2].y = C[1].y + (C[0].y - B[3 * sseg + 3].y); |
| 756 |
gvrender_polyline(job, C + 1, 2); |
| 757 |
C[1] = C[2]; |
| 758 |
gvrender_polyline(job, C, 2); |
| 759 |
break; |
| 760 |
case TAB: |
| 761 |
/* |
| 762 |
* Adjust the perimeter for the protrusions. |
| 763 |
* |
| 764 |
* D[3] ×──× D[2] |
| 765 |
* │ │ B[1] |
| 766 |
* B[3] ×──×──────────×──× AF[0]=B[0]=D[0] |
| 767 |
* │ B[2]=D[1] │ |
| 768 |
* B[4] × │ |
| 769 |
* │ │ |
| 770 |
* B[5] × │ |
| 771 |
* └────────────────┘ |
| 772 |
* |
| 773 |
*/ |
| 774 |
/* Add the tab edges. */ |
| 775 |
D = gv_calloc(sides + 2, sizeof(pointf)); |
| 776 |
D[0] = AF[0]; |
| 777 |
D[1] = B[2]; |
| 778 |
D[2].x = B[2].x + (B[3].x - B[4].x) / 3; |
| 779 |
D[2].y = B[2].y + (B[3].y - B[4].y) / 3; |
| 780 |
D[3].x = B[3].x + (B[3].x - B[4].x) / 3; |
| 781 |
D[3].y = B[3].y + (B[3].y - B[4].y) / 3; |
| 782 |
for (size_t seg = 4; seg < sides + 2; seg++) |
| 783 |
D[seg] = AF[seg - 2]; |
| 784 |
gvrender_polygon(job, D, sides + 2, filled); |
| 785 |
free(D); |
| 786 |
|
| 787 |
|
| 788 |
/* Draw the inner edge. */ |
| 789 |
C[0] = B[3]; |
| 790 |
C[1] = B[2]; |
| 791 |
gvrender_polyline(job, C, 2); |
| 792 |
break; |
| 793 |
case FOLDER: |
| 794 |
/* |
| 795 |
* Adjust the perimeter for the protrusions. |
| 796 |
* |
| 797 |
* D[2] ×────× D[1] |
| 798 |
* B[3]= ╱ ╲ |
| 799 |
* D[4] ×──×────× × × AF[0]=B[0]=D[0] |
| 800 |
* │ B[2] D[3] B[1]│ |
| 801 |
* B[4] × │ |
| 802 |
* │ │ |
| 803 |
* B[5] × │ |
| 804 |
* └────────────────┘ |
| 805 |
* |
| 806 |
*/ |
| 807 |
/* Add the folder edges. */ |
| 808 |
D = gv_calloc(sides + 3, sizeof(pointf)); |
| 809 |
D[0] = AF[0]; |
| 810 |
D[1].x = AF[0].x - (AF[0].x - B[1].x) / 4; |
| 811 |
D[1].y = AF[0].y + (B[3].y - B[4].y) / 3; |
| 812 |
D[2].x = AF[0].x - 2 * (AF[0].x - B[1].x); |
| 813 |
D[2].y = D[1].y; |
| 814 |
D[3].x = AF[0].x - 2.25 * (AF[0].x - B[1].x); |
| 815 |
D[3].y = B[3].y; |
| 816 |
D[4].x = B[3].x; |
| 817 |
D[4].y = B[3].y; |
| 818 |
for (size_t seg = 4; seg < sides + 3; seg++) |
| 819 |
D[seg] = AF[seg - 3]; |
| 820 |
gvrender_polygon(job, D, sides + 3, filled); |
| 821 |
free(D); |
| 822 |
break; |
| 823 |
case BOX3D: |
| 824 |
assert(sides == 4); |
| 825 |
/* Adjust for the cutoff edges. */ |
| 826 |
D = gv_calloc(sides + 2, sizeof(pointf)); |
| 827 |
D[0] = AF[0]; |
| 828 |
D[1] = B[2]; |
| 829 |
D[2] = B[4]; |
| 830 |
D[3] = AF[2]; |
| 831 |
D[4] = B[8]; |
| 832 |
D[5] = B[10]; |
| 833 |
gvrender_polygon(job, D, sides + 2, filled); |
| 834 |
free(D); |
| 835 |
|
| 836 |
/* Draw the inner vertices. */ |
| 837 |
C[0].x = B[1].x + (B[11].x - B[0].x); |
| 838 |
C[0].y = B[1].y + (B[11].y - B[0].y); |
| 839 |
C[1] = B[4]; |
| 840 |
gvrender_polyline(job, C, 2); |
| 841 |
C[1] = B[8]; |
| 842 |
gvrender_polyline(job, C, 2); |
| 843 |
C[1] = B[0]; |
| 844 |
gvrender_polyline(job, C, 2); |
| 845 |
break; |
| 846 |
case COMPONENT: |
| 847 |
assert(sides == 4); |
| 848 |
/* |
| 849 |
* Adjust the perimeter for the protrusions. |
| 850 |
* |
| 851 |
* D[1] ×────────────────× D[0] |
| 852 |
* │ │ |
| 853 |
* 3×───×2──┐ │ |
| 854 |
* │ │ │ |
| 855 |
* 4×───×5──┘ │ |
| 856 |
* │ │ |
| 857 |
* 7×───×6──┐ │ |
| 858 |
* │ │ │ |
| 859 |
* 8×───×9──┘ │ |
| 860 |
* │ │ |
| 861 |
* 10×────────────────× D[11] |
| 862 |
* |
| 863 |
*/ |
| 864 |
D = gv_calloc(sides + 8, sizeof(pointf)); |
| 865 |
D[0] = AF[0]; |
| 866 |
D[1] = AF[1]; |
| 867 |
D[2].x = B[3].x + (B[4].x - B[3].x); |
| 868 |
D[2].y = B[3].y + (B[4].y - B[3].y); |
| 869 |
D[3].x = D[2].x + (B[3].x - B[2].x); |
| 870 |
D[3].y = D[2].y + (B[3].y - B[2].y); |
| 871 |
D[4].x = D[3].x + (B[4].x - B[3].x); |
| 872 |
D[4].y = D[3].y + (B[4].y - B[3].y); |
| 873 |
D[5].x = D[4].x + (D[2].x - D[3].x); |
| 874 |
D[5].y = D[4].y + (D[2].y - D[3].y); |
| 875 |
|
| 876 |
D[9].x = B[6].x + (B[5].x - B[6].x); |
| 877 |
D[9].y = B[6].y + (B[5].y - B[6].y); |
| 878 |
D[8].x = D[9].x + (B[6].x - B[7].x); |
| 879 |
D[8].y = D[9].y + (B[6].y - B[7].y); |
| 880 |
D[7].x = D[8].x + (B[5].x - B[6].x); |
| 881 |
D[7].y = D[8].y + (B[5].y - B[6].y); |
| 882 |
D[6].x = D[7].x + (D[9].x - D[8].x); |
| 883 |
D[6].y = D[7].y + (D[9].y - D[8].y); |
| 884 |
|
| 885 |
D[10] = AF[2]; |
| 886 |
D[11] = AF[3]; |
| 887 |
gvrender_polygon(job, D, sides + 8, filled); |
| 888 |
|
| 889 |
/* Draw the internal vertices. */ |
| 890 |
C[0] = D[2]; |
| 891 |
C[1].x = D[2].x - (D[3].x - D[2].x); |
| 892 |
C[1].y = D[2].y - (D[3].y - D[2].y); |
| 893 |
C[2].x = C[1].x + (D[4].x - D[3].x); |
| 894 |
C[2].y = C[1].y + (D[4].y - D[3].y); |
| 895 |
C[3] = D[5]; |
| 896 |
gvrender_polyline(job, C, 4); |
| 897 |
C[0] = D[6]; |
| 898 |
C[1].x = D[6].x - (D[7].x - D[6].x); |
| 899 |
C[1].y = D[6].y - (D[7].y - D[6].y); |
| 900 |
C[2].x = C[1].x + (D[8].x - D[7].x); |
| 901 |
C[2].y = C[1].y + (D[8].y - D[7].y); |
| 902 |
C[3] = D[9]; |
| 903 |
gvrender_polyline(job, C, 4); |
| 904 |
|
| 905 |
free(D); |
| 906 |
break; |
| 907 |
|
| 908 |
case PROMOTER: |
| 909 |
/* |
| 910 |
* L-shaped arrow on a center line, scales in the x direction |
| 911 |
* |
| 912 |
* |
| 913 |
* D[1] │╲ |
| 914 |
* ×────────────────× ╲ |
| 915 |
* │ D[0] ╲ |
| 916 |
* │ ╲ |
| 917 |
* │ ╱ |
| 918 |
* │ D[5] ╱ |
| 919 |
* │ ┌───────× ╱ |
| 920 |
* │ │ │╱ |
| 921 |
* ─────┴────────┴───────────── |
| 922 |
*/ |
| 923 |
/* Add the tab edges. */ |
| 924 |
|
| 925 |
//the arrow's thickness is (B[2].x-B[3].x)/2 or (B[3].y-B[4].y)/2; |
| 926 |
// the thickness is substituted with (AF[0].x - AF[1].x)/8 to make it scalable |
| 927 |
// in the y with label length |
| 928 |
D = gv_calloc(sides + 5, sizeof(pointf)); |
| 929 |
D[0].x = mid_x(AF) + (AF[0].x - AF[1].x)/8; //x_center + width |
| 930 |
D[0].y = mid_y(&AF[1]) + (B[3].y-B[4].y)*3/2; //D[4].y + width |
| 931 |
D[1].x = mid_x(AF) - (AF[0].x - AF[1].x)/4; //x_center - 2*width |
| 932 |
D[1].y = D[0].y; |
| 933 |
D[2].x = D[1].x; |
| 934 |
D[2].y = mid_y(&AF[1]); |
| 935 |
D[3].x = D[2].x + (B[2].x - B[3].x)/2; //D[2].x + width |
| 936 |
D[3].y = mid_y(&AF[1]); |
| 937 |
D[4].x = D[3].x; |
| 938 |
D[4].y = mid_y(&AF[1]) + (B[3].y-B[4].y); //highest cds point |
| 939 |
D[5].x = D[0].x; |
| 940 |
D[5].y = D[4].y; //highest cds point |
| 941 |
D[6].x = D[0].x; |
| 942 |
D[6].y = D[4].y - (B[3].y-B[4].y)/4; //D[4].y - width/2 |
| 943 |
D[7].x = D[6].x + (B[2].x - B[3].x); //D[6].x + 2*width |
| 944 |
D[7].y = D[6].y + (B[3].y - B[4].y)/2; //D[6].y + width |
| 945 |
D[8].x = D[0].x; |
| 946 |
D[8].y = D[0].y + (B[3].y - B[4].y)/4;//D[0].y + width/2 |
| 947 |
gvrender_polygon(job, D, sides + 5, filled); |
| 948 |
|
| 949 |
/*dsDNA line*/ |
| 950 |
C[0].x = AF[1].x; |
| 951 |
C[0].y = mid_y(&AF[1]); |
| 952 |
C[1].x = AF[0].x; |
| 953 |
C[1].y = AF[2].y + (AF[0].y - AF[3].y)/2; |
| 954 |
gvrender_polyline(job, C, 2); |
| 955 |
free(D); |
| 956 |
|
| 957 |
break; |
| 958 |
|
| 959 |
case CDS: |
| 960 |
/* |
| 961 |
* arrow without the protrusions, scales normally |
| 962 |
* |
| 963 |
* |
| 964 |
* D[1] = AF[1] |
| 965 |
* ×────────────────×╲ |
| 966 |
* │ D[0]╲ |
| 967 |
* │ ╲ |
| 968 |
* │ ╱ |
| 969 |
* │ ╱ |
| 970 |
* ×────────────────×╱ |
| 971 |
* D[3] |
| 972 |
* |
| 973 |
*/ |
| 974 |
D = gv_calloc(sides + 1, sizeof(pointf)); |
| 975 |
D[0].x = B[1].x; |
| 976 |
D[0].y = B[1].y - (B[3].y - B[4].y)/2; |
| 977 |
D[1].x = B[3].x; |
| 978 |
D[1].y = B[3].y - (B[3].y - B[4].y)/2; |
| 979 |
D[2].x = AF[2].x; |
| 980 |
D[2].y = AF[2].y + (B[3].y - B[4].y)/2; |
| 981 |
D[3].x = B[1].x; |
| 982 |
D[3].y = AF[2].y + (B[3].y - B[4].y)/2; |
| 983 |
D[4].y = AF[0].y - (AF[0].y - AF[3].y)/2; |
| 984 |
D[4].x = AF[0].x; |
| 985 |
|
| 986 |
gvrender_polygon(job, D, sides + 1, filled); |
| 987 |
free(D); |
| 988 |
|
| 989 |
break; |
| 990 |
|
| 991 |
case TERMINATOR: |
| 992 |
/* |
| 993 |
* T-shape, does not scale, always in the center |
| 994 |
* |
| 995 |
* |
| 996 |
* D[4] |
| 997 |
* ×────────────────× |
| 998 |
* │ D[3] |
| 999 |
* │ │ |
| 1000 |
* │ │ |
| 1001 |
* │ D[6] D[1] │ |
| 1002 |
* D[5]×───× ×────× D[2] |
| 1003 |
* │ │ |
| 1004 |
* ─────────┴───────×─D[0]────── |
| 1005 |
*/ |
| 1006 |
//width units are (B[2].x-B[3].x)/2 or (B[3].y-B[4].y)/2; |
| 1007 |
D = gv_calloc(sides + 4, sizeof(pointf)); |
| 1008 |
D[0].x = mid_x(AF) + (B[2].x-B[3].x)/4; //x_center + width/2 |
| 1009 |
D[0].y = mid_y(&AF[1]); |
| 1010 |
D[1].x = D[0].x; |
| 1011 |
D[1].y = D[0].y + (B[3].y-B[4].y)/2; |
| 1012 |
D[2].x = D[1].x + (B[2].x-B[3].x)/2; |
| 1013 |
D[2].y = D[1].y; |
| 1014 |
D[3].x = D[2].x; |
| 1015 |
D[3].y = D[2].y + (B[3].y-B[4].y)/2; |
| 1016 |
D[4].x = mid_x(AF) - (B[2].x-B[3].x)*3/4; //D[3].y mirrored across the center |
| 1017 |
D[4].y = D[3].y; |
| 1018 |
D[5].x = D[4].x; |
| 1019 |
D[5].y = D[2].y; |
| 1020 |
D[6].x = mid_x(AF) - (B[2].x-B[3].x)/4; //D[1].x mirrored across the center |
| 1021 |
D[6].y = D[1].y; |
| 1022 |
D[7].x = D[6].x; |
| 1023 |
D[7].y = D[0].y; |
| 1024 |
gvrender_polygon(job, D, sides + 4, filled); |
| 1025 |
|
| 1026 |
/*dsDNA line*/ |
| 1027 |
C[0].x = AF[1].x; |
| 1028 |
C[0].y = mid_y(&AF[1]); |
| 1029 |
C[1].x = AF[0].x; |
| 1030 |
C[1].y = AF[2].y + (AF[0].y - AF[3].y)/2; |
| 1031 |
gvrender_polyline(job, C, 2); |
| 1032 |
free(D); |
| 1033 |
|
| 1034 |
break; |
| 1035 |
|
| 1036 |
case UTR: |
| 1037 |
/* |
| 1038 |
* half-octagon with line, does not scale, always in center |
| 1039 |
* |
| 1040 |
* D[3] |
| 1041 |
* ───── D[2] |
| 1042 |
* ╱ ╲ |
| 1043 |
* ╱ ╲ D[1] |
| 1044 |
* │ │ |
| 1045 |
* ─────┴───────┴─────── |
| 1046 |
* D[0] |
| 1047 |
* |
| 1048 |
* |
| 1049 |
* |
| 1050 |
*/ |
| 1051 |
//width units are (B[2].x-B[3].x)/2 or (B[3].y-B[4].y)/2; |
| 1052 |
D = gv_calloc(sides + 2, sizeof(pointf)); |
| 1053 |
D[0].x = mid_x(AF) + (B[2].x-B[3].x)*3/4; //x_center+width |
| 1054 |
D[0].y = mid_y(&AF[1]); |
| 1055 |
D[1].x = D[0].x; |
| 1056 |
D[1].y = D[0].y + (B[3].y-B[4].y)/4; //D[0].y+width/2 |
| 1057 |
D[2].x = mid_x(AF) + (B[2].x-B[3].x)/4; //x_center+width/2 |
| 1058 |
D[2].y = D[1].y + (B[3].y-B[4].y)/2; //D[1].y+width |
| 1059 |
D[3].x = mid_x(AF) - (B[2].x-B[3].x)/4; //D[2].x mirrored across the center |
| 1060 |
D[3].y = D[2].y; |
| 1061 |
D[4].x = mid_x(AF) - (B[2].x-B[3].x)*3/4; |
| 1062 |
D[4].y = D[1].y; |
| 1063 |
D[5].x = D[4].x; |
| 1064 |
D[5].y = D[0].y; |
| 1065 |
gvrender_polygon(job, D, sides + 2, filled); |
| 1066 |
|
| 1067 |
/*dsDNA line*/ |
| 1068 |
C[0].x = AF[1].x; |
| 1069 |
C[0].y = mid_y(&AF[1]); |
| 1070 |
C[1].x = AF[0].x; |
| 1071 |
C[1].y = AF[2].y + (AF[0].y - AF[3].y)/2; |
| 1072 |
gvrender_polyline(job, C, 2); |
| 1073 |
free(D); |
| 1074 |
|
| 1075 |
break; |
| 1076 |
case PRIMERSITE: |
| 1077 |
/* |
| 1078 |
* half arrow shape, scales in the x-direction |
| 1079 |
* D[1] |
| 1080 |
* │╲ |
| 1081 |
* │ ╲ |
| 1082 |
* │ ╲ |
| 1083 |
* ┌───────────┘ ╲ |
| 1084 |
* │ ╲ |
| 1085 |
* └─────────────────╲ D[0] |
| 1086 |
* |
| 1087 |
* ──────────────────────────────── |
| 1088 |
* |
| 1089 |
*/ |
| 1090 |
//width units are (B[2].x-B[3].x)/2 or (B[3].y-B[4].y)/2; |
| 1091 |
// the thickness is substituted with (AF[0].x - AF[1].x)/8 to make it scalable |
| 1092 |
// in the y with label length |
| 1093 |
D = gv_calloc(sides + 1, sizeof(pointf)); |
| 1094 |
D[0].x = mid_x(AF) + (B[2].x-B[3].x);//x_center + width*2 |
| 1095 |
D[0].y = mid_y(&AF[1]) + (B[3].y-B[4].y)/4;//y_center + 1/2 width |
| 1096 |
D[1].x = D[0].x - (B[2].x-B[3].x); //x_center |
| 1097 |
D[1].y = D[0].y + (B[3].y-B[4].y); |
| 1098 |
D[2].x = D[1].x; |
| 1099 |
D[2].y = D[0].y + (B[3].y-B[4].y)/2; |
| 1100 |
D[3].x = mid_x(AF) - (AF[0].x - AF[1].x)/4;//x_center - 2*(scalable width) |
| 1101 |
D[3].y = D[2].y; |
| 1102 |
D[4].x = D[3].x; |
| 1103 |
D[4].y = D[0].y; |
| 1104 |
gvrender_polygon(job, D, sides + 1, filled); |
| 1105 |
|
| 1106 |
/*dsDNA line*/ |
| 1107 |
C[0].x = AF[1].x; |
| 1108 |
C[0].y = mid_y(&AF[1]); |
| 1109 |
C[1].x = AF[0].x; |
| 1110 |
C[1].y = AF[2].y + (AF[0].y - AF[3].y)/2; |
| 1111 |
gvrender_polyline(job, C, 2); |
| 1112 |
free(D); |
| 1113 |
|
| 1114 |
break; |
| 1115 |
case RESTRICTIONSITE: |
| 1116 |
/* |
| 1117 |
* zigzag shape, scales in the x-direction (only the middle section) |
| 1118 |
* |
| 1119 |
* |
| 1120 |
* ┌───D[2] |
| 1121 |
* │ └──────── D[0] |
| 1122 |
* ────┤ ├──── |
| 1123 |
* └────────┐ │ |
| 1124 |
* D[4] └─── D[7] |
| 1125 |
* |
| 1126 |
* |
| 1127 |
* |
| 1128 |
*/ |
| 1129 |
//width units are (B[2].x-B[3].x)/2 or (B[3].y-B[4].y)/2; |
| 1130 |
// the thickness is substituted with (AF[0].x - AF[1].x)/8 to make it scalable |
| 1131 |
// in the y with label length |
| 1132 |
D = gv_calloc(sides + 4, sizeof(pointf)); |
| 1133 |
D[0].x = mid_x(AF) + (AF[0].x - AF[1].x)/8 + (B[2].x-B[3].x)/2;//x_center + scalable_width + width |
| 1134 |
D[0].y = mid_y(&AF[1]) + (B[3].y-B[4].y)/4;//y_center + 1/2 width |
| 1135 |
D[1].x = mid_x(AF) - (AF[0].x - AF[1].x)/8; //x_center - width |
| 1136 |
D[1].y = D[0].y; |
| 1137 |
D[2].x = D[1].x; |
| 1138 |
D[2].y = D[1].y + (B[3].y-B[4].y)/2; |
| 1139 |
D[3].x = D[2].x - (B[2].x-B[3].x)/2; //D[2].x - width |
| 1140 |
D[3].y = D[2].y; |
| 1141 |
D[4].x = D[3].x; |
| 1142 |
D[4].y = mid_y(&AF[1]) - (B[3].y-B[4].y)/4; //y_center - 1/2(width) |
| 1143 |
D[5].x = D[0].x - (B[2].x-B[3].x)/2; |
| 1144 |
D[5].y = D[4].y; |
| 1145 |
D[6].x = D[5].x; |
| 1146 |
D[6].y = D[5].y - (B[3].y-B[4].y)/2; |
| 1147 |
D[7].x = D[0].x; |
| 1148 |
D[7].y = D[6].y; |
| 1149 |
gvrender_polygon(job, D, sides + 4, filled); |
| 1150 |
|
| 1151 |
/*dsDNA line left half*/ |
| 1152 |
C[0].x = AF[1].x; |
| 1153 |
C[0].y = mid_y(&AF[1]); |
| 1154 |
C[1].x = D[4].x; |
| 1155 |
C[1].y = AF[2].y + (AF[0].y - AF[3].y)/2; |
| 1156 |
gvrender_polyline(job, C, 2); |
| 1157 |
|
| 1158 |
/*dsDNA line right half*/ |
| 1159 |
C[0].x = D[7].x; |
| 1160 |
C[0].y = mid_y(&AF[1]); |
| 1161 |
C[1].x = AF[0].x; |
| 1162 |
C[1].y = AF[2].y + (AF[0].y - AF[3].y)/2; |
| 1163 |
gvrender_polyline(job, C, 2); |
| 1164 |
free(D); |
| 1165 |
|
| 1166 |
break; |
| 1167 |
case FIVEPOVERHANG: |
| 1168 |
/* |
| 1169 |
* does not scale, on the left side |
| 1170 |
* |
| 1171 |
* D[3]──────D[2] |
| 1172 |
* │ │ |
| 1173 |
* D[0]──────D[1] |
| 1174 |
* ┌────┐ ──────────── |
| 1175 |
* │ │ |
| 1176 |
* D[0]──D[1] |
| 1177 |
* |
| 1178 |
* |
| 1179 |
* |
| 1180 |
*/ |
| 1181 |
//width units are (B[2].x-B[3].x)/2 or (B[3].y-B[4].y)/2; |
| 1182 |
// the thickness is substituted with (AF[0].x - AF[1].x)/8 to make it scalable |
| 1183 |
// in the y with label length |
| 1184 |
D = gv_calloc(sides, sizeof(pointf)); |
| 1185 |
D[0].x = AF[1].x;//the very left edge |
| 1186 |
D[0].y = mid_y(&AF[1]) + (B[3].y-B[4].y)/8;//y_center + 1/4 width |
| 1187 |
D[1].x = D[0].x + 2*(B[2].x-B[3].x); |
| 1188 |
D[1].y = D[0].y; |
| 1189 |
D[2].x = D[1].x; |
| 1190 |
D[2].y = D[1].y + (B[3].y-B[4].y)/2; |
| 1191 |
D[3].x = D[0].x; |
| 1192 |
D[3].y = D[2].y; |
| 1193 |
gvrender_polygon(job, D, sides, filled); |
| 1194 |
|
| 1195 |
/*second, lower shape*/ |
| 1196 |
free(D); |
| 1197 |
D = gv_calloc(sides, sizeof(pointf)); |
| 1198 |
D[0].x = AF[1].x + (B[2].x-B[3].x); |
| 1199 |
D[0].y = mid_y(&AF[1]) - (B[3].y-B[4].y)*5/8; //y_center - 5/4 width |
| 1200 |
D[1].x = D[0].x + (B[2].x-B[3].x); |
| 1201 |
D[1].y = D[0].y; |
| 1202 |
D[2].x = D[1].x; |
| 1203 |
D[2].y = D[1].y + (B[3].y-B[4].y)/2; |
| 1204 |
D[3].x = D[0].x; |
| 1205 |
D[3].y = D[2].y; |
| 1206 |
gvrender_polygon(job, D, sides, filled); |
| 1207 |
|
| 1208 |
/*dsDNA line right half*/ |
| 1209 |
C[0].x = D[1].x; |
| 1210 |
C[0].y = mid_y(&AF[1]); |
| 1211 |
C[1].x = AF[0].x; |
| 1212 |
C[1].y = AF[2].y + (AF[0].y - AF[3].y)/2; |
| 1213 |
gvrender_polyline(job, C, 2); |
| 1214 |
free(D); |
| 1215 |
|
| 1216 |
break; |
| 1217 |
case THREEPOVERHANG: |
| 1218 |
/* |
| 1219 |
* does not scale, on the right side |
| 1220 |
* |
| 1221 |
* D[2]──────D[1] |
| 1222 |
* │ │ |
| 1223 |
* ─────── D[3]──────D[0] |
| 1224 |
* ┌────┐ D[1] |
| 1225 |
* │ │ |
| 1226 |
* D[3]──D[0] |
| 1227 |
* |
| 1228 |
* |
| 1229 |
* |
| 1230 |
*/ |
| 1231 |
//width units are (B[2].x-B[3].x)/2 or (B[3].y-B[4].y)/2; |
| 1232 |
// the thickness is substituted with (AF[0].x - AF[1].x)/8 to make it scalable |
| 1233 |
// in the y with label length |
| 1234 |
D = gv_calloc(sides, sizeof(pointf)); |
| 1235 |
D[0].x = AF[0].x;//the very right edge |
| 1236 |
D[0].y = mid_y(&AF[1]) + (B[3].y-B[4].y)/8;//y_center + 1/4 width |
| 1237 |
D[1].x = D[0].x; |
| 1238 |
D[1].y = D[0].y + (B[3].y-B[4].y)/2; |
| 1239 |
D[2].x = D[1].x - 2*(B[3].y-B[4].y); |
| 1240 |
D[2].y = D[1].y; |
| 1241 |
D[3].x = D[2].x; |
| 1242 |
D[3].y = D[0].y; |
| 1243 |
gvrender_polygon(job, D, sides, filled); |
| 1244 |
|
| 1245 |
/*second, lower shape*/ |
| 1246 |
free(D); |
| 1247 |
D = gv_calloc(sides, sizeof(pointf)); |
| 1248 |
D[0].x = AF[0].x - (B[2].x-B[3].x); |
| 1249 |
D[0].y = mid_y(&AF[1]) - (B[3].y-B[4].y)*5/8; //y_center - 5/4 width |
| 1250 |
D[1].x = D[0].x; |
| 1251 |
D[1].y = D[0].y + (B[3].y-B[4].y)/2; |
| 1252 |
D[2].x = D[1].x - (B[3].y-B[4].y); |
| 1253 |
D[2].y = D[1].y; |
| 1254 |
D[3].x = D[2].x; |
| 1255 |
D[3].y = D[0].y; |
| 1256 |
gvrender_polygon(job, D, sides, filled); |
| 1257 |
|
| 1258 |
/*dsDNA line left half*/ |
| 1259 |
C[0].x = AF[1].x; |
| 1260 |
C[0].y = mid_y(&AF[1]); |
| 1261 |
C[1].x = D[3].x; |
| 1262 |
C[1].y = AF[2].y + (AF[0].y - AF[3].y)/2; |
| 1263 |
gvrender_polyline(job, C, 2); |
| 1264 |
free(D); |
| 1265 |
|
| 1266 |
break; |
| 1267 |
case NOVERHANG: |
| 1268 |
/* |
| 1269 |
* does not scale |
| 1270 |
* |
| 1271 |
* D[3]──────D[2] D[3]──────D[2] |
| 1272 |
* │ │ │ │ |
| 1273 |
* ───D[0]──────D[1] D[0]──────D[1]──── |
| 1274 |
* D[3]──────D[2] D[3]──────D[2] |
| 1275 |
* │ │ │ │ |
| 1276 |
* D[0]──────D[1] D[0]──────D[1] |
| 1277 |
* |
| 1278 |
* |
| 1279 |
* |
| 1280 |
* |
| 1281 |
*/ |
| 1282 |
//width units are (B[2].x-B[3].x)/2 or (B[3].y-B[4].y)/2; |
| 1283 |
// the thickness is substituted with (AF[0].x - AF[1].x)/8 to make it scalable |
| 1284 |
// in the y with label length |
| 1285 |
/*upper left rectangle*/ |
| 1286 |
D = gv_calloc(sides, sizeof(pointf)); |
| 1287 |
D[0].x = mid_x(AF) - (B[2].x-B[3].x)*9/8; //x_center - 2*width - 1/4*width |
| 1288 |
D[0].y = mid_y(&AF[1]) + (B[3].y-B[4].y)/8;//y_center + 1/4 width |
| 1289 |
D[1].x = D[0].x + (B[2].x-B[3].x); |
| 1290 |
D[1].y = D[0].y; |
| 1291 |
D[2].x = D[1].x; |
| 1292 |
D[2].y = D[1].y + (B[3].y-B[4].y)/2; |
| 1293 |
D[3].x = D[0].x; |
| 1294 |
D[3].y = D[2].y; |
| 1295 |
gvrender_polygon(job, D, sides, filled); |
| 1296 |
|
| 1297 |
/*lower, left rectangle*/ |
| 1298 |
free(D); |
| 1299 |
D = gv_calloc(sides, sizeof(pointf)); |
| 1300 |
D[0].x = mid_x(AF) - (B[2].x-B[3].x)*9/8; //x_center - 2*width - 1/4*width |
| 1301 |
D[0].y = mid_y(&AF[1]) - (B[3].y-B[4].y)*5/8;//y_center - width - 1/4 width |
| 1302 |
D[1].x = D[0].x + (B[2].x-B[3].x); |
| 1303 |
D[1].y = D[0].y; |
| 1304 |
D[2].x = D[1].x; |
| 1305 |
D[2].y = D[1].y + (B[3].y-B[4].y)/2; |
| 1306 |
D[3].x = D[0].x; |
| 1307 |
D[3].y = D[2].y; |
| 1308 |
gvrender_polygon(job, D, sides, filled); |
| 1309 |
|
| 1310 |
/*lower, right rectangle*/ |
| 1311 |
free(D); |
| 1312 |
D = gv_calloc(sides, sizeof(pointf)); |
| 1313 |
D[0].x = mid_x(AF) + (B[2].x-B[3].x)/8; //x_center + 1/4*width |
| 1314 |
D[0].y = mid_y(&AF[1]) - (B[3].y-B[4].y)*5/8;//y_center - width - 1/4 width |
| 1315 |
D[1].x = D[0].x + (B[2].x-B[3].x); |
| 1316 |
D[1].y = D[0].y; |
| 1317 |
D[2].x = D[1].x; |
| 1318 |
D[2].y = D[1].y + (B[3].y-B[4].y)/2; |
| 1319 |
D[3].x = D[0].x; |
| 1320 |
D[3].y = D[2].y; |
| 1321 |
gvrender_polygon(job, D, sides, filled); |
| 1322 |
|
| 1323 |
/*upper, right rectangle*/ |
| 1324 |
free(D); |
| 1325 |
D = gv_calloc(sides, sizeof(pointf)); |
| 1326 |
D[0].x = mid_x(AF) + (B[2].x-B[3].x)/8; //x_center + 1/4*width |
| 1327 |
D[0].y = mid_y(&AF[1]) + (B[3].y-B[4].y)/8;//y_center - width - 1/4 width |
| 1328 |
D[1].x = D[0].x + (B[2].x-B[3].x); |
| 1329 |
D[1].y = D[0].y; |
| 1330 |
D[2].x = D[1].x; |
| 1331 |
D[2].y = D[1].y + (B[3].y-B[4].y)/2; |
| 1332 |
D[3].x = D[0].x; |
| 1333 |
D[3].y = D[2].y; |
| 1334 |
gvrender_polygon(job, D, sides, filled); |
| 1335 |
|
| 1336 |
/*dsDNA line right half*/ |
| 1337 |
C[0].x = D[1].x; |
| 1338 |
C[0].y = mid_y(&AF[1]); |
| 1339 |
C[1].x = AF[0].x; |
| 1340 |
C[1].y = AF[2].y + (AF[0].y - AF[3].y)/2; |
| 1341 |
gvrender_polyline(job, C, 2); |
| 1342 |
|
| 1343 |
/*dsDNA line left half*/ |
| 1344 |
C[0].x = mid_x(AF) - (B[2].x-B[3].x)*9/8; //D[0].x of of the left rectangles |
| 1345 |
C[0].y = mid_y(&AF[1]); |
| 1346 |
C[1].x = AF[1].x; |
| 1347 |
C[1].y = AF[2].y + (AF[0].y - AF[3].y)/2; |
| 1348 |
gvrender_polyline(job, C, 2); |
| 1349 |
free(D); |
| 1350 |
|
| 1351 |
break; |
| 1352 |
case ASSEMBLY: |
| 1353 |
/* |
| 1354 |
* does not scale |
| 1355 |
* |
| 1356 |
* D[3]──────────D[2] |
| 1357 |
* │ │ |
| 1358 |
* D[0]──────────D[1] |
| 1359 |
* ──── ───────── |
| 1360 |
* D[3]──────────D[2] |
| 1361 |
* │ │ |
| 1362 |
* D[0]──────────D[1] |
| 1363 |
* |
| 1364 |
*/ |
| 1365 |
//width units are (B[2].x-B[3].x)/2 or (B[3].y-B[4].y)/2; |
| 1366 |
// the thickness is substituted with (AF[0].x - AF[1].x)/8 to make it scalable |
| 1367 |
// in the y with label length |
| 1368 |
D = gv_calloc(sides, sizeof(pointf)); |
| 1369 |
D[0].x = mid_x(AF) - (B[2].x-B[3].x); //x_center - 2*width |
| 1370 |
D[0].y = mid_y(&AF[1]) + (B[3].y-B[4].y)/8;//y_center + 1/4 width |
| 1371 |
D[1].x = D[0].x + 2*(B[2].x-B[3].x); |
| 1372 |
D[1].y = D[0].y; |
| 1373 |
D[2].x = D[1].x; |
| 1374 |
D[2].y = D[1].y + (B[3].y-B[4].y)/2; |
| 1375 |
D[3].x = D[0].x; |
| 1376 |
D[3].y = D[2].y; |
| 1377 |
gvrender_polygon(job, D, sides, filled); |
| 1378 |
|
| 1379 |
/*second, lower shape*/ |
| 1380 |
free(D); |
| 1381 |
D = gv_calloc(sides, sizeof(pointf)); |
| 1382 |
D[0].x = mid_x(AF) - (B[2].x-B[3].x); //x_center - 2*width |
| 1383 |
D[0].y = mid_y(&AF[1]) - (B[3].y-B[4].y)*5/8;//y_center - width - 1/4 width |
| 1384 |
D[1].x = D[0].x + 2*(B[2].x-B[3].x); |
| 1385 |
D[1].y = D[0].y; |
| 1386 |
D[2].x = D[1].x; |
| 1387 |
D[2].y = D[1].y + (B[3].y-B[4].y)/2; |
| 1388 |
D[3].x = D[0].x; |
| 1389 |
D[3].y = D[2].y; |
| 1390 |
gvrender_polygon(job, D, sides, filled); |
| 1391 |
|
| 1392 |
/*dsDNA line right half*/ |
| 1393 |
C[0].x = D[1].x; |
| 1394 |
C[0].y = mid_y(&AF[1]); |
| 1395 |
C[1].x = AF[0].x; |
| 1396 |
C[1].y = AF[2].y + (AF[0].y - AF[3].y)/2; |
| 1397 |
gvrender_polyline(job, C, 2); |
| 1398 |
|
| 1399 |
/*dsDNA line left half*/ |
| 1400 |
C[0].x = AF[1].x; |
| 1401 |
C[0].y = mid_y(&AF[1]); |
| 1402 |
C[1].x = D[0].x; |
| 1403 |
C[1].y = AF[2].y + (AF[0].y - AF[3].y)/2; |
| 1404 |
gvrender_polyline(job, C, 2); |
| 1405 |
free(D); |
| 1406 |
|
| 1407 |
break; |
| 1408 |
case SIGNATURE: |
| 1409 |
/* |
| 1410 |
* |
| 1411 |
* |
| 1412 |
* ┌──────────────┐ |
| 1413 |
* │ │ |
| 1414 |
* │x │ |
| 1415 |
* │_____________ │ |
| 1416 |
* └──────────────┘ |
| 1417 |
*/ |
| 1418 |
//width units are (B[2].x-B[3].x)/2 or (B[3].y-B[4].y)/2; |
| 1419 |
// the thickness is substituted with (AF[0].x - AF[1].x)/8 to make it scalable |
| 1420 |
// in the y with label length |
| 1421 |
D = gv_calloc(sides, sizeof(pointf)); |
| 1422 |
D[0].x = AF[0].x; |
| 1423 |
D[0].y = B[1].y - (B[3].y - B[4].y)/2; |
| 1424 |
D[1].x = B[3].x; |
| 1425 |
D[1].y = B[3].y - (B[3].y - B[4].y)/2; |
| 1426 |
D[2].x = AF[2].x; |
| 1427 |
D[2].y = AF[2].y + (B[3].y - B[4].y)/2; |
| 1428 |
D[3].x = AF[0].x; |
| 1429 |
D[3].y = AF[2].y + (B[3].y - B[4].y)/2; |
| 1430 |
gvrender_polygon(job, D, sides, filled); |
| 1431 |
|
| 1432 |
/* "\" of the X*/ |
| 1433 |
C[0].x = AF[1].x + (B[2].x-B[3].x)/4; |
| 1434 |
C[0].y = mid_y(&AF[1]) + (B[3].y-B[4].y)/8; //y_center + 1/4 width |
| 1435 |
C[1].x = C[0].x + (B[2].x-B[3].x)/4;//C[0].x + width/2 |
| 1436 |
C[1].y = C[0].y - (B[3].y-B[4].y)/4;//C[0].y - width/2 |
| 1437 |
gvrender_polyline(job, C, 2); |
| 1438 |
|
| 1439 |
/*"/" of the X*/ |
| 1440 |
C[0].x = AF[1].x + (B[2].x-B[3].x)/4; |
| 1441 |
C[0].y = mid_y(&AF[1]) - (B[3].y-B[4].y)/8; //y_center - 1/4 width |
| 1442 |
C[1].x = C[0].x + (B[2].x-B[3].x)/4;//C[0].x + width/2 |
| 1443 |
C[1].y = C[0].y + (B[3].y-B[4].y)/4;//C[0].y + width/2 |
| 1444 |
gvrender_polyline(job, C, 2); |
| 1445 |
|
| 1446 |
/*bottom line*/ |
| 1447 |
C[0].x = AF[1].x + (B[2].x-B[3].x)/4; |
| 1448 |
C[0].y = AF[2].y + (B[3].y-B[4].y)*3/4; |
| 1449 |
C[1].x = AF[0].x - (B[2].x-B[3].x)/4; |
| 1450 |
C[1].y = C[0].y; |
| 1451 |
gvrender_polyline(job, C, 2); |
| 1452 |
free(D); |
| 1453 |
|
| 1454 |
break; |
| 1455 |
case INSULATOR: |
| 1456 |
/* |
| 1457 |
* double square |
| 1458 |
* |
| 1459 |
* ┌─────┐ |
| 1460 |
*──┤ ┌─┐ ├─── |
| 1461 |
* │ └─┘ │ |
| 1462 |
* └─────┘ |
| 1463 |
* |
| 1464 |
*/ |
| 1465 |
//width units are (B[2].x-B[3].x)/2 or (B[3].y-B[4].y)/2; |
| 1466 |
D = gv_calloc(sides, sizeof(pointf)); |
| 1467 |
D[0].x = mid_x(AF) + (B[2].x-B[3].x)/2; //x_center+width |
| 1468 |
D[0].y = mid_y(&AF[1]) + (B[2].x-B[3].x)/2; |
| 1469 |
D[1].x = D[0].x; |
| 1470 |
D[1].y = mid_y(&AF[1]) - (B[2].x-B[3].x)/2; //D[0].y- width |
| 1471 |
D[2].x = mid_x(AF) - (B[2].x-B[3].x)/2; //x_center-width |
| 1472 |
D[2].y = D[1].y; |
| 1473 |
D[3].x = D[2].x; |
| 1474 |
D[3].y = D[0].y; |
| 1475 |
gvrender_polygon(job, D, sides, filled); |
| 1476 |
free(D); |
| 1477 |
|
| 1478 |
/*outer square line*/ |
| 1479 |
C[0].x = mid_x(AF) + (B[2].x-B[3].x)*3/4; //x_center+1.5*width |
| 1480 |
C[0].y = mid_y(&AF[1]) + (B[2].x-B[3].x)*3/4; //y_center |
| 1481 |
C[1].x = C[0].x; |
| 1482 |
C[1].y = mid_y(&AF[1]) - (B[2].x-B[3].x)*3/4; //y_center- 1.5*width |
| 1483 |
C[2].x = mid_x(AF) - (B[2].x-B[3].x)*3/4; //x_center-1.5*width |
| 1484 |
C[2].y = C[1].y; |
| 1485 |
C[3].x = C[2].x; |
| 1486 |
C[3].y = C[0].y; |
| 1487 |
C[4] = C[0]; |
| 1488 |
gvrender_polyline(job, C, 5); |
| 1489 |
|
| 1490 |
/*dsDNA line right half*/ |
| 1491 |
C[0].x = mid_x(AF) + (B[2].x-B[3].x)*3/4; |
| 1492 |
C[0].y = mid_y(&AF[1]); |
| 1493 |
C[1].x = AF[0].x; |
| 1494 |
C[1].y = AF[2].y + (AF[0].y - AF[3].y)/2; |
| 1495 |
gvrender_polyline(job, C, 2); |
| 1496 |
|
| 1497 |
/*dsDNA line left half*/ |
| 1498 |
C[0].x = AF[1].x; |
| 1499 |
C[0].y = mid_y(&AF[1]); |
| 1500 |
C[1].x = mid_x(AF) - (B[2].x-B[3].x)*3/4; |
| 1501 |
C[1].y = AF[2].y + (AF[0].y - AF[3].y)/2; |
| 1502 |
gvrender_polyline(job, C, 2); |
| 1503 |
|
| 1504 |
break; |
| 1505 |
case RIBOSITE: |
| 1506 |
/* |
| 1507 |
* X with a dashed line on the bottom |
| 1508 |
* |
| 1509 |
* |
| 1510 |
* X |
| 1511 |
* ╎ |
| 1512 |
* ─────┴────── |
| 1513 |
*/ |
| 1514 |
//width units are (B[2].x-B[3].x)/2 or (B[3].y-B[4].y)/2; |
| 1515 |
|
| 1516 |
D = gv_calloc(sides + 12, sizeof(pointf)); // 12-sided x |
| 1517 |
D[0].x = mid_x(AF) + (B[2].x-B[3].x)/4; //x_center+width/2 , lower right corner of the x |
| 1518 |
D[0].y = mid_y(&AF[1]) + (B[3].y-B[4].y)/2; //y_center + width |
| 1519 |
D[1].x = D[0].x; |
| 1520 |
D[1].y = D[0].y + (B[3].y-B[4].y)/8; //D[0].y +width/4 |
| 1521 |
D[2].x = D[0].x - (B[2].x-B[3].x)/8; //D[0].x- width/4 //right nook of the x |
| 1522 |
D[2].y = D[1].y + (B[3].y-B[4].y)/8; //D[0].y+width/2 or D[1].y+width/4 |
| 1523 |
D[3].x = D[0].x; |
| 1524 |
D[3].y = D[2].y + (B[3].y-B[4].y)/8; //D[2].y + width/4 |
| 1525 |
D[4].x = D[0].x; |
| 1526 |
D[4].y = D[3].y + (B[3].y-B[4].y)/8; //top right corner of the x |
| 1527 |
D[5].x = D[2].x; |
| 1528 |
D[5].y = D[4].y; |
| 1529 |
D[6].x = mid_x(AF); |
| 1530 |
D[6].y = D[3].y; //top nook |
| 1531 |
D[7].x = D[6].x - (B[2].x-B[3].x)/8; //D[5] mirrored across y |
| 1532 |
D[7].y = D[5].y; |
| 1533 |
D[8].x = D[7].x - (B[2].x-B[3].x)/8;//top left corner |
| 1534 |
D[8].y = D[7].y; |
| 1535 |
D[9].x = D[8].x; |
| 1536 |
D[9].y = D[3].y; |
| 1537 |
D[10].x = D[8].x + (B[2].x-B[3].x)/8; |
| 1538 |
D[10].y = D[2].y; |
| 1539 |
D[11].x = D[8].x; |
| 1540 |
D[11].y = D[1].y; |
| 1541 |
D[12].x = D[8].x; |
| 1542 |
D[12].y = D[0].y; |
| 1543 |
D[13].x = D[10].x; |
| 1544 |
D[13].y = D[12].y; |
| 1545 |
D[14].x = D[6].x; //bottom nook |
| 1546 |
D[14].y = D[1].y; |
| 1547 |
D[15].x = D[2].x; |
| 1548 |
D[15].y = D[0].y; |
| 1549 |
gvrender_polygon(job, D, sides + 12, filled); |
| 1550 |
|
| 1551 |
//2-part dash line |
| 1552 |
|
| 1553 |
/*line below the x, bottom dash*/ |
| 1554 |
C[0].x = D[14].x; //x_center |
| 1555 |
C[0].y = mid_y(&AF[1]); |
| 1556 |
C[1].x = C[0].x; |
| 1557 |
C[1].y = C[0].y + (B[3].y-B[4].y)/8; //y_center + 1/4*width |
| 1558 |
gvrender_polyline(job, C, 2); |
| 1559 |
|
| 1560 |
/*line below the x, top dash*/ |
| 1561 |
C[0].x = D[14].x; //x_center |
| 1562 |
C[0].y = mid_y(&AF[1]) + (B[3].y-B[4].y)/4; |
| 1563 |
C[1].x = C[0].x; |
| 1564 |
C[1].y = C[0].y + (B[3].y-B[4].y)/8; |
| 1565 |
gvrender_polyline(job, C, 2); |
| 1566 |
|
| 1567 |
/*dsDNA line*/ |
| 1568 |
C[0].x = AF[1].x; |
| 1569 |
C[0].y = mid_y(&AF[1]); |
| 1570 |
C[1].x = AF[0].x; |
| 1571 |
C[1].y = AF[2].y + (AF[0].y - AF[3].y)/2; |
| 1572 |
gvrender_polyline(job, C, 2); |
| 1573 |
free(D); |
| 1574 |
|
| 1575 |
break; |
| 1576 |
case RNASTAB: |
| 1577 |
/* |
| 1578 |
* octagon with a dashed line on the bottom |
| 1579 |
* |
| 1580 |
* |
| 1581 |
* O |
| 1582 |
* ╎ |
| 1583 |
* ─────┴────── |
| 1584 |
*/ |
| 1585 |
//width units are (B[2].x-B[3].x)/2 or (B[3].y-B[4].y)/2; |
| 1586 |
|
| 1587 |
D = gv_calloc(sides + 4, sizeof(pointf)); // 12-sided x |
| 1588 |
D[0].x = mid_x(AF) + (B[2].x-B[3].x)/8; //x_center+width/8 , lower right corner of the hexagon |
| 1589 |
D[0].y = mid_y(&AF[1]) + (B[3].y-B[4].y)/2; //y_center + width |
| 1590 |
D[1].x = D[0].x + (B[2].x-B[3].x)/8; |
| 1591 |
D[1].y = D[0].y + (B[3].y-B[4].y)/8; //D[0].y +width/4 |
| 1592 |
D[2].x = D[1].x; //D[0].x- width/4 |
| 1593 |
D[2].y = D[1].y + (B[3].y-B[4].y)/4; //D[1].y+width/2 |
| 1594 |
D[3].x = D[0].x; |
| 1595 |
D[3].y = D[2].y + (B[3].y-B[4].y)/8; //D[2].y + width/4 |
| 1596 |
D[4].x = D[3].x - (B[2].x-B[3].x)/4; |
| 1597 |
D[4].y = D[3].y; //top of the hexagon |
| 1598 |
D[5].x = D[4].x - (B[2].x-B[3].x)/8; |
| 1599 |
D[5].y = D[2].y; |
| 1600 |
D[6].x = D[5].x; |
| 1601 |
D[6].y = D[1].y; //left side |
| 1602 |
D[7].x = D[4].x; |
| 1603 |
D[7].y = D[0].y; //bottom |
| 1604 |
gvrender_polygon(job, D, sides + 4, filled); |
| 1605 |
|
| 1606 |
//2-part dash line |
| 1607 |
|
| 1608 |
/*line below the x, bottom dash*/ |
| 1609 |
C[0].x = mid_x(AF); |
| 1610 |
C[0].y = mid_y(&AF[1]); |
| 1611 |
C[1].x = C[0].x; |
| 1612 |
C[1].y = C[0].y + (B[3].y-B[4].y)/8; //y_center + 1/4*width |
| 1613 |
gvrender_polyline(job, C, 2); |
| 1614 |
|
| 1615 |
/*line below the x, top dash*/ |
| 1616 |
C[0].x = mid_x(AF); |
| 1617 |
C[0].y = mid_y(&AF[1]) + (B[3].y-B[4].y)/4; |
| 1618 |
C[1].x = C[0].x; |
| 1619 |
C[1].y = C[0].y + (B[3].y-B[4].y)/8; |
| 1620 |
gvrender_polyline(job, C, 2); |
| 1621 |
|
| 1622 |
|
| 1623 |
|
| 1624 |
/*dsDNA line*/ |
| 1625 |
C[0].x = AF[1].x; |
| 1626 |
C[0].y = mid_y(&AF[1]); |
| 1627 |
C[1].x = AF[0].x; |
| 1628 |
C[1].y = AF[2].y + (AF[0].y - AF[3].y)/2; |
| 1629 |
gvrender_polyline(job, C, 2); |
| 1630 |
free(D); |
| 1631 |
|
| 1632 |
break; |
| 1633 |
case PROTEASESITE: |
| 1634 |
/* |
| 1635 |
* X with a solid line on the bottom |
| 1636 |
* |
| 1637 |
* |
| 1638 |
* X |
| 1639 |
* │ |
| 1640 |
* ─────┴────── |
| 1641 |
*/ |
| 1642 |
//width units are (B[2].x-B[3].x)/2 or (B[3].y-B[4].y)/2; |
| 1643 |
D = gv_calloc(sides + 12, sizeof(pointf)); // 12-sided x |
| 1644 |
D[0].x = mid_x(AF) + (B[2].x-B[3].x)/4; //x_center+width/2 , lower right corner of the x |
| 1645 |
D[0].y = mid_y(&AF[1]) + (B[3].y-B[4].y)/2; //y_center + width |
| 1646 |
D[1].x = D[0].x; |
| 1647 |
D[1].y = D[0].y + (B[3].y-B[4].y)/8; //D[0].y +width/4 |
| 1648 |
D[2].x = D[0].x - (B[2].x-B[3].x)/8; //D[0].x- width/4 //right nook of the x |
| 1649 |
D[2].y = D[1].y + (B[3].y-B[4].y)/8; //D[0].y+width/2 or D[1].y+width/4 |
| 1650 |
D[3].x = D[0].x; |
| 1651 |
D[3].y = D[2].y + (B[3].y-B[4].y)/8; //D[2].y + width/4 |
| 1652 |
D[4].x = D[0].x; |
| 1653 |
D[4].y = D[3].y + (B[3].y-B[4].y)/8; //top right corner of the x |
| 1654 |
D[5].x = D[2].x; |
| 1655 |
D[5].y = D[4].y; |
| 1656 |
D[6].x = mid_x(AF); |
| 1657 |
D[6].y = D[3].y; //top nook |
| 1658 |
D[7].x = D[6].x - (B[2].x-B[3].x)/8; //D[5] mirrored across y |
| 1659 |
D[7].y = D[5].y; |
| 1660 |
D[8].x = D[7].x - (B[2].x-B[3].x)/8;//top left corner |
| 1661 |
D[8].y = D[7].y; |
| 1662 |
D[9].x = D[8].x; |
| 1663 |
D[9].y = D[3].y; |
| 1664 |
D[10].x = D[8].x + (B[2].x-B[3].x)/8; |
| 1665 |
D[10].y = D[2].y; |
| 1666 |
D[11].x = D[8].x; |
| 1667 |
D[11].y = D[1].y; |
| 1668 |
D[12].x = D[8].x; |
| 1669 |
D[12].y = D[0].y; |
| 1670 |
D[13].x = D[10].x; |
| 1671 |
D[13].y = D[12].y; |
| 1672 |
D[14].x = D[6].x; //bottom nook |
| 1673 |
D[14].y = D[1].y; |
| 1674 |
D[15].x = D[2].x; |
| 1675 |
D[15].y = D[0].y; |
| 1676 |
gvrender_polygon(job, D, sides + 12, filled); |
| 1677 |
|
| 1678 |
|
| 1679 |
/*line below the x*/ |
| 1680 |
C[0] = D[14]; |
| 1681 |
C[1].x = C[0].x; |
| 1682 |
C[1].y = mid_y(&AF[1]); |
| 1683 |
gvrender_polyline(job, C, 2); |
| 1684 |
|
| 1685 |
/*dsDNA line*/ |
| 1686 |
C[0].x = AF[1].x; |
| 1687 |
C[0].y = mid_y(&AF[1]); |
| 1688 |
C[1].x = AF[0].x; |
| 1689 |
C[1].y = AF[2].y + (AF[0].y - AF[3].y)/2; |
| 1690 |
gvrender_polyline(job, C, 2); |
| 1691 |
free(D); |
| 1692 |
|
| 1693 |
break; |
| 1694 |
case PROTEINSTAB: |
| 1695 |
/* |
| 1696 |
* octagon with a solid line on the bottom |
| 1697 |
* |
| 1698 |
* |
| 1699 |
* O |
| 1700 |
* │ |
| 1701 |
* ─────┴────── |
| 1702 |
*/ |
| 1703 |
//width units are (B[2].x-B[3].x)/2 or (B[3].y-B[4].y)/2; |
| 1704 |
|
| 1705 |
D = gv_calloc(sides + 4, sizeof(pointf)); // 12-sided x |
| 1706 |
D[0].x = mid_x(AF) + (B[2].x-B[3].x)/8; //x_center+width/8 , lower right corner of the hexagon |
| 1707 |
D[0].y = mid_y(&AF[1]) + (B[3].y-B[4].y)/2; //y_center + width |
| 1708 |
D[1].x = D[0].x + (B[2].x-B[3].x)/8; |
| 1709 |
D[1].y = D[0].y + (B[3].y-B[4].y)/8; //D[0].y +width/4 |
| 1710 |
D[2].x = D[1].x; //D[0].x- width/4 |
| 1711 |
D[2].y = D[1].y + (B[3].y-B[4].y)/4; //D[1].y+width/2 |
| 1712 |
D[3].x = D[0].x; |
| 1713 |
D[3].y = D[2].y + (B[3].y-B[4].y)/8; //D[2].y + width/4 |
| 1714 |
D[4].x = D[3].x - (B[2].x-B[3].x)/4; |
| 1715 |
D[4].y = D[3].y; //top of the hexagon |
| 1716 |
D[5].x = D[4].x - (B[2].x-B[3].x)/8; |
| 1717 |
D[5].y = D[2].y; |
| 1718 |
D[6].x = D[5].x; |
| 1719 |
D[6].y = D[1].y; //left side |
| 1720 |
D[7].x = D[4].x; |
| 1721 |
D[7].y = D[0].y; //bottom |
| 1722 |
gvrender_polygon(job, D, sides + 4, filled); |
| 1723 |
|
| 1724 |
/*line below the x*/ |
| 1725 |
C[0].x = mid_x(AF); |
| 1726 |
C[0].y = D[0].y; |
| 1727 |
C[1].x = C[0].x; |
| 1728 |
C[1].y = mid_y(&AF[1]); |
| 1729 |
gvrender_polyline(job, C, 2); |
| 1730 |
|
| 1731 |
/*dsDNA line*/ |
| 1732 |
C[0].x = AF[1].x; |
| 1733 |
C[0].y = mid_y(&AF[1]); |
| 1734 |
C[1].x = AF[0].x; |
| 1735 |
C[1].y = AF[2].y + (AF[0].y - AF[3].y)/2; |
| 1736 |
gvrender_polyline(job, C, 2); |
| 1737 |
free(D); |
| 1738 |
|
| 1739 |
break; |
| 1740 |
|
| 1741 |
case RPROMOTER: |
| 1742 |
/* |
| 1743 |
* Adjust the perimeter for the protrusions. |
| 1744 |
* |
| 1745 |
* |
| 1746 |
* D[1] = AF[1] │╲ |
| 1747 |
* ×────────────────× ╲ |
| 1748 |
* │ D[0] ╲ |
| 1749 |
* │ ╲ |
| 1750 |
* │ ╱ |
| 1751 |
* │ ╱ |
| 1752 |
* │ ┌───────┐ ╱ |
| 1753 |
* │ │ │╱ |
| 1754 |
* └────────┘ |
| 1755 |
*/ |
| 1756 |
/* Add the tab edges. */ |
| 1757 |
D = gv_calloc(sides + 5, sizeof(pointf)); // 5 new points |
| 1758 |
D[0].x = B[1].x - (B[2].x - B[3].x)/2; |
| 1759 |
D[0].y = B[1].y - (B[3].y - B[4].y)/2; |
| 1760 |
D[1].x = B[3].x; |
| 1761 |
D[1].y = B[3].y - (B[3].y - B[4].y)/2; |
| 1762 |
D[2].x = AF[2].x; |
| 1763 |
D[2].y = AF[2].y; |
| 1764 |
D[3].x = B[2].x + (B[2].x - B[3].x)/2; |
| 1765 |
D[3].y = AF[2].y; |
| 1766 |
D[4].x = B[2].x + (B[2].x - B[3].x)/2; |
| 1767 |
D[4].y = AF[2].y + (B[3].y - B[4].y)/2; |
| 1768 |
D[5].x = B[1].x - (B[2].x - B[3].x)/2; |
| 1769 |
D[5].y = AF[2].y + (B[3].y - B[4].y)/2; |
| 1770 |
D[6].x = B[1].x - (B[2].x - B[3].x)/2; |
| 1771 |
D[6].y = AF[3].y; |
| 1772 |
D[7].y = AF[0].y - (AF[0].y - AF[3].y)/2; /*triangle point */ |
| 1773 |
D[7].x = AF[0].x; /*triangle point */ |
| 1774 |
D[8].y = AF[0].y; |
| 1775 |
D[8].x = B[1].x - (B[2].x - B[3].x)/2; |
| 1776 |
|
| 1777 |
gvrender_polygon(job, D, sides + 5, filled); |
| 1778 |
free(D); |
| 1779 |
break; |
| 1780 |
|
| 1781 |
case RARROW: |
| 1782 |
/* |
| 1783 |
* Adjust the perimeter for the protrusions. |
| 1784 |
* |
| 1785 |
* |
| 1786 |
* D[1] = AF[1] │╲ |
| 1787 |
* ×────────────────× ╲ |
| 1788 |
* │ D[0] ╲ |
| 1789 |
* │ ╲ |
| 1790 |
* │ ╱ |
| 1791 |
* │ ╱ |
| 1792 |
* └────────────────┐ ╱ |
| 1793 |
* │╱ |
| 1794 |
* |
| 1795 |
*/ |
| 1796 |
/* Add the tab edges. */ |
| 1797 |
D = gv_calloc(sides + 3, sizeof(pointf)); // 3 new points |
| 1798 |
D[0].x = B[1].x - (B[2].x - B[3].x)/2; |
| 1799 |
D[0].y = B[1].y - (B[3].y - B[4].y)/2; |
| 1800 |
D[1].x = B[3].x; |
| 1801 |
D[1].y = B[3].y - (B[3].y - B[4].y)/2; |
| 1802 |
D[2].x = AF[2].x; |
| 1803 |
D[2].y = AF[2].y + (B[3].y - B[4].y)/2; |
| 1804 |
D[3].x = B[1].x - (B[2].x - B[3].x)/2; |
| 1805 |
D[3].y = AF[2].y + (B[3].y - B[4].y)/2; |
| 1806 |
D[4].x = B[1].x - (B[2].x - B[3].x)/2; |
| 1807 |
D[4].y = AF[3].y; |
| 1808 |
D[5].y = AF[0].y - (AF[0].y - AF[3].y)/2;/*triangle point*/ |
| 1809 |
D[5].x = AF[0].x; /*triangle point */ |
| 1810 |
D[6].y = AF[0].y; |
| 1811 |
D[6].x = B[1].x - (B[2].x - B[3].x)/2; |
| 1812 |
|
| 1813 |
gvrender_polygon(job, D, sides + 3, filled); |
| 1814 |
free(D); |
| 1815 |
break; |
| 1816 |
|
| 1817 |
case LARROW: |
| 1818 |
/* |
| 1819 |
* Adjust the perimeter for the protrusions. |
| 1820 |
* |
| 1821 |
* |
| 1822 |
* ╱│ |
| 1823 |
* ╱ └────────────────┐ |
| 1824 |
* ╱ │ |
| 1825 |
* ╲ │ |
| 1826 |
* ╲ ┌────────────────┘ |
| 1827 |
* ╲│ |
| 1828 |
* |
| 1829 |
*/ |
| 1830 |
/* Add the tab edges. */ |
| 1831 |
D = gv_calloc(sides + 3, sizeof(pointf)); // 3 new points |
| 1832 |
D[0].x = AF[0].x; |
| 1833 |
D[0].y = AF[0].y - (B[3].y-B[4].y)/2; |
| 1834 |
D[1].x = B[2].x + (B[2].x - B[3].x)/2; |
| 1835 |
D[1].y = AF[0].y - (B[3].y-B[4].y)/2;/*D[0].y*/ |
| 1836 |
D[2].x = B[2].x + (B[2].x - B[3].x)/2;/*D[1].x*/ |
| 1837 |
D[2].y = B[2].y; |
| 1838 |
D[3].x = AF[1].x; /*triangle point*/ |
| 1839 |
D[3].y = AF[1].y - (AF[1].y - AF[2].y)/2; /*triangle point*/ |
| 1840 |
D[4].x = B[2].x + (B[2].x - B[3].x)/2;/*D[1].x*/ |
| 1841 |
D[4].y = AF[2].y; |
| 1842 |
D[5].y = AF[2].y + (B[3].y-B[4].y)/2; |
| 1843 |
D[5].x = B[2].x + (B[2].x - B[3].x)/2;/*D[1].x*/ |
| 1844 |
D[6].y = AF[3].y + (B[3].y - B[4].y)/2; |
| 1845 |
D[6].x = AF[0].x;/*D[0]*/ |
| 1846 |
|
| 1847 |
gvrender_polygon(job, D, sides + 3, filled); |
| 1848 |
free(D); |
| 1849 |
break; |
| 1850 |
|
| 1851 |
case LPROMOTER: |
| 1852 |
/* |
| 1853 |
* Adjust the perimeter for the protrusions. |
| 1854 |
* |
| 1855 |
* |
| 1856 |
* ╱│ |
| 1857 |
* ╱ └────────────────× |
| 1858 |
* ╱ D[0] |
| 1859 |
* ╱ │ |
| 1860 |
* ╲ │ |
| 1861 |
* ╲ │ |
| 1862 |
* ╲ ┌────────┐ │ |
| 1863 |
* ╲│ │ │ |
| 1864 |
* └───────┘ |
| 1865 |
*/ |
| 1866 |
/* Add the tab edges. */ |
| 1867 |
D = gv_calloc(sides + 5, sizeof(pointf)); // 3 new points |
| 1868 |
D[0].x = AF[0].x; |
| 1869 |
D[0].y = AF[0].y - (B[3].y-B[4].y)/2; |
| 1870 |
D[1].x = B[2].x + (B[2].x - B[3].x)/2; |
| 1871 |
D[1].y = AF[0].y - (B[3].y-B[4].y)/2;/*D[0].y*/ |
| 1872 |
D[2].x = B[2].x + (B[2].x - B[3].x)/2;/*D[1].x*/ |
| 1873 |
D[2].y = B[2].y; |
| 1874 |
D[3].x = AF[1].x; /*triangle point*/ |
| 1875 |
D[3].y = AF[1].y - (AF[1].y - AF[2].y)/2; /*triangle point*/ |
| 1876 |
D[4].x = B[2].x + (B[2].x - B[3].x)/2;/*D[1].x*/ |
| 1877 |
D[4].y = AF[2].y; |
| 1878 |
D[5].y = AF[2].y + (B[3].y-B[4].y)/2; |
| 1879 |
D[5].x = B[2].x + (B[2].x - B[3].x)/2;/*D[1].x*/ |
| 1880 |
D[6].y = AF[3].y + (B[3].y - B[4].y)/2; |
| 1881 |
D[6].x = B[1].x - (B[2].x - B[3].x)/2; |
| 1882 |
D[7].x = B[1].x - (B[2].x - B[3].x)/2;/*D[6].x*/ |
| 1883 |
D[7].y = AF[3].y; |
| 1884 |
D[8].x = AF[3].x; |
| 1885 |
D[8].y = AF[3].y; |
| 1886 |
|
| 1887 |
gvrender_polygon(job, D, sides + 5, filled); |
| 1888 |
free(D); |
| 1889 |
break; |
| 1890 |
} |
| 1891 |
free(B); |
| 1892 |
} |
| 1893 |
|
| 1894 |
/*=============================poly start=========================*/ |
| 1895 |
|
| 1896 |
/* userSize; |
| 1897 |
* Return maximum size, in points, of width and height supplied |
| 1898 |
* by user, if any. Return 0 otherwise. |
| 1899 |
*/ |
| 1900 |
static double userSize(node_t * n) |
| 1901 |
{ |
| 1902 |
double w, h; |
| 1903 |
w = late_double(n, N_width, 0.0, MIN_NODEWIDTH); |
| 1904 |
h = late_double(n, N_height, 0.0, MIN_NODEHEIGHT); |
| 1905 |
return INCH2PS(fmax(w, h)); |
| 1906 |
} |
| 1907 |
|
| 1908 |
shape_kind shapeOf(node_t * n) |
| 1909 |
{ |
| 1910 |
shape_desc *sh = ND_shape(n); |
| 1911 |
void (*ifn) (node_t *); |
| 1912 |
|
| 1913 |
if (!sh) |
| 1914 |
return SH_UNSET; |
| 1915 |
ifn = ND_shape(n)->fns->initfn; |
| 1916 |
if (ifn == poly_init) |
| 1917 |
return SH_POLY; |
| 1918 |
else if (ifn == record_init) |
| 1919 |
return SH_RECORD; |
| 1920 |
else if (ifn == point_init) |
| 1921 |
return SH_POINT; |
| 1922 |
else if (ifn == epsf_init) |
| 1923 |
return SH_EPSF; |
| 1924 |
else |
| 1925 |
return SH_UNSET; |
| 1926 |
} |
| 1927 |
|
| 1928 |
bool isPolygon(node_t * n) |
| 1929 |
{ |
| 1930 |
return ND_shape(n) && ND_shape(n)->fns->initfn == poly_init; |
| 1931 |
} |
| 1932 |
|
| 1933 |
static void poly_init(node_t * n) |
| 1934 |
{ |
| 1935 |
pointf dimen, min_bb; |
| 1936 |
pointf outline_bb; |
| 1937 |
point imagesize; |
| 1938 |
pointf *vertices; |
| 1939 |
char *p, *sfile, *fxd; |
| 1940 |
double temp, alpha, beta, gamma; |
| 1941 |
double orientation, distortion, skew; |
| 1942 |
double scalex, scaley; |
| 1943 |
double width, height, marginx, marginy, spacex; |
| 1944 |
polygon_t *poly = gv_alloc(sizeof(polygon_t)); |
| 1945 |
bool isPlain = IS_PLAIN(n); |
| 1946 |
|
| 1947 |
bool regular = !!ND_shape(n)->polygon->regular; |
| 1948 |
size_t peripheries = ND_shape(n)->polygon->peripheries; |
| 1949 |
size_t sides = ND_shape(n)->polygon->sides; |
| 1950 |
orientation = ND_shape(n)->polygon->orientation; |
| 1951 |
skew = ND_shape(n)->polygon->skew; |
| 1952 |
distortion = ND_shape(n)->polygon->distortion; |
| 1953 |
regular |= mapbool(agget(n, "regular")); |
| 1954 |
|
| 1955 |
/* all calculations in floating point POINTS */ |
| 1956 |
|
| 1957 |
/* make x and y dimensions equal if node is regular |
| 1958 |
* If the user has specified either width or height, use the max. |
| 1959 |
* Else use minimum default value. |
| 1960 |
* If node is not regular, use the current width and height. |
| 1961 |
*/ |
| 1962 |
if (isPlain) { |
| 1963 |
width = height = 0; |
| 1964 |
} |
| 1965 |
else if (regular) { |
| 1966 |
double sz = userSize(n); |
| 1967 |
if (sz > 0.0) |
| 1968 |
width = height = sz; |
| 1969 |
else { |
| 1970 |
width = ND_width(n); |
| 1971 |
height = ND_height(n); |
| 1972 |
width = height = INCH2PS(fmin(width, height)); |
| 1973 |
} |
| 1974 |
} else { |
| 1975 |
width = INCH2PS(ND_width(n)); |
| 1976 |
height = INCH2PS(ND_height(n)); |
| 1977 |
} |
| 1978 |
|
| 1979 |
peripheries = (size_t)late_int(n, N_peripheries, (int)peripheries, 0); |
| 1980 |
orientation += late_double(n, N_orientation, 0.0, -360.0); |
| 1981 |
if (sides == 0) { /* not for builtins */ |
| 1982 |
skew = late_double(n, N_skew, 0.0, -100.0); |
| 1983 |
sides = (size_t)late_int(n, N_sides, 4, 0); |
| 1984 |
distortion = late_double(n, N_distortion, 0.0, -100.0); |
| 1985 |
} |
| 1986 |
|
| 1987 |
/* get label dimensions */ |
| 1988 |
dimen = ND_label(n)->dimen; |
| 1989 |
|
| 1990 |
/* minimal whitespace around label */ |
| 1991 |
if (dimen.x > 0 || dimen.y > 0) { |
| 1992 |
/* padding */ |
| 1993 |
if (!isPlain) { |
| 1994 |
if ((p = agget(n, "margin"))) { |
| 1995 |
marginx = marginy = 0; |
| 1996 |
const int i = sscanf(p, "%lf,%lf", &marginx, &marginy); |
| 1997 |
marginx = fmax(marginx, 0); |
| 1998 |
marginy = fmax(marginy, 0); |
| 1999 |
if (i > 0) { |
| 2000 |
dimen.x += 2 * INCH2PS(marginx); |
| 2001 |
if (i > 1) |
| 2002 |
dimen.y += 2 * INCH2PS(marginy); |
| 2003 |
else |
| 2004 |
dimen.y += 2 * INCH2PS(marginx); |
| 2005 |
} else |
| 2006 |
PAD(dimen); |
| 2007 |
} else |
| 2008 |
PAD(dimen); |
| 2009 |
} |
| 2010 |
} |
| 2011 |
spacex = dimen.x - ND_label(n)->dimen.x; |
| 2012 |
|
| 2013 |
/* quantization */ |
| 2014 |
if ((temp = GD_drawing(agraphof(n))->quantum) > 0.0) { |
| 2015 |
temp = INCH2PS(temp); |
| 2016 |
dimen.x = quant(dimen.x, temp); |
| 2017 |
dimen.y = quant(dimen.y, temp); |
| 2018 |
} |
| 2019 |
|
| 2020 |
imagesize.x = imagesize.y = 0; |
| 2021 |
if (ND_shape(n)->usershape) { |
| 2022 |
/* custom requires a shapefile |
| 2023 |
* not custom is an adaptable user shape such as a postscript |
| 2024 |
* function. |
| 2025 |
*/ |
| 2026 |
if (streq(ND_shape(n)->name, "custom")) { |
| 2027 |
sfile = agget(n, "shapefile"); |
| 2028 |
imagesize = gvusershape_size(agraphof(n), sfile); |
| 2029 |
if (imagesize.x == -1 && imagesize.y == -1) { |
| 2030 |
agwarningf( |
| 2031 |
"No or improper shapefile=\"%s\" for node \"%s\"\n", |
| 2032 |
sfile ? sfile : "<nil>", agnameof(n)); |
| 2033 |
imagesize.x = imagesize.y = 0; |
| 2034 |
} else { |
| 2035 |
GD_has_images(agraphof(n)) = true; |
| 2036 |
imagesize.x += 2; /* some fixed padding */ |
| 2037 |
imagesize.y += 2; |
| 2038 |
} |
| 2039 |
} |
| 2040 |
} else if ((sfile = agget(n, "image")) && *sfile != '\0') { |
| 2041 |
imagesize = gvusershape_size(agraphof(n), sfile); |
| 2042 |
if (imagesize.x == -1 && imagesize.y == -1) { |
| 2043 |
agwarningf( |
| 2044 |
"No or improper image=\"%s\" for node \"%s\"\n", |
| 2045 |
sfile ? sfile : "<nil>", agnameof(n)); |
| 2046 |
imagesize.x = imagesize.y = 0; |
| 2047 |
} else { |
| 2048 |
GD_has_images(agraphof(n)) = true; |
| 2049 |
imagesize.x += 2; /* some fixed padding */ |
| 2050 |
imagesize.y += 2; |
| 2051 |
} |
| 2052 |
} |
| 2053 |
|
| 2054 |
/* initialize node bb to labelsize */ |
| 2055 |
pointf bb = {.x = fmax(dimen.x, imagesize.x), |
| 2056 |
.y = fmax(dimen.y, imagesize.y)}; |
| 2057 |
|
| 2058 |
/* I don't know how to distort or skew ellipses in postscript */ |
| 2059 |
/* Convert request to a polygon with a large number of sides */ |
| 2060 |
if (sides <= 2 && |
| 2061 |
(!is_exactly_zero(distortion) || !is_exactly_zero(skew))) { |
| 2062 |
sides = 120; |
| 2063 |
} |
| 2064 |
|
| 2065 |
/* extra sizing depends on if label is centered vertically */ |
| 2066 |
p = agget(n, "labelloc"); |
| 2067 |
if (p && (p[0] == 't' || p[0] == 'b')) |
| 2068 |
ND_label(n)->valign = p[0]; |
| 2069 |
else |
| 2070 |
ND_label(n)->valign = 'c'; |
| 2071 |
|
| 2072 |
const bool isBox = sides == 4 && fabs(fmod(orientation, 90)) < 0.5 |
| 2073 |
&& is_exactly_zero(distortion) && is_exactly_zero(skew); |
| 2074 |
if (isBox) { |
| 2075 |
/* for regular boxes the fit should be exact */ |
| 2076 |
} else if (ND_shape(n)->polygon->vertices) { |
| 2077 |
poly_desc_t* pd = (poly_desc_t*)ND_shape(n)->polygon->vertices; |
| 2078 |
bb = pd->size_gen(bb); |
| 2079 |
} else { |
| 2080 |
/* for all other shapes, compute a smallest ellipse |
| 2081 |
* containing bb centered on the origin, and then pad for that. |
| 2082 |
* We assume the ellipse is defined by a scaling up of bb. |
| 2083 |
*/ |
| 2084 |
temp = bb.y * SQRT2; |
| 2085 |
if (height > temp && ND_label(n)->valign == 'c') { |
| 2086 |
/* if there is height to spare |
| 2087 |
* and the label is centered vertically |
| 2088 |
* then just pad x in proportion to the spare height */ |
| 2089 |
bb.x *= sqrt(1. / (1. - SQR(bb.y / height))); |
| 2090 |
} else { |
| 2091 |
bb.x *= SQRT2; |
| 2092 |
bb.y = temp; |
| 2093 |
} |
| 2094 |
#if 1 |
| 2095 |
if (sides > 2) { |
| 2096 |
temp = cos(M_PI / (double)sides); |
| 2097 |
bb.x /= temp; |
| 2098 |
bb.y /= temp; |
| 2099 |
/* FIXME - for odd-sided polygons, e.g. triangles, there |
| 2100 |
would be a better fit with some vertical adjustment of the shape */ |
| 2101 |
} |
| 2102 |
#endif |
| 2103 |
} |
| 2104 |
|
| 2105 |
/* at this point, bb is the minimum size of node that can hold the label */ |
| 2106 |
min_bb = bb; |
| 2107 |
|
| 2108 |
/* increase node size to width/height if needed */ |
| 2109 |
fxd = late_string(n, N_fixed, "false"); |
| 2110 |
if (*fxd == 's' && streq(fxd,"shape")) { |
| 2111 |
bb = (pointf){.x = width, .y = height}; |
| 2112 |
poly->option.fixedshape = true; |
| 2113 |
} else if (mapbool(fxd)) { |
| 2114 |
/* check only label, as images we can scale to fit */ |
| 2115 |
if (width < ND_label(n)->dimen.x || height < ND_label(n)->dimen.y) |
| 2116 |
agwarningf( |
| 2117 |
"node '%s', graph '%s' size too small for label\n", |
| 2118 |
agnameof(n), agnameof(agraphof(n))); |
| 2119 |
bb = (pointf){.x = width, .y = height}; |
| 2120 |
} else { |
| 2121 |
bb.x = width = fmax(width, bb.x); |
| 2122 |
bb.y = height = fmax(height, bb.y); |
| 2123 |
} |
| 2124 |
|
| 2125 |
/* If regular, make dimensions the same. |
| 2126 |
* Need this to guarantee final node size is regular. |
| 2127 |
*/ |
| 2128 |
if (regular) { |
| 2129 |
width = height = bb.x = bb.y = fmax(bb.x, bb.y); |
| 2130 |
} |
| 2131 |
|
| 2132 |
/* Compute space available for label. Provides the justification borders */ |
| 2133 |
if (!mapbool(late_string(n, N_nojustify, "false"))) { |
| 2134 |
if (isBox) { |
| 2135 |
ND_label(n)->space.x = fmax(dimen.x, bb.x) - spacex; |
| 2136 |
} |
| 2137 |
else if (dimen.y < bb.y) { |
| 2138 |
temp = bb.x * sqrt(1.0 - SQR(dimen.y) / SQR(bb.y)); |
| 2139 |
ND_label(n)->space.x = fmax(dimen.x, temp) - spacex; |
| 2140 |
} |
| 2141 |
else |
| 2142 |
ND_label(n)->space.x = dimen.x - spacex; |
| 2143 |
} else { |
| 2144 |
ND_label(n)->space.x = dimen.x - spacex; |
| 2145 |
} |
| 2146 |
|
| 2147 |
if (!poly->option.fixedshape) { |
| 2148 |
temp = bb.y - min_bb.y; |
| 2149 |
if (dimen.y < imagesize.y) |
| 2150 |
temp += imagesize.y - dimen.y; |
| 2151 |
ND_label(n)->space.y = dimen.y + temp; |
| 2152 |
} |
| 2153 |
|
| 2154 |
const double penwidth = late_double(n, N_penwidth, DEFAULT_NODEPENWIDTH, |
| 2155 |
MIN_NODEPENWIDTH); |
| 2156 |
|
| 2157 |
size_t outp = peripheries; |
| 2158 |
if (peripheries < 1) |
| 2159 |
outp = 1; |
| 2160 |
|
| 2161 |
if (peripheries >= 1 && penwidth > 0) { |
| 2162 |
// allocate extra vertices representing the outline, i.e., the outermost |
| 2163 |
// periphery with penwidth taken into account |
| 2164 |
++outp; |
| 2165 |
} |
| 2166 |
|
| 2167 |
if (sides < 3) { /* ellipses */ |
| 2168 |
sides = 2; |
| 2169 |
vertices = gv_calloc(outp * sides, sizeof(pointf)); |
| 2170 |
pointf P = {.x = bb.x / 2., .y = bb.y / 2.}; |
| 2171 |
vertices[0] = (pointf){.x = -P.x, .y = -P.y}; |
| 2172 |
vertices[1] = P; |
| 2173 |
if (peripheries > 1) { |
| 2174 |
for (size_t j = 1, i = 2; j < peripheries; j++) { |
| 2175 |
P.x += GAP; |
| 2176 |
P.y += GAP; |
| 2177 |
vertices[i] = (pointf){.x = -P.x, .y = -P.y}; |
| 2178 |
i++; |
| 2179 |
vertices[i] = P; |
| 2180 |
i++; |
| 2181 |
} |
| 2182 |
bb.x = 2. * P.x; |
| 2183 |
bb.y = 2. * P.y; |
| 2184 |
} |
| 2185 |
outline_bb = bb; |
| 2186 |
if (outp > peripheries) { |
| 2187 |
// add an outline at half the penwidth outside the outermost periphery |
| 2188 |
P.x += penwidth / 2; |
| 2189 |
P.y += penwidth / 2; |
| 2190 |
size_t i = sides * peripheries; |
| 2191 |
vertices[i] = (pointf){.x = -P.x, .y = -P.y}; |
| 2192 |
i++; |
| 2193 |
vertices[i] = P; |
| 2194 |
i++; |
| 2195 |
outline_bb.x = 2. * P.x; |
| 2196 |
outline_bb.y = 2. * P.y; |
| 2197 |
} |
| 2198 |
} else { |
| 2199 |
|
| 2200 |
/* |
| 2201 |
* FIXME - this code is wrong - it doesn't work for concave boundaries. |
| 2202 |
* (e.g. "folder" or "promoter") |
| 2203 |
* I don't think it even needs sectorangle, or knowledge of skewed shapes. |
| 2204 |
* (Concepts that only work for convex regular (modulo skew/distort) polygons.) |
| 2205 |
* |
| 2206 |
* I think it only needs to know inside v. outside (by always drawing |
| 2207 |
* boundaries clockwise, say), and the two adjacent segments. |
| 2208 |
* |
| 2209 |
* It needs to find the point where the two lines, parallel to |
| 2210 |
* the current segments, and outside by GAP distance, intersect. |
| 2211 |
*/ |
| 2212 |
|
| 2213 |
double sinx = 0, cosx = 0, xmax, ymax; |
| 2214 |
vertices = gv_calloc(outp * sides, sizeof(pointf)); |
| 2215 |
if (ND_shape(n)->polygon->vertices) { |
| 2216 |
poly_desc_t* pd = (poly_desc_t*)ND_shape(n)->polygon->vertices; |
| 2217 |
pd->vertex_gen (vertices, &bb); |
| 2218 |
xmax = bb.x/2; |
| 2219 |
ymax = bb.y/2; |
| 2220 |
} else { |
| 2221 |
double angle, sectorangle, sidelength, skewdist, gdistortion, gskew; |
| 2222 |
sectorangle = 2. * M_PI / (double)sides; |
| 2223 |
sidelength = sin(sectorangle / 2.); |
| 2224 |
skewdist = hypot(fabs(distortion) + fabs(skew), 1.); |
| 2225 |
gdistortion = distortion * SQRT2 / cos(sectorangle / 2.); |
| 2226 |
gskew = skew / 2.; |
| 2227 |
angle = (sectorangle - M_PI) / 2.; |
| 2228 |
sinx = sin(angle); |
| 2229 |
cosx = cos(angle); |
| 2230 |
pointf R = {.x = .5 * cosx, .y = .5 * sinx}; |
| 2231 |
xmax = ymax = 0.; |
| 2232 |
angle += (M_PI - sectorangle) / 2.; |
| 2233 |
for (size_t i = 0; i < sides; i++) { |
| 2234 |
|
| 2235 |
/*next regular vertex */ |
| 2236 |
angle += sectorangle; |
| 2237 |
sinx = sin(angle); |
| 2238 |
cosx = cos(angle); |
| 2239 |
R.x += sidelength * cosx; |
| 2240 |
R.y += sidelength * sinx; |
| 2241 |
|
| 2242 |
/*distort and skew */ |
| 2243 |
pointf P = { |
| 2244 |
.x = R.x * (skewdist + R.y * gdistortion) + R.y * gskew, |
| 2245 |
.y = R.y}; |
| 2246 |
|
| 2247 |
/*orient P.x,P.y */ |
| 2248 |
alpha = RADIANS(orientation) + atan2(P.y, P.x); |
| 2249 |
sinx = sin(alpha); |
| 2250 |
cosx = cos(alpha); |
| 2251 |
P.x = P.y = hypot(P.x, P.y); |
| 2252 |
P.x *= cosx; |
| 2253 |
P.y *= sinx; |
| 2254 |
|
| 2255 |
/*scale for label */ |
| 2256 |
P.x *= bb.x; |
| 2257 |
P.y *= bb.y; |
| 2258 |
|
| 2259 |
/*find max for bounding box */ |
| 2260 |
xmax = fmax(fabs(P.x), xmax); |
| 2261 |
ymax = fmax(fabs(P.y), ymax); |
| 2262 |
|
| 2263 |
/* store result in array of points */ |
| 2264 |
vertices[i] = P; |
| 2265 |
if (isBox) { /* enforce exact symmetry of box */ |
| 2266 |
vertices[1] = (pointf){.x = -P.x, .y = P.y}; |
| 2267 |
vertices[2] = (pointf){.x = -P.x, .y = -P.y}; |
| 2268 |
vertices[3] = (pointf){.x = P.x, .y = -P.y}; |
| 2269 |
break; |
| 2270 |
} |
| 2271 |
} |
| 2272 |
} |
| 2273 |
|
| 2274 |
/* apply minimum dimensions */ |
| 2275 |
xmax *= 2.; |
| 2276 |
ymax *= 2.; |
| 2277 |
bb = (pointf){.x = fmax(width, xmax), .y = fmax(height, ymax)}; |
| 2278 |
outline_bb = bb; |
| 2279 |
|
| 2280 |
scalex = bb.x / xmax; |
| 2281 |
scaley = bb.y / ymax; |
| 2282 |
|
| 2283 |
size_t i; |
| 2284 |
for (i = 0; i < sides; i++) { |
| 2285 |
pointf P = vertices[i]; |
| 2286 |
P.x *= scalex; |
| 2287 |
P.y *= scaley; |
| 2288 |
vertices[i] = P; |
| 2289 |
} |
| 2290 |
|
| 2291 |
if (outp > 1) { |
| 2292 |
pointf R = vertices[0]; |
| 2293 |
pointf Q; |
| 2294 |
for (size_t j = 1; j < sides; j++) { |
| 2295 |
Q = vertices[(i - j) % sides]; |
| 2296 |
if (!is_exactly_equal(Q.x, R.x) || !is_exactly_equal(Q.y, R.y)) { |
| 2297 |
break; |
| 2298 |
} |
| 2299 |
} |
| 2300 |
assert(!is_exactly_equal(R.x, Q.x) || !is_exactly_equal(R.y, Q.y)); |
| 2301 |
beta = atan2(R.y - Q.y, R.x - Q.x); |
| 2302 |
pointf Qprev = Q; |
| 2303 |
for (i = 0; i < sides; i++) { |
| 2304 |
|
| 2305 |
/*for each vertex find the bisector */ |
| 2306 |
Q = vertices[i]; |
| 2307 |
if (is_exactly_equal(Q.x, Qprev.x) && is_exactly_equal(Q.y, Qprev.y)) { |
| 2308 |
// The vertex points for the side ending at Q are equal, |
| 2309 |
// i.e. this side is actually a point and its angle is |
| 2310 |
// undefined. Therefore we keep the same offset for the end |
| 2311 |
// point as already calculated for the start point. This may |
| 2312 |
// occur for shapes which are represented as polygons during |
| 2313 |
// layout, but are drawn using Bézier curves during |
| 2314 |
// rendering, e.g. for the `cylinder` shape. |
| 2315 |
} else { |
| 2316 |
for (size_t j = 1; j < sides; j++) { |
| 2317 |
R = vertices[(i + j) % sides]; |
| 2318 |
if (!is_exactly_equal(R.x, Q.x) || !is_exactly_equal(R.y, Q.y)) { |
| 2319 |
break; |
| 2320 |
} |
| 2321 |
} |
| 2322 |
assert(!is_exactly_equal(R.x, Q.x) || !is_exactly_equal(R.y, Q.y)); |
| 2323 |
alpha = beta; |
| 2324 |
beta = atan2(R.y - Q.y, R.x - Q.x); |
| 2325 |
gamma = (alpha + M_PI - beta) / 2.; |
| 2326 |
|
| 2327 |
/*find distance along bisector to */ |
| 2328 |
/*intersection of next periphery */ |
| 2329 |
temp = GAP / sin(gamma); |
| 2330 |
|
| 2331 |
/*convert this distance to x and y */ |
| 2332 |
sinx = sin(alpha - gamma) * temp; |
| 2333 |
cosx = cos(alpha - gamma) * temp; |
| 2334 |
} |
| 2335 |
assert(cosx != 0 || sinx != 0); |
| 2336 |
Qprev = Q; |
| 2337 |
|
| 2338 |
/*save the vertices of all the */ |
| 2339 |
/*peripheries at this base vertex */ |
| 2340 |
for (size_t j = 1; j < peripheries; j++) { |
| 2341 |
Q.x += cosx; |
| 2342 |
Q.y += sinx; |
| 2343 |
vertices[i + j * sides] = Q; |
| 2344 |
} |
| 2345 |
if (outp > peripheries) { |
| 2346 |
// add an outline at half the penwidth outside the outermost periphery |
| 2347 |
Q.x += cosx * penwidth / 2 / GAP; |
| 2348 |
Q.y += sinx * penwidth / 2 / GAP; |
| 2349 |
vertices[i + peripheries * sides] = Q; |
| 2350 |
} |
| 2351 |
} |
| 2352 |
for (i = 0; i < sides; i++) { |
| 2353 |
pointf P = vertices[i + (peripheries - 1) * sides]; |
| 2354 |
bb = (pointf){.x = fmax(2.0 * fabs(P.x), bb.x), |
| 2355 |
.y = fmax(2.0 * fabs(P.y), bb.y)}; |
| 2356 |
Q = vertices[i + (outp - 1) * sides]; |
| 2357 |
outline_bb = (pointf){.x = fmax(2.0 * fabs(Q.x), outline_bb.x), |
| 2358 |
.y = fmax(2.0 * fabs(Q.y), outline_bb.y)}; |
| 2359 |
} |
| 2360 |
} |
| 2361 |
} |
| 2362 |
poly->regular = regular; |
| 2363 |
poly->peripheries = peripheries; |
| 2364 |
poly->sides = sides; |
| 2365 |
poly->orientation = orientation; |
| 2366 |
poly->skew = skew; |
| 2367 |
poly->distortion = distortion; |
| 2368 |
poly->vertices = vertices; |
| 2369 |
|
| 2370 |
if (poly->option.fixedshape) { |
| 2371 |
/* set width and height to reflect label and shape */ |
| 2372 |
ND_width(n) = PS2INCH(fmax(dimen.x, bb.x)); |
| 2373 |
ND_height(n) = PS2INCH(fmax(dimen.y, bb.y)); |
| 2374 |
ND_outline_width(n) = PS2INCH(fmax(dimen.x, outline_bb.x)); |
| 2375 |
ND_outline_height(n) = PS2INCH(fmax(dimen.y, outline_bb.y)); |
| 2376 |
} else { |
| 2377 |
ND_width(n) = PS2INCH(bb.x); |
| 2378 |
ND_height(n) = PS2INCH(bb.y); |
| 2379 |
ND_outline_width(n) = PS2INCH(outline_bb.x); |
| 2380 |
ND_outline_height(n) = PS2INCH(outline_bb.y); |
| 2381 |
} |
| 2382 |
ND_shape_info(n) = poly; |
| 2383 |
} |
| 2384 |
|
| 2385 |
static void poly_free(node_t * n) |
| 2386 |
{ |
| 2387 |
polygon_t *p = ND_shape_info(n); |
| 2388 |
|
| 2389 |
if (p) { |
| 2390 |
free(p->vertices); |
| 2391 |
free(p); |
| 2392 |
} |
| 2393 |
} |
| 2394 |
|
| 2395 |
/* poly_inside: |
| 2396 |
* Return true if point p is inside polygonal shape of node inside_context->s.n. |
| 2397 |
* Calculations are done using unrotated node shape. Thus, if p is in a rotated |
| 2398 |
* coordinate system, it is reset as P in the unrotated coordinate system. Similarly, |
| 2399 |
* the ND_rw, ND_lw and ND_ht values are rotated if the graph is flipped. |
| 2400 |
*/ |
| 2401 |
static bool poly_inside(inside_t * inside_context, pointf p) |
| 2402 |
{ |
| 2403 |
size_t sides; |
| 2404 |
const pointf O = {0}; |
| 2405 |
pointf *vertex = NULL; |
| 2406 |
|
| 2407 |
int s; |
| 2408 |
pointf P, Q, R; |
| 2409 |
boxf *bp; |
| 2410 |
node_t *n; |
| 2411 |
|
| 2412 |
if (!inside_context) { |
| 2413 |
return false; |
| 2414 |
} |
| 2415 |
|
| 2416 |
bp = inside_context->s.bp; |
| 2417 |
n = inside_context->s.n; |
| 2418 |
P = ccwrotatepf(p, 90 * GD_rankdir(agraphof(n))); |
| 2419 |
|
| 2420 |
/* Quick test if port rectangle is target */ |
| 2421 |
if (bp) { |
| 2422 |
boxf bbox = *bp; |
| 2423 |
return INSIDE(P, bbox); |
| 2424 |
} |
| 2425 |
|
| 2426 |
if (n != inside_context->s.lastn) { |
| 2427 |
double n_width, n_height; |
| 2428 |
double n_outline_width; |
| 2429 |
double n_outline_height; |
| 2430 |
inside_context->s.last_poly = ND_shape_info(n); |
| 2431 |
vertex = inside_context->s.last_poly->vertices; |
| 2432 |
sides = inside_context->s.last_poly->sides; |
| 2433 |
|
| 2434 |
double xsize, ysize; |
| 2435 |
if (inside_context->s.last_poly->option.fixedshape) { |
| 2436 |
boxf bb = polyBB(inside_context->s.last_poly); |
| 2437 |
n_width = bb.UR.x - bb.LL.x; |
| 2438 |
n_height = bb.UR.y - bb.LL.y; |
| 2439 |
n_outline_width = n_width; |
| 2440 |
n_outline_height = n_height; |
| 2441 |
/* get point and node size adjusted for rankdir=LR */ |
| 2442 |
if (GD_flip(agraphof(n))) { |
| 2443 |
ysize = n_width; |
| 2444 |
xsize = n_height; |
| 2445 |
} else { |
| 2446 |
xsize = n_width; |
| 2447 |
ysize = n_height; |
| 2448 |
} |
| 2449 |
} else { |
| 2450 |
/* get point and node size adjusted for rankdir=LR */ |
| 2451 |
if (GD_flip(agraphof(n))) { |
| 2452 |
ysize = ND_lw(n) + ND_rw(n); |
| 2453 |
xsize = ND_ht(n); |
| 2454 |
} else { |
| 2455 |
xsize = ND_lw(n) + ND_rw(n); |
| 2456 |
ysize = ND_ht(n); |
| 2457 |
} |
| 2458 |
n_width = INCH2PS(ND_width(n)); |
| 2459 |
n_height = INCH2PS(ND_height(n)); |
| 2460 |
n_outline_width = INCH2PS(ND_outline_width(n)); |
| 2461 |
n_outline_height = INCH2PS(ND_outline_height(n)); |
| 2462 |
} |
| 2463 |
|
| 2464 |
/* scale */ |
| 2465 |
inside_context->s.scalex = n_width; |
| 2466 |
if (!is_exactly_zero(xsize)) |
| 2467 |
inside_context->s.scalex /= xsize; |
| 2468 |
inside_context->s.scaley = n_height; |
| 2469 |
if (!is_exactly_zero(ysize)) |
| 2470 |
inside_context->s.scaley /= ysize; |
| 2471 |
inside_context->s.box_URx = n_outline_width / 2; |
| 2472 |
inside_context->s.box_URy = n_outline_height / 2; |
| 2473 |
|
| 2474 |
const double penwidth = late_double(n, N_penwidth, DEFAULT_NODEPENWIDTH, |
| 2475 |
MIN_NODEPENWIDTH); |
| 2476 |
if (inside_context->s.last_poly->peripheries >= 1 && penwidth > 0) { |
| 2477 |
/* index to outline, i.e., the outer-periphery with penwidth taken into account */ |
| 2478 |
inside_context->s.outp = |
| 2479 |
(inside_context->s.last_poly->peripheries + 1 - 1) * sides; |
| 2480 |
} else if (inside_context->s.last_poly->peripheries < 1) { |
| 2481 |
inside_context->s.outp = 0; |
| 2482 |
} else { |
| 2483 |
/* index to outer-periphery */ |
| 2484 |
inside_context->s.outp = |
| 2485 |
(inside_context->s.last_poly->peripheries - 1) * sides; |
| 2486 |
} |
| 2487 |
inside_context->s.lastn = n; |
| 2488 |
} else { |
| 2489 |
vertex = inside_context->s.last_poly->vertices; |
| 2490 |
sides = inside_context->s.last_poly->sides; |
| 2491 |
} |
| 2492 |
|
| 2493 |
/* scale */ |
| 2494 |
P.x *= inside_context->s.scalex; |
| 2495 |
P.y *= inside_context->s.scaley; |
| 2496 |
|
| 2497 |
/* inside bounding box? */ |
| 2498 |
if (fabs(P.x) > inside_context->s.box_URx || |
| 2499 |
fabs(P.y) > inside_context->s.box_URy) |
| 2500 |
return false; |
| 2501 |
|
| 2502 |
/* ellipses */ |
| 2503 |
if (sides <= 2) |
| 2504 |
return hypot(P.x / inside_context->s.box_URx, |
| 2505 |
P.y / inside_context->s.box_URy) < 1; |
| 2506 |
|
| 2507 |
/* use fast test in case we are converging on a segment */ |
| 2508 |
size_t i = inside_context->s.last % sides; // in case last left over from larger polygon |
| 2509 |
size_t i1 = (i + 1) % sides; |
| 2510 |
Q = vertex[i + inside_context->s.outp]; |
| 2511 |
R = vertex[i1 + inside_context->s.outp]; |
| 2512 |
if (!same_side(P, O, Q, R)) /* false if outside the segment's face */ |
| 2513 |
return false; |
| 2514 |
/* else inside the segment face... */ |
| 2515 |
if ((s = same_side(P, Q, R, O)) && same_side(P, R, O, Q)) /* true if between the segment's sides */ |
| 2516 |
return true; |
| 2517 |
/* else maybe in another segment */ |
| 2518 |
for (size_t j = 1; j < sides; j++) { // iterate over remaining segments |
| 2519 |
if (s) { /* clockwise */ |
| 2520 |
i = i1; |
| 2521 |
i1 = (i + 1) % sides; |
| 2522 |
} else { /* counter clockwise */ |
| 2523 |
i1 = i; |
| 2524 |
i = (i + sides - 1) % sides; |
| 2525 |
} |
| 2526 |
if (!same_side(P, O, vertex[i + inside_context->s.outp], |
| 2527 |
vertex[i1 + inside_context->s.outp])) { // false if outside any other segment’s face |
| 2528 |
inside_context->s.last = i; |
| 2529 |
return false; |
| 2530 |
} |
| 2531 |
} |
| 2532 |
/* inside all segments' faces */ |
| 2533 |
inside_context->s.last = i; // in case next edge is to same side |
| 2534 |
return true; |
| 2535 |
} |
| 2536 |
|
| 2537 |
static int poly_path(node_t * n, port * p, int side, boxf rv[], int *kptr) |
| 2538 |
{ |
| 2539 |
(void)n; |
| 2540 |
(void)p; |
| 2541 |
(void)side; |
| 2542 |
(void)rv; |
| 2543 |
(void)kptr; |
| 2544 |
|
| 2545 |
return 0; |
| 2546 |
} |
| 2547 |
|
| 2548 |
static unsigned char invflip_side(unsigned char side, int rankdir) { |
| 2549 |
switch (rankdir) { |
| 2550 |
case RANKDIR_TB: |
| 2551 |
break; |
| 2552 |
case RANKDIR_BT: |
| 2553 |
switch (side) { |
| 2554 |
case TOP: |
| 2555 |
side = BOTTOM; |
| 2556 |
break; |
| 2557 |
case BOTTOM: |
| 2558 |
side = TOP; |
| 2559 |
break; |
| 2560 |
default: |
| 2561 |
break; |
| 2562 |
} |
| 2563 |
break; |
| 2564 |
case RANKDIR_LR: |
| 2565 |
switch (side) { |
| 2566 |
case TOP: |
| 2567 |
side = RIGHT; |
| 2568 |
break; |
| 2569 |
case BOTTOM: |
| 2570 |
side = LEFT; |
| 2571 |
break; |
| 2572 |
case LEFT: |
| 2573 |
side = TOP; |
| 2574 |
break; |
| 2575 |
case RIGHT: |
| 2576 |
side = BOTTOM; |
| 2577 |
break; |
| 2578 |
default: |
| 2579 |
break; |
| 2580 |
} |
| 2581 |
break; |
| 2582 |
case RANKDIR_RL: |
| 2583 |
switch (side) { |
| 2584 |
case TOP: |
| 2585 |
side = RIGHT; |
| 2586 |
break; |
| 2587 |
case BOTTOM: |
| 2588 |
side = LEFT; |
| 2589 |
break; |
| 2590 |
case LEFT: |
| 2591 |
side = BOTTOM; |
| 2592 |
break; |
| 2593 |
case RIGHT: |
| 2594 |
side = TOP; |
| 2595 |
break; |
| 2596 |
default: |
| 2597 |
break; |
| 2598 |
} |
| 2599 |
break; |
| 2600 |
default: |
| 2601 |
UNREACHABLE(); |
| 2602 |
} |
| 2603 |
return side; |
| 2604 |
} |
| 2605 |
|
| 2606 |
static double invflip_angle(double angle, int rankdir) |
| 2607 |
{ |
| 2608 |
switch (rankdir) { |
| 2609 |
case RANKDIR_TB: |
| 2610 |
break; |
| 2611 |
case RANKDIR_BT: |
| 2612 |
angle *= -1; |
| 2613 |
break; |
| 2614 |
case RANKDIR_LR: |
| 2615 |
angle -= M_PI * 0.5; |
| 2616 |
break; |
| 2617 |
case RANKDIR_RL: |
| 2618 |
if (angle == M_PI) |
| 2619 |
angle = -0.5 * M_PI; |
| 2620 |
else if (angle == M_PI * 0.75) |
| 2621 |
angle = -0.25 * M_PI; |
| 2622 |
else if (angle == M_PI * 0.5) |
| 2623 |
angle = 0; |
| 2624 |
else if (angle == 0) |
| 2625 |
angle = M_PI * 0.5; |
| 2626 |
else if (angle == M_PI * -0.25) |
| 2627 |
angle = M_PI * 0.75; |
| 2628 |
else if (angle == M_PI * -0.5) |
| 2629 |
angle = M_PI; |
| 2630 |
break; |
| 2631 |
default: |
| 2632 |
UNREACHABLE(); |
| 2633 |
} |
| 2634 |
return angle; |
| 2635 |
} |
| 2636 |
|
| 2637 |
/* compassPoint: |
| 2638 |
* Compute compass points for non-trivial shapes. |
| 2639 |
* It finds where the ray ((0,0),(x,y)) hits the boundary and |
| 2640 |
* returns it. |
| 2641 |
* Assumes ictxt and ictxt->n are non-NULL. |
| 2642 |
* |
| 2643 |
* bezier_clip uses the shape's _inside function, which assumes the input |
| 2644 |
* point is in the rotated coordinate system (as determined by rankdir), so |
| 2645 |
* it rotates the point counterclockwise based on rankdir to get the node's |
| 2646 |
* coordinate system. |
| 2647 |
* To handle this, if rankdir is set, we rotate (x,y) clockwise, and then |
| 2648 |
* rotate the answer counterclockwise. |
| 2649 |
*/ |
| 2650 |
static pointf compassPoint(inside_t * ictxt, double y, double x) |
| 2651 |
{ |
| 2652 |
pointf curve[4]; /* Bézier control points for a straight line */ |
| 2653 |
node_t *n = ictxt->s.n; |
| 2654 |
graph_t* g = agraphof(n); |
| 2655 |
int rd = GD_rankdir(g); |
| 2656 |
pointf p; |
| 2657 |
|
| 2658 |
p.x = x; |
| 2659 |
p.y = y; |
| 2660 |
if (rd) |
| 2661 |
p = cwrotatepf(p, 90 * rd); |
| 2662 |
|
| 2663 |
curve[0].x = curve[0].y = 0; |
| 2664 |
curve[1] = curve[0]; |
| 2665 |
curve[3] = curve[2] = p; |
| 2666 |
|
| 2667 |
bezier_clip(ictxt, ND_shape(n)->fns->insidefn, curve, true); |
| 2668 |
|
| 2669 |
if (rd) |
| 2670 |
curve[0] = ccwrotatepf(curve[0], 90 * rd); |
| 2671 |
return curve[0]; |
| 2672 |
} |
| 2673 |
|
| 2674 |
/* compassPort: |
| 2675 |
* Attach a compass point to a port pp, and fill in remaining fields. |
| 2676 |
* n is the corresponding node; bp is the bounding box of the port. |
| 2677 |
* compass is the compass point |
| 2678 |
* Return 1 if unrecognized compass point, in which case we |
| 2679 |
* use the center. |
| 2680 |
* |
| 2681 |
* This function also finishes initializing the port structure, |
| 2682 |
* even if no compass point is involved. |
| 2683 |
* The sides value gives the set of sides shared by the port. This |
| 2684 |
* is used with a compass point to indicate if the port is exposed, to |
| 2685 |
* set the port's side value. |
| 2686 |
* |
| 2687 |
* If ictxt is NULL, we are working with a simple rectangular shape (node or |
| 2688 |
* port of record of HTML label), so compass points are trivial. If ictxt is |
| 2689 |
* not NULL, it provides shape information so that the compass point can be |
| 2690 |
* calculated based on the shape. |
| 2691 |
* |
| 2692 |
* The code assumes the node has its unrotated shape to find the points, |
| 2693 |
* angles, etc. At the end, the parameters are adjusted to take into account |
| 2694 |
* the rankdir attribute. In particular, the first if-else statement flips |
| 2695 |
* the already adjusted ND_ht, ND_lw and ND_rw back to non-flipped values. |
| 2696 |
* |
| 2697 |
*/ |
| 2698 |
static int compassPort(node_t *n, boxf *bp, port *pp, const char *compass, |
| 2699 |
unsigned char sides, inside_t * ictxt) { |
| 2700 |
boxf b; |
| 2701 |
pointf p, ctr; |
| 2702 |
int rv = 0; |
| 2703 |
double theta = 0.0; |
| 2704 |
bool constrain = false; |
| 2705 |
bool dyna = false; |
| 2706 |
unsigned char side = 0; |
| 2707 |
bool clip = true; |
| 2708 |
bool defined; |
| 2709 |
double maxv; /* sufficiently large value outside of range of node */ |
| 2710 |
|
| 2711 |
if (bp) { |
| 2712 |
b = *bp; |
| 2713 |
p = (pointf){(b.LL.x + b.UR.x) / 2, (b.LL.y + b.UR.y) / 2}; |
| 2714 |
defined = true; |
| 2715 |
} else { |
| 2716 |
p.x = p.y = 0.; |
| 2717 |
if (GD_flip(agraphof(n))) { |
| 2718 |
b.UR.x = ND_ht(n) / 2.; |
| 2719 |
b.LL.x = -b.UR.x; |
| 2720 |
b.UR.y = ND_lw(n); |
| 2721 |
b.LL.y = -b.UR.y; |
| 2722 |
} else { |
| 2723 |
b.UR.y = ND_ht(n) / 2.; |
| 2724 |
b.LL.y = -b.UR.y; |
| 2725 |
b.UR.x = ND_lw(n); |
| 2726 |
b.LL.x = -b.UR.x; |
| 2727 |
} |
| 2728 |
defined = false; |
| 2729 |
} |
| 2730 |
maxv = fmax(b.UR.x, b.UR.y); |
| 2731 |
maxv *= 4.0; |
| 2732 |
ctr = p; |
| 2733 |
if (compass && *compass) { |
| 2734 |
switch (*compass++) { |
| 2735 |
case 'e': |
| 2736 |
if (*compass) |
| 2737 |
rv = 1; |
| 2738 |
else { |
| 2739 |
if (ictxt) |
| 2740 |
p = compassPoint(ictxt, ctr.y, maxv); |
| 2741 |
else |
| 2742 |
p.x = b.UR.x; |
| 2743 |
theta = 0.0; |
| 2744 |
constrain = true; |
| 2745 |
defined = true; |
| 2746 |
clip = false; |
| 2747 |
side = sides & RIGHT; |
| 2748 |
} |
| 2749 |
break; |
| 2750 |
case 's': |
| 2751 |
p.y = b.LL.y; |
| 2752 |
constrain = true; |
| 2753 |
clip = false; |
| 2754 |
switch (*compass) { |
| 2755 |
case '\0': |
| 2756 |
theta = -M_PI * 0.5; |
| 2757 |
defined = true; |
| 2758 |
if (ictxt) |
| 2759 |
p = compassPoint(ictxt, -maxv, ctr.x); |
| 2760 |
else |
| 2761 |
p.x = ctr.x; |
| 2762 |
side = sides & BOTTOM; |
| 2763 |
break; |
| 2764 |
case 'e': |
| 2765 |
theta = -M_PI * 0.25; |
| 2766 |
defined = true; |
| 2767 |
if (ictxt) |
| 2768 |
p = compassPoint(ictxt, -maxv, maxv); |
| 2769 |
else |
| 2770 |
p.x = b.UR.x; |
| 2771 |
side = sides & (BOTTOM | RIGHT); |
| 2772 |
break; |
| 2773 |
case 'w': |
| 2774 |
theta = -M_PI * 0.75; |
| 2775 |
defined = true; |
| 2776 |
if (ictxt) |
| 2777 |
p = compassPoint(ictxt, -maxv, -maxv); |
| 2778 |
else |
| 2779 |
p.x = b.LL.x; |
| 2780 |
side = sides & (BOTTOM | LEFT); |
| 2781 |
break; |
| 2782 |
default: |
| 2783 |
p.y = ctr.y; |
| 2784 |
constrain = false; |
| 2785 |
clip = true; |
| 2786 |
rv = 1; |
| 2787 |
break; |
| 2788 |
} |
| 2789 |
break; |
| 2790 |
case 'w': |
| 2791 |
if (*compass) |
| 2792 |
rv = 1; |
| 2793 |
else { |
| 2794 |
if (ictxt) |
| 2795 |
p = compassPoint(ictxt, ctr.y, -maxv); |
| 2796 |
else |
| 2797 |
p.x = b.LL.x; |
| 2798 |
theta = M_PI; |
| 2799 |
constrain = true; |
| 2800 |
defined = true; |
| 2801 |
clip = false; |
| 2802 |
side = sides & LEFT; |
| 2803 |
} |
| 2804 |
break; |
| 2805 |
case 'n': |
| 2806 |
p.y = b.UR.y; |
| 2807 |
constrain = true; |
| 2808 |
clip = false; |
| 2809 |
switch (*compass) { |
| 2810 |
case '\0': |
| 2811 |
defined = true; |
| 2812 |
theta = M_PI * 0.5; |
| 2813 |
if (ictxt) |
| 2814 |
p = compassPoint(ictxt, maxv, ctr.x); |
| 2815 |
else |
| 2816 |
p.x = ctr.x; |
| 2817 |
side = sides & TOP; |
| 2818 |
break; |
| 2819 |
case 'e': |
| 2820 |
defined = true; |
| 2821 |
theta = M_PI * 0.25; |
| 2822 |
if (ictxt) |
| 2823 |
p = compassPoint(ictxt, maxv, maxv); |
| 2824 |
else |
| 2825 |
p.x = b.UR.x; |
| 2826 |
side = sides & (TOP | RIGHT); |
| 2827 |
break; |
| 2828 |
case 'w': |
| 2829 |
defined = true; |
| 2830 |
theta = M_PI * 0.75; |
| 2831 |
if (ictxt) |
| 2832 |
p = compassPoint(ictxt, maxv, -maxv); |
| 2833 |
else |
| 2834 |
p.x = b.LL.x; |
| 2835 |
side = sides & (TOP | LEFT); |
| 2836 |
break; |
| 2837 |
default: |
| 2838 |
p.y = ctr.y; |
| 2839 |
constrain = false; |
| 2840 |
clip = true; |
| 2841 |
rv = 1; |
| 2842 |
break; |
| 2843 |
} |
| 2844 |
break; |
| 2845 |
case '_': |
| 2846 |
dyna = true; |
| 2847 |
side = sides; |
| 2848 |
break; |
| 2849 |
case 'c': |
| 2850 |
break; |
| 2851 |
default: |
| 2852 |
rv = 1; |
| 2853 |
break; |
| 2854 |
} |
| 2855 |
} |
| 2856 |
p = cwrotatepf(p, 90 * GD_rankdir(agraphof(n))); |
| 2857 |
if (dyna) |
| 2858 |
pp->side = side; |
| 2859 |
else |
| 2860 |
pp->side = invflip_side(side, GD_rankdir(agraphof(n))); |
| 2861 |
pp->bp = bp; |
| 2862 |
pp->p = p; |
| 2863 |
pp->theta = invflip_angle(theta, GD_rankdir(agraphof(n))); |
| 2864 |
if (p.x == 0 && p.y == 0) |
| 2865 |
pp->order = MC_SCALE / 2; |
| 2866 |
else { |
| 2867 |
/* compute angle with 0 at north pole, increasing CCW */ |
| 2868 |
double angle = atan2(p.y, p.x) + 1.5 * M_PI; |
| 2869 |
if (angle >= 2 * M_PI) |
| 2870 |
angle -= 2 * M_PI; |
| 2871 |
pp->order = (int) (MC_SCALE * angle / (2 * M_PI)); |
| 2872 |
} |
| 2873 |
pp->constrained = constrain; |
| 2874 |
pp->defined = defined; |
| 2875 |
pp->clip = clip; |
| 2876 |
pp->dyna = dyna; |
| 2877 |
return rv; |
| 2878 |
} |
| 2879 |
|
| 2880 |
static port poly_port(node_t * n, char *portname, char *compass) |
| 2881 |
{ |
| 2882 |
port rv; |
| 2883 |
boxf *bp; |
| 2884 |
unsigned char sides; // bitmap of which sides the port lies along |
| 2885 |
|
| 2886 |
if (portname[0] == '\0') |
| 2887 |
return Center; |
| 2888 |
|
| 2889 |
if (compass == NULL) |
| 2890 |
compass = "_"; |
| 2891 |
sides = BOTTOM | RIGHT | TOP | LEFT; |
| 2892 |
if (ND_label(n)->html && (bp = html_port(n, portname, &sides))) { |
| 2893 |
if (compassPort(n, bp, &rv, compass, sides, NULL)) { |
| 2894 |
agwarningf( |
| 2895 |
"node %s, port %s, unrecognized compass point '%s' - ignored\n", |
| 2896 |
agnameof(n), portname, compass); |
| 2897 |
} |
| 2898 |
} else { |
| 2899 |
inside_t *ictxtp; |
| 2900 |
inside_t ictxt = {0}; |
| 2901 |
|
| 2902 |
if (IS_BOX(n)) |
| 2903 |
ictxtp = NULL; |
| 2904 |
else { |
| 2905 |
ictxt.s.n = n; |
| 2906 |
ictxt.s.bp = NULL; |
| 2907 |
ictxtp = &ictxt; |
| 2908 |
} |
| 2909 |
if (compassPort(n, NULL, &rv, portname, sides, ictxtp)) |
| 2910 |
unrecognized(n, portname); |
| 2911 |
} |
| 2912 |
|
| 2913 |
rv.name = NULL; |
| 2914 |
return rv; |
| 2915 |
} |
| 2916 |
|
| 2917 |
static bool multicolor(const char *f) { |
| 2918 |
return strchr(f, ':') != NULL; |
| 2919 |
} |
| 2920 |
|
| 2921 |
/* generic polygon gencode routine */ |
| 2922 |
static void poly_gencode(GVJ_t * job, node_t * n) |
| 2923 |
{ |
| 2924 |
obj_state_t *obj = job->obj; |
| 2925 |
polygon_t *poly; |
| 2926 |
double xsize, ysize; |
| 2927 |
pointf P, *vertices; |
| 2928 |
int filled; |
| 2929 |
bool usershape_p; |
| 2930 |
bool pfilled; /* true if fill not handled by user shape */ |
| 2931 |
char *color, *name; |
| 2932 |
int doMap = (obj->url || obj->explicit_tooltip); |
| 2933 |
char* fillcolor=NULL; |
| 2934 |
char* pencolor=NULL; |
| 2935 |
|
| 2936 |
if (doMap && !(job->flags & EMIT_CLUSTERS_LAST)) |
| 2937 |
gvrender_begin_anchor(job, |
| 2938 |
obj->url, obj->tooltip, obj->target, |
| 2939 |
obj->id); |
| 2940 |
|
| 2941 |
poly = ND_shape_info(n); |
| 2942 |
vertices = poly->vertices; |
| 2943 |
const size_t sides = poly->sides; |
| 2944 |
size_t peripheries = poly->peripheries; |
| 2945 |
pointf *AF = gv_calloc(sides + 5, sizeof(pointf)); |
| 2946 |
|
| 2947 |
/* nominal label position in the center of the node */ |
| 2948 |
ND_label(n)->pos = ND_coord(n); |
| 2949 |
|
| 2950 |
xsize = (ND_lw(n) + ND_rw(n)) / INCH2PS(ND_width(n)); |
| 2951 |
ysize = ND_ht(n) / INCH2PS(ND_height(n)); |
| 2952 |
|
| 2953 |
const graphviz_polygon_style_t style = stylenode(job, n); |
| 2954 |
|
| 2955 |
char *clrs[2] = {0}; |
| 2956 |
if (ND_gui_state(n) & GUI_STATE_ACTIVE) { |
| 2957 |
pencolor = DEFAULT_ACTIVEPENCOLOR; |
| 2958 |
gvrender_set_pencolor(job, pencolor); |
| 2959 |
color = DEFAULT_ACTIVEFILLCOLOR; |
| 2960 |
gvrender_set_fillcolor(job, color); |
| 2961 |
filled = FILL; |
| 2962 |
} else if (ND_gui_state(n) & GUI_STATE_SELECTED) { |
| 2963 |
pencolor = DEFAULT_SELECTEDPENCOLOR; |
| 2964 |
gvrender_set_pencolor(job, pencolor); |
| 2965 |
color = DEFAULT_SELECTEDFILLCOLOR; |
| 2966 |
gvrender_set_fillcolor(job, color); |
| 2967 |
filled = FILL; |
| 2968 |
} else if (ND_gui_state(n) & GUI_STATE_DELETED) { |
| 2969 |
pencolor = DEFAULT_DELETEDPENCOLOR; |
| 2970 |
gvrender_set_pencolor(job, pencolor); |
| 2971 |
color = DEFAULT_DELETEDFILLCOLOR; |
| 2972 |
gvrender_set_fillcolor(job, color); |
| 2973 |
filled = FILL; |
| 2974 |
} else if (ND_gui_state(n) & GUI_STATE_VISITED) { |
| 2975 |
pencolor = DEFAULT_VISITEDPENCOLOR; |
| 2976 |
gvrender_set_pencolor(job, pencolor); |
| 2977 |
color = DEFAULT_VISITEDFILLCOLOR; |
| 2978 |
gvrender_set_fillcolor(job, color); |
| 2979 |
filled = FILL; |
| 2980 |
} else { |
| 2981 |
if (style.filled) { |
| 2982 |
double frac; |
| 2983 |
fillcolor = findFill (n); |
| 2984 |
if (findStopColor (fillcolor, clrs, &frac)) { |
| 2985 |
gvrender_set_fillcolor(job, clrs[0]); |
| 2986 |
if (clrs[1]) |
| 2987 |
gvrender_set_gradient_vals(job,clrs[1],late_int(n,N_gradientangle,0,0), frac); |
| 2988 |
else |
| 2989 |
gvrender_set_gradient_vals(job,DEFAULT_COLOR,late_int(n,N_gradientangle,0,0), frac); |
| 2990 |
if (style.radial) |
| 2991 |
filled = RGRADIENT; |
| 2992 |
else |
| 2993 |
filled = GRADIENT; |
| 2994 |
} |
| 2995 |
else { |
| 2996 |
gvrender_set_fillcolor(job, fillcolor); |
| 2997 |
filled = FILL; |
| 2998 |
} |
| 2999 |
} |
| 3000 |
else if (style.striped || style.wedged) { |
| 3001 |
fillcolor = findFill (n); |
| 3002 |
filled = 1; |
| 3003 |
} |
| 3004 |
else { |
| 3005 |
filled = 0; |
| 3006 |
} |
| 3007 |
pencolor = penColor(job, n); /* emit pen color */ |
| 3008 |
} |
| 3009 |
|
| 3010 |
pfilled = !ND_shape(n)->usershape || streq(ND_shape(n)->name, "custom"); |
| 3011 |
|
| 3012 |
/* if no boundary but filled, set boundary color to transparent */ |
| 3013 |
if (peripheries == 0 && filled != 0 && pfilled) { |
| 3014 |
peripheries = 1; |
| 3015 |
gvrender_set_pencolor(job, "transparent"); |
| 3016 |
} |
| 3017 |
|
| 3018 |
/* draw peripheries first */ |
| 3019 |
size_t j; |
| 3020 |
for (j = 0; j < peripheries; j++) { |
| 3021 |
for (size_t i = 0; i < sides; i++) { |
| 3022 |
P = vertices[i + j * sides]; |
| 3023 |
AF[i].x = P.x * xsize + ND_coord(n).x; |
| 3024 |
AF[i].y = P.y * ysize + ND_coord(n).y; |
| 3025 |
} |
| 3026 |
if (sides <= 2) { |
| 3027 |
if (style.wedged && j == 0 && multicolor(fillcolor)) { |
| 3028 |
int rv = wedgedEllipse (job, AF, fillcolor); |
| 3029 |
if (rv > 1) |
| 3030 |
agerr (AGPREV, "in node %s\n", agnameof(n)); |
| 3031 |
filled = 0; |
| 3032 |
} |
| 3033 |
gvrender_ellipse(job, AF, filled); |
| 3034 |
if (style.diagonals) { |
| 3035 |
Mcircle_hack(job, n); |
| 3036 |
} |
| 3037 |
} else if (style.striped) { |
| 3038 |
if (j == 0) { |
| 3039 |
int rv = stripedBox (job, AF, fillcolor, 1); |
| 3040 |
if (rv > 1) |
| 3041 |
agerr (AGPREV, "in node %s\n", agnameof(n)); |
| 3042 |
} |
| 3043 |
gvrender_polygon(job, AF, sides, 0); |
| 3044 |
} else if (style.underline) { |
| 3045 |
gvrender_set_pencolor(job, "transparent"); |
| 3046 |
gvrender_polygon(job, AF, sides, filled); |
| 3047 |
gvrender_set_pencolor(job, pencolor); |
| 3048 |
gvrender_polyline(job, AF+2, 2); |
| 3049 |
} else if (SPECIAL_CORNERS(style)) { |
| 3050 |
round_corners(job, AF, sides, style, filled); |
| 3051 |
} else { |
| 3052 |
gvrender_polygon(job, AF, sides, filled); |
| 3053 |
} |
| 3054 |
/* fill innermost periphery only */ |
| 3055 |
filled = 0; |
| 3056 |
} |
| 3057 |
|
| 3058 |
usershape_p = false; |
| 3059 |
if (ND_shape(n)->usershape) { |
| 3060 |
name = ND_shape(n)->name; |
| 3061 |
if (streq(name, "custom")) { |
| 3062 |
if ((name = agget(n, "shapefile")) && name[0]) |
| 3063 |
usershape_p = true; |
| 3064 |
} else |
| 3065 |
usershape_p = true; |
| 3066 |
} else if ((name = agget(n, "image")) && name[0]) { |
| 3067 |
usershape_p = true; |
| 3068 |
} |
| 3069 |
if (usershape_p) { |
| 3070 |
/* get coords of innermost periphery */ |
| 3071 |
for (size_t i = 0; i < sides; i++) { |
| 3072 |
P = vertices[i]; |
| 3073 |
AF[i].x = P.x * xsize + ND_coord(n).x; |
| 3074 |
AF[i].y = P.y * ysize + ND_coord(n).y; |
| 3075 |
} |
| 3076 |
/* lay down fill first */ |
| 3077 |
if (filled != 0 && pfilled) { |
| 3078 |
if (sides <= 2) { |
| 3079 |
if (style.wedged && j == 0 && multicolor(fillcolor)) { |
| 3080 |
int rv = wedgedEllipse (job, AF, fillcolor); |
| 3081 |
if (rv > 1) |
| 3082 |
agerr (AGPREV, "in node %s\n", agnameof(n)); |
| 3083 |
filled = 0; |
| 3084 |
} |
| 3085 |
gvrender_ellipse(job, AF, filled); |
| 3086 |
if (style.diagonals) { |
| 3087 |
Mcircle_hack(job, n); |
| 3088 |
} |
| 3089 |
} else if (style.striped) { |
| 3090 |
int rv = stripedBox (job, AF, fillcolor, 1); |
| 3091 |
if (rv > 1) |
| 3092 |
agerr (AGPREV, "in node %s\n", agnameof(n)); |
| 3093 |
gvrender_polygon(job, AF, sides, 0); |
| 3094 |
} else if (style.rounded || style.diagonals) { |
| 3095 |
round_corners(job, AF, sides, style, filled); |
| 3096 |
} else { |
| 3097 |
gvrender_polygon(job, AF, sides, filled); |
| 3098 |
} |
| 3099 |
} |
| 3100 |
gvrender_usershape(job, name, AF, sides, filled != 0, |
| 3101 |
late_string(n, N_imagescale, "false"), |
| 3102 |
late_string(n, N_imagepos, "mc")); |
| 3103 |
filled = 0; /* with user shapes, we have done the fill if needed */ |
| 3104 |
} |
| 3105 |
|
| 3106 |
free(AF); |
| 3107 |
free (clrs[0]); |
| 3108 |
free (clrs[1]); |
| 3109 |
|
| 3110 |
emit_label(job, EMIT_NLABEL, ND_label(n)); |
| 3111 |
if (doMap) { |
| 3112 |
if (job->flags & EMIT_CLUSTERS_LAST) |
| 3113 |
gvrender_begin_anchor(job, |
| 3114 |
obj->url, obj->tooltip, obj->target, |
| 3115 |
obj->id); |
| 3116 |
gvrender_end_anchor(job); |
| 3117 |
} |
| 3118 |
} |
| 3119 |
|
| 3120 |
/*=======================end poly======================================*/ |
| 3121 |
|
| 3122 |
/*===============================point start========================*/ |
| 3123 |
|
| 3124 |
/* point_init: |
| 3125 |
* shorthand for shape=circle, style=filled, width=0.05, label="" |
| 3126 |
*/ |
| 3127 |
static void point_init(node_t * n) |
| 3128 |
{ |
| 3129 |
polygon_t *poly = gv_alloc(sizeof(polygon_t)); |
| 3130 |
size_t sides, outp, peripheries = ND_shape(n)->polygon->peripheries; |
| 3131 |
double sz; |
| 3132 |
pointf P, *vertices; |
| 3133 |
size_t i, j; |
| 3134 |
double w, h; |
| 3135 |
|
| 3136 |
/* set width and height, and make them equal |
| 3137 |
* if user has set weight or height, use it. |
| 3138 |
* if both are set, use smallest. |
| 3139 |
* if neither, use default |
| 3140 |
*/ |
| 3141 |
w = late_double(n, N_width, DBL_MAX, MIN_NODEWIDTH); |
| 3142 |
h = late_double(n, N_height, DBL_MAX, MIN_NODEHEIGHT); |
| 3143 |
w = fmin(w, h); |
| 3144 |
if (is_exactly_equal(w, DBL_MAX) && |
| 3145 |
is_exactly_equal(h, DBL_MAX)) // neither defined |
| 3146 |
ND_width(n) = ND_height(n) = DEF_POINT; |
| 3147 |
else { |
| 3148 |
w = fmin(w, h); |
| 3149 |
/* If w == 0, use it; otherwise, make w no less than MIN_POINT due |
| 3150 |
* to the restrictions mentioned above. |
| 3151 |
*/ |
| 3152 |
if (w > 0.0) |
| 3153 |
w = fmax(w, MIN_POINT); |
| 3154 |
ND_width(n) = ND_height(n) = w; |
| 3155 |
} |
| 3156 |
|
| 3157 |
sz = ND_width(n) * POINTS_PER_INCH; |
| 3158 |
peripheries = (size_t)late_int(n, N_peripheries, (int)peripheries, 0); |
| 3159 |
if (peripheries < 1) |
| 3160 |
outp = 1; |
| 3161 |
else |
| 3162 |
outp = peripheries; |
| 3163 |
sides = 2; |
| 3164 |
const double penwidth = late_double(n, N_penwidth, DEFAULT_NODEPENWIDTH, |
| 3165 |
MIN_NODEPENWIDTH); |
| 3166 |
if (peripheries >= 1 && penwidth > 0) { |
| 3167 |
// allocate extra vertices representing the outline, i.e., the outermost |
| 3168 |
// periphery with penwidth taken into account |
| 3169 |
++outp; |
| 3170 |
} |
| 3171 |
vertices = gv_calloc(outp * sides, sizeof(pointf)); |
| 3172 |
P.y = P.x = sz / 2.; |
| 3173 |
vertices[0].x = -P.x; |
| 3174 |
vertices[0].y = -P.y; |
| 3175 |
vertices[1] = P; |
| 3176 |
if (peripheries > 1) { |
| 3177 |
for (j = 1, i = 2; j < peripheries; j++) { |
| 3178 |
P.x += GAP; |
| 3179 |
P.y += GAP; |
| 3180 |
vertices[i].x = -P.x; |
| 3181 |
vertices[i].y = -P.y; |
| 3182 |
i++; |
| 3183 |
vertices[i].x = P.x; |
| 3184 |
vertices[i].y = P.y; |
| 3185 |
i++; |
| 3186 |
} |
| 3187 |
sz = 2. * P.x; |
| 3188 |
} else { |
| 3189 |
i = sides; |
| 3190 |
} |
| 3191 |
|
| 3192 |
if (peripheries >= 1 && penwidth > 0 && outp > peripheries) { |
| 3193 |
// add an outline at half the penwidth outside the outermost periphery |
| 3194 |
P.x += penwidth / 2; |
| 3195 |
P.y += penwidth / 2; |
| 3196 |
vertices[i].x = -P.x; |
| 3197 |
vertices[i].y = -P.y; |
| 3198 |
i++; |
| 3199 |
vertices[i].x = P.x; |
| 3200 |
vertices[i].y = P.y; |
| 3201 |
i++; |
| 3202 |
} |
| 3203 |
const double sz_outline = 2. * P.x; |
| 3204 |
|
| 3205 |
poly->regular = true; |
| 3206 |
poly->peripheries = peripheries; |
| 3207 |
poly->sides = 2; |
| 3208 |
poly->orientation = 0; |
| 3209 |
poly->skew = 0; |
| 3210 |
poly->distortion = 0; |
| 3211 |
poly->vertices = vertices; |
| 3212 |
|
| 3213 |
ND_height(n) = ND_width(n) = PS2INCH(sz); |
| 3214 |
ND_outline_height(n) = ND_outline_width(n) = PS2INCH(sz_outline); |
| 3215 |
ND_shape_info(n) = poly; |
| 3216 |
} |
| 3217 |
|
| 3218 |
static bool point_inside(inside_t * inside_context, pointf p) |
| 3219 |
{ |
| 3220 |
pointf P; |
| 3221 |
node_t *n; |
| 3222 |
|
| 3223 |
if (!inside_context) { |
| 3224 |
return false; |
| 3225 |
} |
| 3226 |
|
| 3227 |
n = inside_context->s.n; |
| 3228 |
P = ccwrotatepf(p, 90 * GD_rankdir(agraphof(n))); |
| 3229 |
|
| 3230 |
if (n != inside_context->s.lastn) { |
| 3231 |
size_t outp; |
| 3232 |
polygon_t *poly = ND_shape_info(n); |
| 3233 |
const size_t sides = 2; |
| 3234 |
const double penwidth = late_double(n, N_penwidth, DEFAULT_NODEPENWIDTH, |
| 3235 |
MIN_NODEPENWIDTH); |
| 3236 |
|
| 3237 |
if (poly->peripheries >= 1 && penwidth > 0) { |
| 3238 |
/* index to outline, i.e., the outer-periphery with penwidth taken into account */ |
| 3239 |
outp = sides * (poly->peripheries + 1 - 1); |
| 3240 |
} else if (poly->peripheries < 1) { |
| 3241 |
outp = 0; |
| 3242 |
} else { |
| 3243 |
/* index to outer-periphery */ |
| 3244 |
outp = sides * (poly->peripheries - 1); |
| 3245 |
} |
| 3246 |
|
| 3247 |
inside_context->s.radius = poly->vertices[outp + 1].x; |
| 3248 |
inside_context->s.lastn = n; |
| 3249 |
} |
| 3250 |
|
| 3251 |
/* inside bounding box? */ |
| 3252 |
if (fabs(P.x) > inside_context->s.radius || |
| 3253 |
fabs(P.y) > inside_context->s.radius) |
| 3254 |
return false; |
| 3255 |
|
| 3256 |
return hypot(P.x, P.y) <= inside_context->s.radius; |
| 3257 |
} |
| 3258 |
|
| 3259 |
static void point_gencode(GVJ_t * job, node_t * n) |
| 3260 |
{ |
| 3261 |
obj_state_t *obj = job->obj; |
| 3262 |
polygon_t *poly; |
| 3263 |
pointf P, *vertices; |
| 3264 |
bool filled; |
| 3265 |
char *color; |
| 3266 |
int doMap = obj->url || obj->explicit_tooltip; |
| 3267 |
|
| 3268 |
if (doMap && !(job->flags & EMIT_CLUSTERS_LAST)) |
| 3269 |
gvrender_begin_anchor(job, |
| 3270 |
obj->url, obj->tooltip, obj->target, |
| 3271 |
obj->id); |
| 3272 |
|
| 3273 |
poly = ND_shape_info(n); |
| 3274 |
vertices = poly->vertices; |
| 3275 |
const size_t sides = poly->sides; |
| 3276 |
size_t peripheries = poly->peripheries; |
| 3277 |
|
| 3278 |
graphviz_polygon_style_t style = {0}; |
| 3279 |
checkStyle(n, &style); |
| 3280 |
if (style.invisible) |
| 3281 |
gvrender_set_style(job, point_style); |
| 3282 |
else |
| 3283 |
gvrender_set_style(job, &point_style[1]); |
| 3284 |
if (N_penwidth) |
| 3285 |
gvrender_set_penwidth(job, late_double(n, N_penwidth, 1.0, 0.0)); |
| 3286 |
|
| 3287 |
if (ND_gui_state(n) & GUI_STATE_ACTIVE) { |
| 3288 |
color = DEFAULT_ACTIVEPENCOLOR; |
| 3289 |
gvrender_set_pencolor(job, color); |
| 3290 |
color = DEFAULT_ACTIVEFILLCOLOR; |
| 3291 |
gvrender_set_fillcolor(job, color); |
| 3292 |
} else if (ND_gui_state(n) & GUI_STATE_SELECTED) { |
| 3293 |
color = DEFAULT_SELECTEDPENCOLOR; |
| 3294 |
gvrender_set_pencolor(job, color); |
| 3295 |
color = DEFAULT_SELECTEDFILLCOLOR; |
| 3296 |
gvrender_set_fillcolor(job, color); |
| 3297 |
} else if (ND_gui_state(n) & GUI_STATE_DELETED) { |
| 3298 |
color = DEFAULT_DELETEDPENCOLOR; |
| 3299 |
gvrender_set_pencolor(job, color); |
| 3300 |
color = DEFAULT_DELETEDFILLCOLOR; |
| 3301 |
gvrender_set_fillcolor(job, color); |
| 3302 |
} else if (ND_gui_state(n) & GUI_STATE_VISITED) { |
| 3303 |
color = DEFAULT_VISITEDPENCOLOR; |
| 3304 |
gvrender_set_pencolor(job, color); |
| 3305 |
color = DEFAULT_VISITEDFILLCOLOR; |
| 3306 |
gvrender_set_fillcolor(job, color); |
| 3307 |
} else { |
| 3308 |
color = findFillDflt(n, "black"); |
| 3309 |
gvrender_set_fillcolor(job, color); /* emit fill color */ |
| 3310 |
penColor(job, n); /* emit pen color */ |
| 3311 |
} |
| 3312 |
filled = true; |
| 3313 |
|
| 3314 |
/* if no boundary but filled, set boundary color to fill color */ |
| 3315 |
if (peripheries == 0) { |
| 3316 |
peripheries = 1; |
| 3317 |
if (color[0]) |
| 3318 |
gvrender_set_pencolor(job, color); |
| 3319 |
} |
| 3320 |
|
| 3321 |
for (size_t j = 0; j < peripheries; j++) { |
| 3322 |
enum {A_size = 2}; |
| 3323 |
pointf AF[A_size] = {{0}}; |
| 3324 |
for (size_t i = 0; i < sides; i++) { |
| 3325 |
P = vertices[i + j * sides]; |
| 3326 |
if (i < A_size) { |
| 3327 |
AF[i].x = P.x + ND_coord(n).x; |
| 3328 |
AF[i].y = P.y + ND_coord(n).y; |
| 3329 |
} |
| 3330 |
} |
| 3331 |
gvrender_ellipse(job, AF, filled); |
| 3332 |
/* fill innermost periphery only */ |
| 3333 |
filled = false; |
| 3334 |
} |
| 3335 |
|
| 3336 |
if (doMap) { |
| 3337 |
if (job->flags & EMIT_CLUSTERS_LAST) |
| 3338 |
gvrender_begin_anchor(job, |
| 3339 |
obj->url, obj->tooltip, obj->target, |
| 3340 |
obj->id); |
| 3341 |
gvrender_end_anchor(job); |
| 3342 |
} |
| 3343 |
} |
| 3344 |
|
| 3345 |
/* the "record" shape is a rudimentary table formatter */ |
| 3346 |
|
| 3347 |
#define HASTEXT 1 |
| 3348 |
#define HASPORT 2 |
| 3349 |
#define HASTABLE 4 |
| 3350 |
#define INTEXT 8 |
| 3351 |
#define INPORT 16 |
| 3352 |
|
| 3353 |
static bool ISCTRL(int c) { |
| 3354 |
return c == '{' || c == '}' || c == '|' || c == '<' || c == '>'; |
| 3355 |
} |
| 3356 |
|
| 3357 |
static char *reclblp; |
| 3358 |
|
| 3359 |
static void free_field(field_t * f) |
| 3360 |
{ |
| 3361 |
int i; |
| 3362 |
|
| 3363 |
for (i = 0; i < f->n_flds; i++) { |
| 3364 |
free_field(f->fld[i]); |
| 3365 |
} |
| 3366 |
|
| 3367 |
free(f->id); |
| 3368 |
free_label(f->lp); |
| 3369 |
free(f->fld); |
| 3370 |
free(f); |
| 3371 |
} |
| 3372 |
|
| 3373 |
/* parse_error: |
| 3374 |
* Clean up memory allocated in parse_reclbl, then return NULL |
| 3375 |
*/ |
| 3376 |
static field_t *parse_error(field_t *rv, char *portname) { |
| 3377 |
free_field(rv); |
| 3378 |
free(portname); |
| 3379 |
return NULL; |
| 3380 |
} |
| 3381 |
|
| 3382 |
static field_t *parse_reclbl(node_t *n, bool LR, bool flag, char *text) { |
| 3383 |
field_t *fp, *rv = gv_alloc(sizeof(field_t)); |
| 3384 |
char *tsp, *psp=NULL, *hstsp, *hspsp=NULL, *sp; |
| 3385 |
char *tmpport = NULL; |
| 3386 |
int cnt, mode, fi; |
| 3387 |
textlabel_t *lbl = ND_label(n); |
| 3388 |
unsigned char uc; |
| 3389 |
|
| 3390 |
fp = NULL; |
| 3391 |
size_t maxf; |
| 3392 |
for (maxf = 1, cnt = 0, sp = reclblp; *sp; sp++) { |
| 3393 |
if (*sp == '\\') { |
| 3394 |
sp++; |
| 3395 |
if (*sp && (*sp == '{' || *sp == '}' || *sp == '|' || *sp == '\\')) |
| 3396 |
continue; |
| 3397 |
} |
| 3398 |
if (*sp == '{') |
| 3399 |
cnt++; |
| 3400 |
else if (*sp == '}') |
| 3401 |
cnt--; |
| 3402 |
else if (*sp == '|' && cnt == 0) |
| 3403 |
maxf++; |
| 3404 |
if (cnt < 0) |
| 3405 |
break; |
| 3406 |
} |
| 3407 |
rv->fld = gv_calloc(maxf, sizeof(field_t*)); |
| 3408 |
rv->LR = LR; |
| 3409 |
mode = 0; |
| 3410 |
fi = 0; |
| 3411 |
hstsp = tsp = text; |
| 3412 |
bool wflag = true; |
| 3413 |
bool ishardspace = false; |
| 3414 |
while (wflag) { |
| 3415 |
if ((uc = *(unsigned char*)reclblp) && uc < ' ') { /* Ignore non-0 control characters */ |
| 3416 |
reclblp++; |
| 3417 |
continue; |
| 3418 |
} |
| 3419 |
switch (*reclblp) { |
| 3420 |
case '<': |
| 3421 |
if (mode & (HASTABLE | HASPORT)) |
| 3422 |
return parse_error(rv, tmpport); |
| 3423 |
if (lbl->html) |
| 3424 |
goto dotext; |
| 3425 |
mode |= (HASPORT | INPORT); |
| 3426 |
reclblp++; |
| 3427 |
hspsp = psp = text; |
| 3428 |
break; |
| 3429 |
case '>': |
| 3430 |
if (lbl->html) |
| 3431 |
goto dotext; |
| 3432 |
if (!(mode & INPORT)) |
| 3433 |
return parse_error(rv, tmpport); |
| 3434 |
if (psp > text + 1 && psp - 1 != hspsp && *(psp - 1) == ' ') |
| 3435 |
psp--; |
| 3436 |
*psp = '\000'; |
| 3437 |
tmpport = gv_strdup(text); |
| 3438 |
mode &= ~INPORT; |
| 3439 |
reclblp++; |
| 3440 |
break; |
| 3441 |
case '{': |
| 3442 |
reclblp++; |
| 3443 |
if (mode != 0 || !*reclblp) |
| 3444 |
return parse_error(rv, tmpport); |
| 3445 |
mode = HASTABLE; |
| 3446 |
if (!(rv->fld[fi++] = parse_reclbl(n, !LR, false, text))) |
| 3447 |
return parse_error(rv, tmpport); |
| 3448 |
break; |
| 3449 |
case '}': |
| 3450 |
case '|': |
| 3451 |
case '\000': |
| 3452 |
if ((!*reclblp && !flag) || (mode & INPORT)) |
| 3453 |
return parse_error(rv, tmpport); |
| 3454 |
if (!(mode & HASTABLE)) |
| 3455 |
fp = rv->fld[fi++] = gv_alloc(sizeof(field_t)); |
| 3456 |
if (tmpport) { |
| 3457 |
fp->id = tmpport; |
| 3458 |
tmpport = NULL; |
| 3459 |
} |
| 3460 |
if (!(mode & (HASTEXT | HASTABLE))) { |
| 3461 |
mode |= HASTEXT; |
| 3462 |
*tsp++ = ' '; |
| 3463 |
} |
| 3464 |
if (mode & HASTEXT) { |
| 3465 |
if (tsp > text + 1 && tsp - 1 != hstsp && *(tsp - 1) == ' ') |
| 3466 |
tsp--; |
| 3467 |
*tsp = '\000'; |
| 3468 |
fp->lp = make_label(n, text, lbl->html, false, |
| 3469 |
lbl->fontsize, lbl->fontname, lbl->fontcolor); |
| 3470 |
fp->LR = true; |
| 3471 |
hstsp = tsp = text; |
| 3472 |
} |
| 3473 |
if (*reclblp) { |
| 3474 |
if (*reclblp == '}') { |
| 3475 |
reclblp++; |
| 3476 |
rv->n_flds = fi; |
| 3477 |
return rv; |
| 3478 |
} |
| 3479 |
mode = 0; |
| 3480 |
reclblp++; |
| 3481 |
} else |
| 3482 |
wflag = false; |
| 3483 |
break; |
| 3484 |
case '\\': |
| 3485 |
if (*(reclblp + 1)) { |
| 3486 |
if (ISCTRL(*(reclblp + 1))) { |
| 3487 |
// nothing |
| 3488 |
} else if (*(reclblp + 1) == ' ' && !lbl->html) |
| 3489 |
ishardspace = true; |
| 3490 |
else { |
| 3491 |
*tsp++ = '\\'; |
| 3492 |
mode |= INTEXT | HASTEXT; |
| 3493 |
} |
| 3494 |
reclblp++; |
| 3495 |
} |
| 3496 |
/* fall through */ |
| 3497 |
default: |
| 3498 |
dotext: |
| 3499 |
if ((mode & HASTABLE) && *reclblp != ' ') |
| 3500 |
return parse_error(rv, tmpport); |
| 3501 |
if (!(mode & (INTEXT | INPORT)) && *reclblp != ' ') |
| 3502 |
mode |= INTEXT | HASTEXT; |
| 3503 |
if (mode & INTEXT) { |
| 3504 |
if (!(*reclblp == ' ' && !ishardspace && *(tsp - 1) == ' ' |
| 3505 |
&& !lbl->html)) |
| 3506 |
*tsp++ = *reclblp; |
| 3507 |
if (ishardspace) |
| 3508 |
hstsp = tsp - 1; |
| 3509 |
} else if (mode & INPORT) { |
| 3510 |
if (!(*reclblp == ' ' && !ishardspace && |
| 3511 |
(psp == text || *(psp - 1) == ' '))) |
| 3512 |
*psp++ = *reclblp; |
| 3513 |
if (ishardspace) |
| 3514 |
hspsp = psp - 1; |
| 3515 |
} |
| 3516 |
reclblp++; |
| 3517 |
while ((*reclblp & 0xc0) == 0x80) |
| 3518 |
*tsp++ = *reclblp++; |
| 3519 |
break; |
| 3520 |
} |
| 3521 |
} |
| 3522 |
rv->n_flds = fi; |
| 3523 |
return rv; |
| 3524 |
} |
| 3525 |
|
| 3526 |
static pointf size_reclbl(node_t * n, field_t * f) |
| 3527 |
{ |
| 3528 |
int i; |
| 3529 |
char *p; |
| 3530 |
double marginx, marginy; |
| 3531 |
pointf d, d0; |
| 3532 |
pointf dimen; |
| 3533 |
|
| 3534 |
if (f->lp) { |
| 3535 |
dimen = f->lp->dimen; |
| 3536 |
|
| 3537 |
/* minimal whitespace around label */ |
| 3538 |
if (dimen.x > 0.0 || dimen.y > 0.0) { |
| 3539 |
/* padding */ |
| 3540 |
if ((p = agget(n, "margin"))) { |
| 3541 |
i = sscanf(p, "%lf,%lf", &marginx, &marginy); |
| 3542 |
if (i > 0) { |
| 3543 |
dimen.x += 2 * INCH2PS(marginx); |
| 3544 |
if (i > 1) |
| 3545 |
dimen.y += 2 * INCH2PS(marginy); |
| 3546 |
else |
| 3547 |
dimen.y += 2 * INCH2PS(marginx); |
| 3548 |
} else |
| 3549 |
PAD(dimen); |
| 3550 |
} else |
| 3551 |
PAD(dimen); |
| 3552 |
} |
| 3553 |
d = dimen; |
| 3554 |
} else { |
| 3555 |
d.x = d.y = 0; |
| 3556 |
for (i = 0; i < f->n_flds; i++) { |
| 3557 |
d0 = size_reclbl(n, f->fld[i]); |
| 3558 |
if (f->LR) { |
| 3559 |
d.x += d0.x; |
| 3560 |
d.y = fmax(d.y, d0.y); |
| 3561 |
} else { |
| 3562 |
d.y += d0.y; |
| 3563 |
d.x = fmax(d.x, d0.x); |
| 3564 |
} |
| 3565 |
} |
| 3566 |
} |
| 3567 |
f->size = d; |
| 3568 |
return d; |
| 3569 |
} |
| 3570 |
|
| 3571 |
static void resize_reclbl(field_t *f, pointf sz, bool nojustify_p) { |
| 3572 |
int i, amt; |
| 3573 |
double inc; |
| 3574 |
pointf d; |
| 3575 |
pointf newsz; |
| 3576 |
field_t *sf; |
| 3577 |
|
| 3578 |
/* adjust field */ |
| 3579 |
d.x = sz.x - f->size.x; |
| 3580 |
d.y = sz.y - f->size.y; |
| 3581 |
f->size = sz; |
| 3582 |
|
| 3583 |
/* adjust text area */ |
| 3584 |
if (f->lp && !nojustify_p) { |
| 3585 |
f->lp->space.x += d.x; |
| 3586 |
f->lp->space.y += d.y; |
| 3587 |
} |
| 3588 |
|
| 3589 |
/* adjust children */ |
| 3590 |
if (f->n_flds) { |
| 3591 |
|
| 3592 |
if (f->LR) |
| 3593 |
inc = d.x / f->n_flds; |
| 3594 |
else |
| 3595 |
inc = d.y / f->n_flds; |
| 3596 |
for (i = 0; i < f->n_flds; i++) { |
| 3597 |
sf = f->fld[i]; |
| 3598 |
amt = (int)((i + 1) * inc) - (int)(i * inc); |
| 3599 |
if (f->LR) |
| 3600 |
newsz = (pointf){sf->size.x + amt, sz.y}; |
| 3601 |
else |
| 3602 |
newsz = (pointf){sz.x, sf->size.y + amt}; |
| 3603 |
resize_reclbl(sf, newsz, nojustify_p); |
| 3604 |
} |
| 3605 |
} |
| 3606 |
} |
| 3607 |
|
| 3608 |
/* pos_reclbl: |
| 3609 |
* Assign position info for each field. Also, set |
| 3610 |
* the sides attribute, which indicates which sides of the |
| 3611 |
* record are accessible to the field. |
| 3612 |
*/ |
| 3613 |
static void pos_reclbl(field_t *f, pointf ul, unsigned char sides) { |
| 3614 |
int i, last; |
| 3615 |
unsigned char mask; |
| 3616 |
|
| 3617 |
f->sides = sides; |
| 3618 |
f->b.LL = (pointf){ul.x, ul.y - f->size.y}; |
| 3619 |
f->b.UR = (pointf){ul.x + f->size.x, ul.y}; |
| 3620 |
last = f->n_flds - 1; |
| 3621 |
for (i = 0; i <= last; i++) { |
| 3622 |
if (sides) { |
| 3623 |
if (f->LR) { |
| 3624 |
if (i == 0) { |
| 3625 |
if (i == last) |
| 3626 |
mask = TOP | BOTTOM | RIGHT | LEFT; |
| 3627 |
else |
| 3628 |
mask = TOP | BOTTOM | LEFT; |
| 3629 |
} else if (i == last) |
| 3630 |
mask = TOP | BOTTOM | RIGHT; |
| 3631 |
else |
| 3632 |
mask = TOP | BOTTOM; |
| 3633 |
} else { |
| 3634 |
if (i == 0) { |
| 3635 |
if (i == last) |
| 3636 |
mask = TOP | BOTTOM | RIGHT | LEFT; |
| 3637 |
else |
| 3638 |
mask = TOP | RIGHT | LEFT; |
| 3639 |
} else if (i == last) |
| 3640 |
mask = LEFT | BOTTOM | RIGHT; |
| 3641 |
else |
| 3642 |
mask = LEFT | RIGHT; |
| 3643 |
} |
| 3644 |
} else |
| 3645 |
mask = 0; |
| 3646 |
pos_reclbl(f->fld[i], ul, (unsigned char)(sides & mask)); |
| 3647 |
if (f->LR) |
| 3648 |
ul.x = ul.x + f->fld[i]->size.x; |
| 3649 |
else |
| 3650 |
ul.y = ul.y - f->fld[i]->size.y; |
| 3651 |
} |
| 3652 |
} |
| 3653 |
|
| 3654 |
#if defined(DEBUG) && DEBUG > 1 |
| 3655 |
static void indent(int l) |
| 3656 |
{ |
| 3657 |
int i; |
| 3658 |
for (i = 0; i < l; i++) |
| 3659 |
fputs(" ", stderr); |
| 3660 |
} |
| 3661 |
|
| 3662 |
static void prbox(boxf b) |
| 3663 |
{ |
| 3664 |
fprintf(stderr, "((%.5g,%.5g),(%.5g,%.5g))\n", b.LL.x, b.LL.y, b.UR.x, |
| 3665 |
b.UR.y); |
| 3666 |
} |
| 3667 |
|
| 3668 |
static void dumpL(field_t * info, int level) |
| 3669 |
{ |
| 3670 |
int i; |
| 3671 |
|
| 3672 |
indent(level); |
| 3673 |
if (info->n_flds == 0) { |
| 3674 |
fprintf(stderr, "Label \"%s\" ", info->lp->text); |
| 3675 |
prbox(info->b); |
| 3676 |
} else { |
| 3677 |
fprintf(stderr, "Tbl "); |
| 3678 |
prbox(info->b); |
| 3679 |
for (i = 0; i < info->n_flds; i++) { |
| 3680 |
dumpL(info->fld[i], level + 1); |
| 3681 |
} |
| 3682 |
} |
| 3683 |
} |
| 3684 |
#endif |
| 3685 |
|
| 3686 |
/* syntax of labels: foo|bar|baz or foo|(recursive|label)|baz */ |
| 3687 |
static void record_init(node_t * n) |
| 3688 |
{ |
| 3689 |
field_t *info; |
| 3690 |
pointf sz; |
| 3691 |
int flip; |
| 3692 |
size_t len; |
| 3693 |
unsigned char sides = BOTTOM | RIGHT | TOP | LEFT; |
| 3694 |
|
| 3695 |
/* Always use rankdir to determine how records are laid out */ |
| 3696 |
flip = !GD_realflip(agraphof(n)); |
| 3697 |
reclblp = ND_label(n)->text; |
| 3698 |
len = strlen(reclblp); |
| 3699 |
/* For some forgotten reason, an empty label is parsed into a space, so |
| 3700 |
* we need at least two bytes in textbuf, as well as accounting for the |
| 3701 |
* error path involving "\\N" below. |
| 3702 |
*/ |
| 3703 |
len = MAX(MAX(len, 1), strlen("\\N")); |
| 3704 |
char *textbuf = gv_calloc(len + 1, sizeof(char)); // temp buffer for storing labels |
| 3705 |
if (!(info = parse_reclbl(n, flip, true, textbuf))) { |
| 3706 |
agerrorf("bad label format %s\n", ND_label(n)->text); |
| 3707 |
reclblp = "\\N"; |
| 3708 |
info = parse_reclbl(n, flip, true, textbuf); |
| 3709 |
} |
| 3710 |
free(textbuf); |
| 3711 |
size_reclbl(n, info); |
| 3712 |
sz.x = INCH2PS(ND_width(n)); |
| 3713 |
sz.y = INCH2PS(ND_height(n)); |
| 3714 |
if (mapbool(late_string(n, N_fixed, "false"))) { |
| 3715 |
if (sz.x < info->size.x || sz.y < info->size.y) { |
| 3716 |
/* should check that the record really won't fit, e.g., there may be no text. |
| 3717 |
agwarningf("node '%s' size may be too small\n", agnameof(n)); |
| 3718 |
*/ |
| 3719 |
} |
| 3720 |
} else { |
| 3721 |
sz.x = fmax(info->size.x, sz.x); |
| 3722 |
sz.y = fmax(info->size.y, sz.y); |
| 3723 |
} |
| 3724 |
resize_reclbl(info, sz, mapbool(late_string(n, N_nojustify, "false"))); |
| 3725 |
pointf ul = {-sz.x / 2., sz.y / 2.}; /* FIXME - is this still true: suspected to introduce rounding error - see Kluge below */ |
| 3726 |
pos_reclbl(info, ul, sides); |
| 3727 |
ND_width(n) = PS2INCH(info->size.x); |
| 3728 |
ND_height(n) = PS2INCH(info->size.y + 1); /* Kluge!! +1 to fix rounding diff between layout and rendering |
| 3729 |
otherwise we can get -1 coords in output */ |
| 3730 |
ND_shape_info(n) = info; |
| 3731 |
} |
| 3732 |
|
| 3733 |
static void record_free(node_t * n) |
| 3734 |
{ |
| 3735 |
field_t *p = ND_shape_info(n); |
| 3736 |
|
| 3737 |
free_field(p); |
| 3738 |
} |
| 3739 |
|
| 3740 |
static field_t *map_rec_port(field_t * f, char *str) |
| 3741 |
{ |
| 3742 |
field_t *rv; |
| 3743 |
int sub; |
| 3744 |
|
| 3745 |
if (f->id && streq(f->id, str)) |
| 3746 |
rv = f; |
| 3747 |
else { |
| 3748 |
rv = NULL; |
| 3749 |
for (sub = 0; sub < f->n_flds; sub++) |
| 3750 |
if ((rv = map_rec_port(f->fld[sub], str))) |
| 3751 |
break; |
| 3752 |
} |
| 3753 |
return rv; |
| 3754 |
} |
| 3755 |
|
| 3756 |
static port record_port(node_t * n, char *portname, char *compass) |
| 3757 |
{ |
| 3758 |
field_t *f; |
| 3759 |
field_t *subf; |
| 3760 |
port rv; |
| 3761 |
unsigned char sides; // bitmap of which sides the port lies along |
| 3762 |
|
| 3763 |
if (portname[0] == '\0') |
| 3764 |
return Center; |
| 3765 |
sides = BOTTOM | RIGHT | TOP | LEFT; |
| 3766 |
if (compass == NULL) |
| 3767 |
compass = "_"; |
| 3768 |
f = ND_shape_info(n); |
| 3769 |
if ((subf = map_rec_port(f, portname))) { |
| 3770 |
if (compassPort(n, &subf->b, &rv, compass, subf->sides, NULL)) { |
| 3771 |
agwarningf( |
| 3772 |
"node %s, port %s, unrecognized compass point '%s' - ignored\n", |
| 3773 |
agnameof(n), portname, compass); |
| 3774 |
} |
| 3775 |
} else if (compassPort(n, &f->b, &rv, portname, sides, NULL)) { |
| 3776 |
unrecognized(n, portname); |
| 3777 |
} |
| 3778 |
|
| 3779 |
return rv; |
| 3780 |
} |
| 3781 |
|
| 3782 |
/* record_inside: |
| 3783 |
* Note that this does not handle Mrecords correctly. It assumes |
| 3784 |
* everything is a rectangle. |
| 3785 |
*/ |
| 3786 |
static bool record_inside(inside_t * inside_context, pointf p) |
| 3787 |
{ |
| 3788 |
|
| 3789 |
field_t *fld0; |
| 3790 |
boxf *bp = inside_context->s.bp; |
| 3791 |
node_t *n = inside_context->s.n; |
| 3792 |
boxf bbox; |
| 3793 |
|
| 3794 |
/* convert point to node coordinate system */ |
| 3795 |
p = ccwrotatepf(p, 90 * GD_rankdir(agraphof(n))); |
| 3796 |
|
| 3797 |
if (bp == NULL) { |
| 3798 |
fld0 = ND_shape_info(n); |
| 3799 |
bbox = fld0->b; |
| 3800 |
} else |
| 3801 |
bbox = *bp; |
| 3802 |
|
| 3803 |
// adjust bbox to outline, i.e., the periphery with penwidth taken into account |
| 3804 |
const double penwidth = late_double(n, N_penwidth, DEFAULT_NODEPENWIDTH, |
| 3805 |
MIN_NODEPENWIDTH); |
| 3806 |
const pointf extension = {penwidth / 2, penwidth / 2}; |
| 3807 |
bbox.LL = sub_pointf(bbox.LL, extension); |
| 3808 |
bbox.UR = add_pointf(bbox.UR, extension); |
| 3809 |
|
| 3810 |
return INSIDE(p, bbox); |
| 3811 |
} |
| 3812 |
|
| 3813 |
/* record_path: |
| 3814 |
* Generate box path from port to border. |
| 3815 |
* See poly_path for constraints. |
| 3816 |
*/ |
| 3817 |
static int record_path(node_t * n, port * prt, int side, boxf rv[], |
| 3818 |
int *kptr) |
| 3819 |
{ |
| 3820 |
int i; |
| 3821 |
double ls, rs; |
| 3822 |
pointf p; |
| 3823 |
field_t *info; |
| 3824 |
|
| 3825 |
if (!prt->defined) |
| 3826 |
return 0; |
| 3827 |
p = prt->p; |
| 3828 |
info = ND_shape_info(n); |
| 3829 |
|
| 3830 |
for (i = 0; i < info->n_flds; i++) { |
| 3831 |
if (!GD_flip(agraphof(n))) { |
| 3832 |
ls = info->fld[i]->b.LL.x; |
| 3833 |
rs = info->fld[i]->b.UR.x; |
| 3834 |
} else { |
| 3835 |
ls = info->fld[i]->b.LL.y; |
| 3836 |
rs = info->fld[i]->b.UR.y; |
| 3837 |
} |
| 3838 |
if (BETWEEN(ls, p.x, rs)) { |
| 3839 |
/* FIXME: I don't understand this code */ |
| 3840 |
if (GD_flip(agraphof(n))) { |
| 3841 |
rv[0] = flip_rec_boxf(info->fld[i]->b, ND_coord(n)); |
| 3842 |
} else { |
| 3843 |
rv[0].LL.x = ND_coord(n).x + ls; |
| 3844 |
rv[0].LL.y = ND_coord(n).y - (ND_ht(n) / 2); |
| 3845 |
rv[0].UR.x = ND_coord(n).x + rs; |
| 3846 |
} |
| 3847 |
rv[0].UR.y = ND_coord(n).y + (ND_ht(n) / 2); |
| 3848 |
*kptr = 1; |
| 3849 |
break; |
| 3850 |
} |
| 3851 |
} |
| 3852 |
return side; |
| 3853 |
} |
| 3854 |
|
| 3855 |
static void gen_fields(GVJ_t * job, node_t * n, field_t * f) |
| 3856 |
{ |
| 3857 |
int i; |
| 3858 |
pointf AF[2], coord; |
| 3859 |
|
| 3860 |
if (f->lp) { |
| 3861 |
f->lp->pos = add_pointf(mid_pointf(f->b.LL, f->b.UR), ND_coord(n)); |
| 3862 |
emit_label(job, EMIT_NLABEL, f->lp); |
| 3863 |
penColor(job, n); |
| 3864 |
} |
| 3865 |
|
| 3866 |
coord = ND_coord(n); |
| 3867 |
for (i = 0; i < f->n_flds; i++) { |
| 3868 |
if (i > 0) { |
| 3869 |
if (f->LR) { |
| 3870 |
AF[0] = f->fld[i]->b.LL; |
| 3871 |
AF[1].x = AF[0].x; |
| 3872 |
AF[1].y = f->fld[i]->b.UR.y; |
| 3873 |
} else { |
| 3874 |
AF[1] = f->fld[i]->b.UR; |
| 3875 |
AF[0].x = f->fld[i]->b.LL.x; |
| 3876 |
AF[0].y = AF[1].y; |
| 3877 |
} |
| 3878 |
AF[0] = add_pointf(AF[0], coord); |
| 3879 |
AF[1] = add_pointf(AF[1], coord); |
| 3880 |
gvrender_polyline(job, AF, 2); |
| 3881 |
} |
| 3882 |
gen_fields(job, n, f->fld[i]); |
| 3883 |
} |
| 3884 |
} |
| 3885 |
|
| 3886 |
static void record_gencode(GVJ_t * job, node_t * n) |
| 3887 |
{ |
| 3888 |
obj_state_t *obj = job->obj; |
| 3889 |
boxf BF; |
| 3890 |
pointf AF[4]; |
| 3891 |
field_t *f; |
| 3892 |
int doMap = obj->url || obj->explicit_tooltip; |
| 3893 |
int filled; |
| 3894 |
|
| 3895 |
f = ND_shape_info(n); |
| 3896 |
BF = f->b; |
| 3897 |
BF.LL.x += ND_coord(n).x; |
| 3898 |
BF.LL.y += ND_coord(n).y; |
| 3899 |
BF.UR.x += ND_coord(n).x; |
| 3900 |
BF.UR.y += ND_coord(n).y; |
| 3901 |
|
| 3902 |
if (doMap && !(job->flags & EMIT_CLUSTERS_LAST)) |
| 3903 |
gvrender_begin_anchor(job, |
| 3904 |
obj->url, obj->tooltip, obj->target, |
| 3905 |
obj->id); |
| 3906 |
graphviz_polygon_style_t style = stylenode(job, n); |
| 3907 |
penColor(job, n); |
| 3908 |
char *clrs[2] = {0}; |
| 3909 |
if (style.filled) { |
| 3910 |
char* fillcolor = findFill (n); |
| 3911 |
double frac; |
| 3912 |
|
| 3913 |
if (findStopColor (fillcolor, clrs, &frac)) { |
| 3914 |
gvrender_set_fillcolor(job, clrs[0]); |
| 3915 |
if (clrs[1]) |
| 3916 |
gvrender_set_gradient_vals(job,clrs[1],late_int(n,N_gradientangle,0,0), frac); |
| 3917 |
else |
| 3918 |
gvrender_set_gradient_vals(job,DEFAULT_COLOR,late_int(n,N_gradientangle,0,0), frac); |
| 3919 |
if (style.radial) |
| 3920 |
filled = RGRADIENT; |
| 3921 |
else |
| 3922 |
filled = GRADIENT; |
| 3923 |
} |
| 3924 |
else { |
| 3925 |
filled = FILL; |
| 3926 |
gvrender_set_fillcolor(job, fillcolor); |
| 3927 |
} |
| 3928 |
} |
| 3929 |
else filled = 0; |
| 3930 |
|
| 3931 |
if (streq(ND_shape(n)->name, "Mrecord")) |
| 3932 |
style.rounded = true; |
| 3933 |
if (SPECIAL_CORNERS(style)) { |
| 3934 |
AF[0] = BF.LL; |
| 3935 |
AF[2] = BF.UR; |
| 3936 |
AF[1].x = AF[2].x; |
| 3937 |
AF[1].y = AF[0].y; |
| 3938 |
AF[3].x = AF[0].x; |
| 3939 |
AF[3].y = AF[2].y; |
| 3940 |
round_corners(job, AF, 4, style, filled); |
| 3941 |
} else { |
| 3942 |
gvrender_box(job, BF, filled); |
| 3943 |
} |
| 3944 |
|
| 3945 |
gen_fields(job, n, f); |
| 3946 |
|
| 3947 |
free (clrs[0]); |
| 3948 |
free(clrs[1]); |
| 3949 |
|
| 3950 |
if (doMap) { |
| 3951 |
if (job->flags & EMIT_CLUSTERS_LAST) |
| 3952 |
gvrender_begin_anchor(job, |
| 3953 |
obj->url, obj->tooltip, obj->target, |
| 3954 |
obj->id); |
| 3955 |
gvrender_end_anchor(job); |
| 3956 |
} |
| 3957 |
} |
| 3958 |
|
| 3959 |
static shape_desc **UserShape; |
| 3960 |
static size_t N_UserShape; |
| 3961 |
|
| 3962 |
shape_desc *find_user_shape(const char *name) |
| 3963 |
{ |
| 3964 |
if (UserShape) { |
| 3965 |
for (size_t i = 0; i < N_UserShape; i++) { |
| 3966 |
if (streq(UserShape[i]->name, name)) |
| 3967 |
return UserShape[i]; |
| 3968 |
} |
| 3969 |
} |
| 3970 |
return NULL; |
| 3971 |
} |
| 3972 |
|
| 3973 |
static shape_desc *user_shape(char *name) |
| 3974 |
{ |
| 3975 |
shape_desc *p; |
| 3976 |
|
| 3977 |
if ((p = find_user_shape(name))) |
| 3978 |
return p; |
| 3979 |
size_t i = N_UserShape++; |
| 3980 |
UserShape = gv_recalloc(UserShape, N_UserShape - 1, N_UserShape, sizeof(shape_desc *)); |
| 3981 |
p = UserShape[i] = gv_alloc(sizeof(shape_desc)); |
| 3982 |
*p = Shapes[0]; |
| 3983 |
p->name = strdup(name); |
| 3984 |
if (Lib == NULL && !streq(name, "custom")) { |
| 3985 |
agwarningf("using %s for unknown shape %s\n", Shapes[0].name, |
| 3986 |
p->name); |
| 3987 |
p->usershape = false; |
| 3988 |
} else { |
| 3989 |
p->usershape = true; |
| 3990 |
} |
| 3991 |
return p; |
| 3992 |
} |
| 3993 |
|
| 3994 |
shape_desc *bind_shape(char *name, node_t * np) |
| 3995 |
{ |
| 3996 |
shape_desc *ptr, *rv = NULL; |
| 3997 |
const char *str; |
| 3998 |
|
| 3999 |
str = safefile(agget(np, "shapefile")); |
| 4000 |
/* If shapefile is defined and not epsf, set shape = custom */ |
| 4001 |
if (str && !streq(name, "epsf")) |
| 4002 |
name = "custom"; |
| 4003 |
if (!streq(name, "custom")) { |
| 4004 |
for (ptr = Shapes; ptr->name; ptr++) { |
| 4005 |
if (streq(ptr->name, name)) { |
| 4006 |
rv = ptr; |
| 4007 |
break; |
| 4008 |
} |
| 4009 |
} |
| 4010 |
} |
| 4011 |
if (rv == NULL) |
| 4012 |
rv = user_shape(name); |
| 4013 |
return rv; |
| 4014 |
} |
| 4015 |
|
| 4016 |
static bool epsf_inside(inside_t * inside_context, pointf p) |
| 4017 |
{ |
| 4018 |
pointf P; |
| 4019 |
double x2; |
| 4020 |
node_t *n = inside_context->s.n; |
| 4021 |
|
| 4022 |
P = ccwrotatepf(p, 90 * GD_rankdir(agraphof(n))); |
| 4023 |
x2 = ND_ht(n) / 2; |
| 4024 |
return P.y >= -x2 && P.y <= x2 && P.x >= -ND_lw(n) && P.x <= ND_rw(n); |
| 4025 |
} |
| 4026 |
|
| 4027 |
static void epsf_gencode(GVJ_t * job, node_t * n) |
| 4028 |
{ |
| 4029 |
obj_state_t *obj = job->obj; |
| 4030 |
epsf_t *desc; |
| 4031 |
int doMap = obj->url || obj->explicit_tooltip; |
| 4032 |
|
| 4033 |
desc = ND_shape_info(n); |
| 4034 |
if (!desc) |
| 4035 |
return; |
| 4036 |
|
| 4037 |
if (doMap && !(job->flags & EMIT_CLUSTERS_LAST)) |
| 4038 |
gvrender_begin_anchor(job, |
| 4039 |
obj->url, obj->tooltip, obj->target, |
| 4040 |
obj->id); |
| 4041 |
if (desc) |
| 4042 |
fprintf(job->output_file, |
| 4043 |
"%.5g %.5g translate newpath user_shape_%d\n", |
| 4044 |
ND_coord(n).x + desc->offset.x, |
| 4045 |
ND_coord(n).y + desc->offset.y, desc->macro_id); |
| 4046 |
ND_label(n)->pos = ND_coord(n); |
| 4047 |
|
| 4048 |
emit_label(job, EMIT_NLABEL, ND_label(n)); |
| 4049 |
if (doMap) { |
| 4050 |
if (job->flags & EMIT_CLUSTERS_LAST) |
| 4051 |
gvrender_begin_anchor(job, |
| 4052 |
obj->url, obj->tooltip, obj->target, |
| 4053 |
obj->id); |
| 4054 |
gvrender_end_anchor(job); |
| 4055 |
} |
| 4056 |
} |
| 4057 |
|
| 4058 |
#define alpha (M_PI/10.0) |
| 4059 |
#define alpha2 (2*alpha) |
| 4060 |
#define alpha3 (3*alpha) |
| 4061 |
#define alpha4 (2*alpha2) |
| 4062 |
|
| 4063 |
static pointf star_size (pointf sz0) |
| 4064 |
{ |
| 4065 |
pointf sz; |
| 4066 |
double r, rx, ry; |
| 4067 |
|
| 4068 |
rx = sz0.x/(2*cos(alpha)); |
| 4069 |
ry = sz0.y/(sin(alpha) + sin(alpha3)); |
| 4070 |
const double r0 = fmax(rx, ry); |
| 4071 |
r = r0 * sin(alpha4) * cos(alpha2) / (cos(alpha) * cos(alpha4)); |
| 4072 |
|
| 4073 |
sz.x = 2*r*cos(alpha); |
| 4074 |
sz.y = r*(1 + sin(alpha3)); |
| 4075 |
return sz; |
| 4076 |
} |
| 4077 |
|
| 4078 |
static void star_vertices (pointf* vertices, pointf* bb) |
| 4079 |
{ |
| 4080 |
int i; |
| 4081 |
pointf sz = *bb; |
| 4082 |
double offset, a, aspect = (1 + sin(alpha3))/(2*cos(alpha)); |
| 4083 |
double r, r0, theta = alpha; |
| 4084 |
|
| 4085 |
/* Scale up width or height to required aspect ratio */ |
| 4086 |
a = sz.y/sz.x; |
| 4087 |
if (a > aspect) { |
| 4088 |
sz.x = sz.y/aspect; |
| 4089 |
} |
| 4090 |
else if (a < aspect) { |
| 4091 |
sz.y = sz.x*aspect; |
| 4092 |
} |
| 4093 |
|
| 4094 |
/* for given sz, get radius */ |
| 4095 |
r = sz.x/(2*cos(alpha)); |
| 4096 |
r0 = r * cos(alpha) * cos(alpha4) / (sin(alpha4) * cos(alpha2)); |
| 4097 |
|
| 4098 |
/* offset is the y shift of circle center from bb center */ |
| 4099 |
offset = (r*(1 - sin(alpha3)))/2; |
| 4100 |
|
| 4101 |
for (i = 0; i < 10; i += 2) { |
| 4102 |
vertices[i].x = r*cos(theta); |
| 4103 |
vertices[i].y = r*sin(theta) - offset; |
| 4104 |
theta += alpha2; |
| 4105 |
vertices[i+1].x = r0*cos(theta); |
| 4106 |
vertices[i+1].y = r0*sin(theta) - offset; |
| 4107 |
theta += alpha2; |
| 4108 |
} |
| 4109 |
|
| 4110 |
*bb = sz; |
| 4111 |
} |
| 4112 |
|
| 4113 |
static bool star_inside(inside_t * inside_context, pointf p) |
| 4114 |
{ |
| 4115 |
size_t sides; |
| 4116 |
pointf *vertex; |
| 4117 |
const pointf O = {0}; |
| 4118 |
|
| 4119 |
if (!inside_context) { |
| 4120 |
return false; |
| 4121 |
} |
| 4122 |
boxf *bp = inside_context->s.bp; |
| 4123 |
node_t *n = inside_context->s.n; |
| 4124 |
pointf P, Q, R; |
| 4125 |
int outcnt; |
| 4126 |
|
| 4127 |
P = ccwrotatepf(p, 90 * GD_rankdir(agraphof(n))); |
| 4128 |
|
| 4129 |
/* Quick test if port rectangle is target */ |
| 4130 |
if (bp) { |
| 4131 |
boxf bbox = *bp; |
| 4132 |
return INSIDE(P, bbox); |
| 4133 |
} |
| 4134 |
|
| 4135 |
if (n != inside_context->s.lastn) { |
| 4136 |
inside_context->s.last_poly = ND_shape_info(n); |
| 4137 |
vertex = inside_context->s.last_poly->vertices; |
| 4138 |
sides = inside_context->s.last_poly->sides; |
| 4139 |
|
| 4140 |
const double penwidth = late_double(n, N_penwidth, DEFAULT_NODEPENWIDTH, |
| 4141 |
MIN_NODEPENWIDTH); |
| 4142 |
if (inside_context->s.last_poly->peripheries >= 1 && penwidth > 0) { |
| 4143 |
/* index to outline, i.e., the outer-periphery with penwidth taken into account */ |
| 4144 |
inside_context->s.outp = (inside_context->s.last_poly->peripheries + 1 - 1) |
| 4145 |
* sides; |
| 4146 |
} else if (inside_context->s.last_poly->peripheries < 1) { |
| 4147 |
inside_context->s.outp = 0; |
| 4148 |
} else { |
| 4149 |
/* index to outer-periphery */ |
| 4150 |
inside_context->s.outp = (inside_context->s.last_poly->peripheries - 1) |
| 4151 |
* sides; |
| 4152 |
} |
| 4153 |
inside_context->s.lastn = n; |
| 4154 |
} else { |
| 4155 |
vertex = inside_context->s.last_poly->vertices; |
| 4156 |
sides = inside_context->s.last_poly->sides; |
| 4157 |
} |
| 4158 |
|
| 4159 |
outcnt = 0; |
| 4160 |
for (size_t i = 0; i < sides; i += 2) { |
| 4161 |
Q = vertex[i + inside_context->s.outp]; |
| 4162 |
R = vertex[(i + 4) % sides + inside_context->s.outp]; |
| 4163 |
if (!(same_side(P, O, Q, R))) { |
| 4164 |
outcnt++; |
| 4165 |
} |
| 4166 |
if (outcnt == 2) { |
| 4167 |
return false; |
| 4168 |
} |
| 4169 |
} |
| 4170 |
return true; |
| 4171 |
} |
| 4172 |
|
| 4173 |
/* cylinder: |
| 4174 |
* Code based on PostScript version by Brandon Rhodes. |
| 4175 |
* http://rhodesmill.org/brandon/2007/a-database-symbol-for-graphviz/ |
| 4176 |
*/ |
| 4177 |
static pointf cylinder_size (pointf sz) |
| 4178 |
{ |
| 4179 |
sz.y *= 1.375; |
| 4180 |
return sz; |
| 4181 |
} |
| 4182 |
|
| 4183 |
static void cylinder_vertices (pointf* vertices, pointf* bb) |
| 4184 |
{ |
| 4185 |
double x = bb->x/2; |
| 4186 |
double y = bb->y/2; |
| 4187 |
double yr = bb->y/11; |
| 4188 |
|
| 4189 |
vertices[0].x = x; |
| 4190 |
vertices[0].y = y-yr; |
| 4191 |
vertices[1].x = x; |
| 4192 |
vertices[1].y = y-(1-0.551784)*yr; |
| 4193 |
vertices[2].x = 0.551784*x; |
| 4194 |
vertices[2].y = y; |
| 4195 |
vertices[3].x = 0; |
| 4196 |
vertices[3].y = y; |
| 4197 |
vertices[4].x = -0.551784*x; |
| 4198 |
vertices[4].y = y; |
| 4199 |
vertices[5].x = -x; |
| 4200 |
vertices[5].y = vertices[1].y; |
| 4201 |
vertices[6].x = -x; |
| 4202 |
vertices[6].y = y-yr; |
| 4203 |
vertices[7] = vertices[6]; |
| 4204 |
vertices[8].x = -x; |
| 4205 |
vertices[8].y = yr-y; |
| 4206 |
vertices[9] = vertices[8]; |
| 4207 |
vertices[10].x = -x; |
| 4208 |
vertices[10].y = -vertices[1].y; |
| 4209 |
vertices[11].x = vertices[4].x; |
| 4210 |
vertices[11].y = -vertices[4].y; |
| 4211 |
vertices[12].x = vertices[3].x; |
| 4212 |
vertices[12].y = -vertices[3].y; |
| 4213 |
vertices[13].x = vertices[2].x; |
| 4214 |
vertices[13].y = -vertices[2].y; |
| 4215 |
vertices[14].x = vertices[1].x; |
| 4216 |
vertices[14].y = -vertices[1].y; |
| 4217 |
vertices[15].x = vertices[0].x; |
| 4218 |
vertices[15].y = -vertices[0].y; |
| 4219 |
vertices[16] = vertices[15]; |
| 4220 |
vertices[18] = vertices[17] = vertices[0]; |
| 4221 |
} |
| 4222 |
|
| 4223 |
static void cylinder_draw(GVJ_t *job, pointf *AF, size_t sides, int filled) { |
| 4224 |
pointf vertices[7]; |
| 4225 |
double y0 = AF[0].y; |
| 4226 |
double y02 = y0+y0; |
| 4227 |
|
| 4228 |
vertices[0] = AF[0]; |
| 4229 |
vertices[1].x = AF[1].x; |
| 4230 |
vertices[1].y = y02 - AF[1].y; |
| 4231 |
vertices[2].x = AF[2].x; |
| 4232 |
vertices[2].y = y02 - AF[2].y; |
| 4233 |
vertices[3].x = AF[3].x; |
| 4234 |
vertices[3].y = y02 - AF[3].y; |
| 4235 |
vertices[4].x = AF[4].x; |
| 4236 |
vertices[4].y = y02 - AF[4].y; |
| 4237 |
vertices[5].x = AF[5].x; |
| 4238 |
vertices[5].y = y02 - AF[5].y; |
| 4239 |
vertices[6] = AF[6]; |
| 4240 |
|
| 4241 |
gvrender_beziercurve(job, AF, sides, filled); |
| 4242 |
gvrender_beziercurve(job, vertices, 7, 0); |
| 4243 |
} |
| 4244 |
|
| 4245 |
static const char *side_port[] = {"s", "e", "n", "w"}; |
| 4246 |
|
| 4247 |
static pointf cvtPt(pointf p, int rankdir) { |
| 4248 |
pointf q = { 0, 0 }; |
| 4249 |
|
| 4250 |
switch (rankdir) { |
| 4251 |
case RANKDIR_TB: |
| 4252 |
q = p; |
| 4253 |
break; |
| 4254 |
case RANKDIR_BT: |
| 4255 |
q.x = p.x; |
| 4256 |
q.y = -p.y; |
| 4257 |
break; |
| 4258 |
case RANKDIR_LR: |
| 4259 |
q.y = p.x; |
| 4260 |
q.x = -p.y; |
| 4261 |
break; |
| 4262 |
case RANKDIR_RL: |
| 4263 |
q.y = p.x; |
| 4264 |
q.x = p.y; |
| 4265 |
break; |
| 4266 |
default: |
| 4267 |
UNREACHABLE(); |
| 4268 |
} |
| 4269 |
return q; |
| 4270 |
} |
| 4271 |
|
| 4272 |
/* closestSide: |
| 4273 |
* Resolve unspecified compass-point port to best available port. |
| 4274 |
* At present, this finds the available side closest to the center |
| 4275 |
* of the other port. |
| 4276 |
* |
| 4277 |
* This could be improved: |
| 4278 |
* - if other is unspecified, do them together |
| 4279 |
* - if dot, bias towards bottom of one to top of another, if possible |
| 4280 |
* - if line segment from port centers uses available sides, use these |
| 4281 |
* or center. (This latter may require spline routing to cooperate.) |
| 4282 |
*/ |
| 4283 |
static const char *closestSide(node_t *n, node_t *other, port *oldport) { |
| 4284 |
boxf b; |
| 4285 |
int rkd = GD_rankdir(agraphof(n)->root); |
| 4286 |
pointf p = {0}; |
| 4287 |
const pointf pt = cvtPt(ND_coord(n), rkd); |
| 4288 |
const pointf opt = cvtPt(ND_coord(other), rkd); |
| 4289 |
int sides = oldport->side; |
| 4290 |
const char *rv = NULL; |
| 4291 |
|
| 4292 |
if (sides == 0 || sides == (TOP | BOTTOM | LEFT | RIGHT)) |
| 4293 |
return rv; /* use center */ |
| 4294 |
|
| 4295 |
if (oldport->bp) { |
| 4296 |
b = *oldport->bp; |
| 4297 |
} else { |
| 4298 |
if (GD_flip(agraphof(n))) { |
| 4299 |
b.UR.x = ND_ht(n) / 2; |
| 4300 |
b.LL.x = -b.UR.x; |
| 4301 |
b.UR.y = ND_lw(n); |
| 4302 |
b.LL.y = -b.UR.y; |
| 4303 |
} else { |
| 4304 |
b.UR.y = ND_ht(n) / 2; |
| 4305 |
b.LL.y = -b.UR.y; |
| 4306 |
b.UR.x = ND_lw(n); |
| 4307 |
b.LL.x = -b.UR.x; |
| 4308 |
} |
| 4309 |
} |
| 4310 |
|
| 4311 |
double mind = 0; |
| 4312 |
for (int i = 0; i < 4; i++) { |
| 4313 |
if ((sides & (1 << i)) == 0) |
| 4314 |
continue; |
| 4315 |
switch (i) { |
| 4316 |
case BOTTOM_IX: |
| 4317 |
p.y = b.LL.y; |
| 4318 |
p.x = (b.LL.x + b.UR.x) / 2; |
| 4319 |
break; |
| 4320 |
case RIGHT_IX: |
| 4321 |
p.x = b.UR.x; |
| 4322 |
p.y = (b.LL.y + b.UR.y) / 2; |
| 4323 |
break; |
| 4324 |
case TOP_IX: |
| 4325 |
p.y = b.UR.y; |
| 4326 |
p.x = (b.LL.x + b.UR.x) / 2; |
| 4327 |
break; |
| 4328 |
case LEFT_IX: |
| 4329 |
p.x = b.LL.x; |
| 4330 |
p.y = (b.LL.y + b.UR.y) / 2; |
| 4331 |
break; |
| 4332 |
default: |
| 4333 |
UNREACHABLE(); |
| 4334 |
} |
| 4335 |
p.x += pt.x; |
| 4336 |
p.y += pt.y; |
| 4337 |
const double d = DIST2(p, opt); |
| 4338 |
if (!rv || d < mind) { |
| 4339 |
mind = d; |
| 4340 |
rv = side_port[i]; |
| 4341 |
} |
| 4342 |
} |
| 4343 |
return rv; |
| 4344 |
} |
| 4345 |
|
| 4346 |
port resolvePort(node_t * n, node_t * other, port * oldport) |
| 4347 |
{ |
| 4348 |
port rv; |
| 4349 |
const char *compass = closestSide(n, other, oldport); |
| 4350 |
|
| 4351 |
/* transfer name pointer; all other necessary fields will be regenerated */ |
| 4352 |
rv.name = oldport->name; |
| 4353 |
compassPort(n, oldport->bp, &rv, compass, oldport->side, NULL); |
| 4354 |
|
| 4355 |
return rv; |
| 4356 |
} |
| 4357 |
|
| 4358 |
void resolvePorts(edge_t * e) |
| 4359 |
{ |
| 4360 |
if (ED_tail_port(e).dyna) |
| 4361 |
ED_tail_port(e) = |
| 4362 |
resolvePort(agtail(e), aghead(e), &ED_tail_port(e)); |
| 4363 |
if (ED_head_port(e).dyna) |
| 4364 |
ED_head_port(e) = |
| 4365 |
resolvePort(aghead(e), agtail(e), &ED_head_port(e)); |
| 4366 |
} |