Graphviz 13.0.0~dev.20241220.2304
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* attr;
36 attr = agattr(g, AGTYPE(obj), attr_name,0);
37 return late_bool(obj, attr,def);
38}
39int getAttrInt(Agraph_t* g,void* obj,char* attr_name,int def)
40{
41 Agsym_t* attr;
42 attr = agattr(g, AGTYPE(obj), attr_name,0);
43 return l_int(obj,attr,def);
44}
45float getAttrFloat(Agraph_t* g,void* obj,char* attr_name,float def)
46{
47 Agsym_t* attr;
48 attr = agattr(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* attr;
54 attr = agattr(g, AGTYPE(obj), attr_name,0);
55 return late_string(obj, attr,def);
56}
57
59 glCompPoint p = {0};
60 (void)sscanf(str, "%f,%f,%f", &p.x, &p.y, &p.z);
61 return p;
62}
63
64int point_in_polygon(glCompPoly_t *selPoly, glCompPoint p) {
65 const size_t npol = glCompPoly_size(selPoly);
66 assert(npol > 0);
67
68 int c = 0;
69 for (size_t i = 0, j = npol - 1; i < npol; j = i++) {
70 const glCompPoint pt_i = glCompPoly_get(selPoly, i);
71 const glCompPoint pt_j = glCompPoly_get(selPoly, j);
72 if (((pt_i.y <= p.y && p.y < pt_j.y) ||
73 (pt_j.y <= p.y && p.y < pt_i.y)) &&
74 p.x < (pt_j.x - pt_i.x) * (p.y - pt_i.y) / (pt_j.y - pt_i.y) + pt_i.x)
75 c = !c;
76 }
77 return c;
78 }
char * late_string(void *obj, attrsym_t *attr, char *defaultValue)
Definition utils.c:78
int late_int(void *obj, attrsym_t *attr, int defaultValue, int minimum)
Definition utils.c:33
bool late_bool(void *obj, attrsym_t *attr, bool defaultValue)
Definition utils.c:91
Agsym_t * agattr(Agraph_t *g, int kind, char *name, const char *value)
creates or looks up attributes of a graph
Definition attr.c:338
char * agxget(void *obj, Agsym_t *sym)
Definition attr.c:455
#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:425
string attribute descriptor symbol in Agattr_s.dict
Definition cgraph.h:637
graphs, nodes and edges info: Agraphinfo_t, Agnodeinfo_t and Agedgeinfo_t