Graphviz 13.0.0~dev.20241220.2304
Loading...
Searching...
No Matches
wrapper.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 <pathplan/pathgeom.h>
12#include "Plegal_arrangement.h"
13#include <stdio.h>
14#include <stdlib.h>
15#include "simple.h"
16#include <util/alloc.h>
17
18int Plegal_arrangement(Ppoly_t **polys, size_t n_polys) {
19
20 int rv;
21
22 struct data input;
23 struct intersection ilist[10000];
24
25 struct polygon *polygon_list = gv_calloc(n_polys, sizeof(struct polygon));
26
27 size_t nverts = 0;
28 for (size_t i = 0; i < n_polys; i++)
29 nverts += polys[i]->pn;
30
31 struct vertex *vertex_list = gv_calloc(nverts, sizeof(struct vertex));
32
33 for (size_t i = 0, vno = 0; i < n_polys; i++) {
34 polygon_list[i].start = &vertex_list[vno];
35 for (size_t j = 0; j < polys[i]->pn; j++) {
36 vertex_list[vno].pos.x = polys[i]->ps[j].x;
37 vertex_list[vno].pos.y = polys[i]->ps[j].y;
38 vertex_list[vno].poly = &polygon_list[i];
39 vno++;
40 }
41 polygon_list[i].finish = &vertex_list[vno - 1];
42 }
43
44 input.nvertices = nverts;
45
46 find_ints(vertex_list, &input, ilist);
47
48
49#define EQ_PT(v,w) (((v).x == (w).x) && ((v).y == (w).y))
50 rv = 1;
51 {
52 struct position vft, vsd, avft, avsd;
53 for (int i = 0; i < input.ninters; i++) {
54 vft = ilist[i].firstv->pos;
55 avft = after(ilist[i].firstv)->pos;
56 vsd = ilist[i].secondv->pos;
57 avsd = after(ilist[i].secondv)->pos;
58 if ((vft.x != avft.x && vsd.x != avsd.x) ||
59 (vft.x == avft.x && !EQ_PT(vft, ilist[i]) && !EQ_PT(avft, ilist[i])) ||
60 (vsd.x == avsd.x && !EQ_PT(vsd, ilist[i]) && !EQ_PT(avsd, ilist[i]))) {
61 rv = 0;
62 fprintf(stderr, "\nintersection %d at %.3f %.3f\n",
63 i, ilist[i].x, ilist[i].y);
64 fprintf(stderr, "seg#1 : (%.3f, %.3f) (%.3f, %.3f)\n",
65 ilist[i].firstv->pos.x
66 , ilist[i].firstv->pos.y
67 , after(ilist[i].firstv)->pos.x
68 , after(ilist[i].firstv)->pos.y);
69 fprintf(stderr, "seg#2 : (%.3f, %.3f) (%.3f, %.3f)\n",
70 ilist[i].secondv->pos.x
71 , ilist[i].secondv->pos.y
72 , after(ilist[i].secondv)->pos.x
73 , after(ilist[i].secondv)->pos.y);
74 }
75 }
76 }
77 free(polygon_list);
78 free(vertex_list);
79 return rv;
80}
Memory allocation wrappers that exit on failure.
static void * gv_calloc(size_t nmemb, size_t size)
Definition alloc.h:26
void free(void *)
static int find_ints(vertex vertex_list[], size_t nvertices)
Definition legal.c:282
#define after(v)
Definition legal.c:25
size_t pn
Definition pathgeom.h:47
Ppoint_t * ps
Definition pathgeom.h:46
double x
Definition pathgeom.h:38
double y
Definition pathgeom.h:38
Definition legal.c:50
int ninters
Definition legal.c:51
int nvertices
Definition legal.c:51
float x
Definition simple.h:39
struct vertex * firstv
Definition simple.h:37
struct vertex * secondv
Definition simple.h:37
double x
Definition geom.h:29
double y
Definition geom.h:29
vertex * finish
Definition legal.c:38
vertex * start
Definition legal.c:38
float x
Definition simple.h:22
float y
Definition simple.h:22
Definition legal.c:31
pointf pos
Definition legal.c:32
polygon * poly
Definition legal.c:33
int Plegal_arrangement(Ppoly_t **polys, size_t n_polys)
Definition wrapper.c:18
#define EQ_PT(v, w)