Graphviz 13.0.0~dev.20250607.1528
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#include "smyrna_utils.h"
11#include <assert.h>
12#include <common/types.h>
13#include <common/utils.h>
14#include <limits.h>
15#include <stddef.h>
16#include <stdio.h>
17
18int l_int(void *obj, Agsym_t * attr, int def)
19{
20 return late_int(obj, attr, def, INT_MIN);
21}
22
23float l_float(void *obj, Agsym_t * attr, float def)
24{
25 char *p;
26 if (!attr || !obj)
27 return def;
28 p = agxget(obj, attr);
29 if (!p || p[0] == '\0')
30 return def;
31 return atof(p);
32}
33int getAttrBool(Agraph_t* g,void* obj,char* attr_name,int def)
34{
35 Agsym_t *const attr = agattr_text(g, AGTYPE(obj), attr_name, 0);
36 return late_bool(obj, attr,def);
37}
38int getAttrInt(Agraph_t* g,void* obj,char* attr_name,int def)
39{
40 Agsym_t *const attr = agattr_text(g, AGTYPE(obj), attr_name, 0);
41 return l_int(obj,attr,def);
42}
43float getAttrFloat(Agraph_t* g,void* obj,char* attr_name,float def)
44{
45 Agsym_t *const attr = agattr_text(g, AGTYPE(obj), attr_name, 0);
46 return l_float(obj,attr,def);
47}
48char* getAttrStr(Agraph_t* g,void* obj,char* attr_name,char* def)
49{
50 Agsym_t *const attr = agattr_text(g, AGTYPE(obj), attr_name, 0);
51 return late_string(obj, attr,def);
52}
53
55 glCompPoint p = {0};
56 (void)sscanf(str, "%f,%f,%f", &p.x, &p.y, &p.z);
57 return p;
58}
59
60int point_in_polygon(glCompPoly_t *selPoly, glCompPoint p) {
61 const size_t npol = glCompPoly_size(selPoly);
62 assert(npol > 0);
63
64 int c = 0;
65 for (size_t i = 0, j = npol - 1; i < npol; j = i++) {
66 const glCompPoint pt_i = glCompPoly_get(selPoly, i);
67 const glCompPoint pt_j = glCompPoly_get(selPoly, j);
68 if (((pt_i.y <= p.y && p.y < pt_j.y) ||
69 (pt_j.y <= p.y && p.y < pt_i.y)) &&
70 p.x < (pt_j.x - pt_i.x) * (p.y - pt_i.y) / (pt_j.y - pt_i.y) + pt_i.x)
71 c = !c;
72 }
73 return c;
74 }
char * late_string(void *obj, attrsym_t *attr, char *defaultValue)
Definition utils.c:80
int late_int(void *obj, attrsym_t *attr, int defaultValue, int minimum)
Definition utils.c:35
bool late_bool(void *obj, attrsym_t *attr, bool defaultValue)
Definition utils.c:93
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:348
char * agxget(void *obj, Agsym_t *sym)
Definition attr.c:472
#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:224
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:651
graphs, nodes and edges info: Agraphinfo_t, Agnodeinfo_t and Agedgeinfo_t