Graphviz 14.0.0~dev.20250918.1035
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#include <util/list.h>
18#include <util/prisize_t.h>
19
20int Plegal_arrangement(Ppoly_t **polys, size_t n_polys) {
21
22 int rv;
23 intersections_t ilist = {0};
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 find_ints(vertex_list, nverts, &ilist);
45
46#define EQ_PT(v,w) (((v).x == (w).x) && ((v).y == (w).y))
47 rv = 1;
48 {
49 struct position vft, vsd, avft, avsd;
50 for (size_t i = 0; i < LIST_SIZE(&ilist); i++) {
51 struct intersection inter = LIST_GET(&ilist, i);
52 vft = inter.firstv->pos;
53 avft = after(inter.firstv)->pos;
54 vsd = inter.secondv->pos;
55 avsd = after(inter.secondv)->pos;
56 if ((vft.x != avft.x && vsd.x != avsd.x) ||
57 (vft.x == avft.x && !EQ_PT(vft, inter) && !EQ_PT(avft, inter)) ||
58 (vsd.x == avsd.x && !EQ_PT(vsd, inter) && !EQ_PT(avsd, inter))) {
59 rv = 0;
60 fprintf(stderr, "\nintersection %" PRISIZE_T " at %.3f %.3f\n",
61 i, inter.x, inter.y);
62 fprintf(stderr, "seg#1 : (%.3f, %.3f) (%.3f, %.3f)\n",
63 inter.firstv->pos.x
64 , inter.firstv->pos.y
65 , after(inter.firstv)->pos.x
66 , after(inter.firstv)->pos.y);
67 fprintf(stderr, "seg#2 : (%.3f, %.3f) (%.3f, %.3f)\n",
68 inter.secondv->pos.x
69 , inter.secondv->pos.y
70 , after(inter.secondv)->pos.x
71 , after(inter.secondv)->pos.y);
72 }
73 }
74 }
75 free(polygon_list);
76 free(vertex_list);
77 LIST_FREE(&ilist);
78 return rv;
79}
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:275
#define after(v)
Definition legal.c:26
type-generic dynamically expanding list
#define LIST_SIZE(list)
Definition list.h:80
#define LIST_FREE(list)
Definition list.h:379
#define LIST_GET(list, index)
Definition list.h:165
#define PRISIZE_T
Definition prisize_t.h: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
struct vertex * firstv
Definition simple.h:36
double y
Definition simple.h:38
struct vertex * secondv
Definition simple.h:36
double x
Definition simple.h:38
double x
Definition geom.h:29
double y
Definition geom.h:29
vertex * finish
Definition legal.c:39
vertex * start
Definition legal.c:39
double x
Definition simple.h:21
Definition legal.c:32
pointf pos
Definition legal.c:33
polygon * poly
Definition legal.c:34
int Plegal_arrangement(Ppoly_t **polys, size_t n_polys)
Definition wrapper.c:20
#define EQ_PT(v, w)