Graphviz 14.1.2~dev.20260118.1035
Loading...
Searching...
No Matches
smyrna_utils.c
Go to the documentation of this file.
1/*************************************************************************
2 * Copyright (c) 2011 AT&T Intellectual Property
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * https://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors: Details at https://graphviz.org
9 *************************************************************************/
10
11#include "config.h"
12
13#include "smyrna_utils.h"
14#include <assert.h>
15#include <common/types.h>
16#include <common/utils.h>
17#include <limits.h>
18#include <stddef.h>
19#include <stdio.h>
20
21int l_int(void *obj, Agsym_t * attr, int def)
22{
23 return late_int(obj, attr, def, INT_MIN);
24}
25
26float l_float(void *obj, Agsym_t * attr, float def)
27{
28 char *p;
29 if (!attr || !obj)
30 return def;
31 p = agxget(obj, attr);
32 if (!p || p[0] == '\0')
33 return def;
34 return atof(p);
35}
36int getAttrBool(Agraph_t* g,void* obj,char* attr_name,int def)
37{
38 Agsym_t *const attr = agattr_text(g, AGTYPE(obj), attr_name, 0);
39 return late_bool(obj, attr,def);
40}
41int getAttrInt(Agraph_t* g,void* obj,char* attr_name,int def)
42{
43 Agsym_t *const attr = agattr_text(g, AGTYPE(obj), attr_name, 0);
44 return l_int(obj,attr,def);
45}
46float getAttrFloat(Agraph_t* g,void* obj,char* attr_name,float def)
47{
48 Agsym_t *const attr = agattr_text(g, AGTYPE(obj), attr_name, 0);
49 return l_float(obj,attr,def);
50}
51char* getAttrStr(Agraph_t* g,void* obj,char* attr_name,char* def)
52{
53 Agsym_t *const attr = agattr_text(g, AGTYPE(obj), attr_name, 0);
54 return late_string(obj, attr,def);
55}
56
58 glCompPoint p = {0};
59 (void)sscanf(str, "%f,%f,%f", &p.x, &p.y, &p.z);
60 return p;
61}
62
63int point_in_polygon(glCompPoly_t *selPoly, glCompPoint p) {
64 const size_t npol = LIST_SIZE(selPoly);
65 assert(npol > 0);
66
67 int c = 0;
68 for (size_t i = 0, j = npol - 1; i < npol; j = i++) {
69 const glCompPoint pt_i = LIST_GET(selPoly, i);
70 const glCompPoint pt_j = LIST_GET(selPoly, j);
71 if (((pt_i.y <= p.y && p.y < pt_j.y) ||
72 (pt_j.y <= p.y && p.y < pt_i.y)) &&
73 p.x < (pt_j.x - pt_i.x) * (p.y - pt_i.y) / (pt_j.y - pt_i.y) + pt_i.x)
74 c = !c;
75 }
76 return c;
77 }
char * late_string(void *obj, attrsym_t *attr, char *defaultValue)
Definition utils.c:84
int late_int(void *obj, attrsym_t *attr, int defaultValue, int minimum)
Definition utils.c:39
bool late_bool(void *obj, attrsym_t *attr, bool defaultValue)
Definition utils.c:97
Agsym_t * agattr_text(Agraph_t *g, int kind, char *name, const char *value)
creates or looks up text attributes of a graph
Definition attr.c:336
char * agxget(void *obj, Agsym_t *sym)
Definition attr.c:460
#define AGTYPE(obj)
returns AGRAPH, AGNODE, or AGEDGE depending on the type of the object
Definition cgraph.h:216
textitem scanner parser str
Definition htmlparse.y:218
#define LIST_SIZE(list)
Definition list.h:80
#define LIST_GET(list, index)
Definition list.h:155
float getAttrFloat(Agraph_t *g, void *obj, char *attr_name, float def)
int getAttrInt(Agraph_t *g, void *obj, char *attr_name, int def)
int getAttrBool(Agraph_t *g, void *obj, char *attr_name, int def)
glCompPoint getPointFromStr(const char *str)
char * getAttrStr(Agraph_t *g, void *obj, char *attr_name, char *def)
int l_int(void *obj, Agsym_t *attr, int def)
int point_in_polygon(glCompPoly_t *selPoly, glCompPoint p)
float l_float(void *obj, Agsym_t *attr, float def)
graph or subgraph
Definition cgraph.h:424
string attribute descriptor symbol in Agattr_s.dict
Definition cgraph.h:640
graphs, nodes and edges info: Agraphinfo_t, Agnodeinfo_t and Agedgeinfo_t