Graphviz 14.1.2~dev.20251230.0621
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 "Plegal_arrangement.h"
12#include "simple.h"
13#include <pathplan/pathgeom.h>
14#include <stdbool.h>
15#include <stdio.h>
16#include <stdlib.h>
17#include <util/alloc.h>
18#include <util/gv_math.h>
19#include <util/list.h>
20#include <util/prisize_t.h>
21
22static bool eq_pt(const struct position v, const struct intersection w) {
23 return is_exactly_equal(v.x, w.x) && is_exactly_equal(v.y, w.y);
24}
25
26int Plegal_arrangement(Ppoly_t **polys, size_t n_polys) {
27
28 intersections_t ilist = {0};
29
30 struct polygon *polygon_list = gv_calloc(n_polys, sizeof(struct polygon));
31
32 size_t nverts = 0;
33 for (size_t i = 0; i < n_polys; i++)
34 nverts += polys[i]->pn;
35
36 struct vertex *vertex_list = gv_calloc(nverts, sizeof(struct vertex));
37
38 for (size_t i = 0, vno = 0; i < n_polys; i++) {
39 polygon_list[i].start = &vertex_list[vno];
40 for (size_t j = 0; j < polys[i]->pn; j++) {
41 vertex_list[vno].pos.x = polys[i]->ps[j].x;
42 vertex_list[vno].pos.y = polys[i]->ps[j].y;
43 vertex_list[vno].poly = &polygon_list[i];
44 vno++;
45 }
46 polygon_list[i].finish = &vertex_list[vno - 1];
47 }
48
49 find_ints(vertex_list, nverts, &ilist);
50
51 int rv = 1;
52 for (size_t i = 0; i < LIST_SIZE(&ilist); i++) {
53 struct intersection inter = LIST_GET(&ilist, i);
54 const struct position vft = inter.firstv->pos;
55 const struct position avft = after(inter.firstv)->pos;
56 const struct position vsd = inter.secondv->pos;
57 const struct position avsd = after(inter.secondv)->pos;
58 if ((!is_exactly_equal(vft.x, avft.x) &&
59 !is_exactly_equal(vsd.x, avsd.x)) ||
60 (is_exactly_equal(vft.x, avft.x) && !eq_pt(vft, inter) &&
61 !eq_pt(avft, inter)) ||
62 (is_exactly_equal(vsd.x, avsd.x) && !eq_pt(vsd, inter) &&
63 !eq_pt(avsd, inter))) {
64 rv = 0;
65 fprintf(stderr, "\nintersection %" PRISIZE_T " at %.3f %.3f\n", i,
66 inter.x, inter.y);
67 fprintf(stderr, "seg#1 : (%.3f, %.3f) (%.3f, %.3f)\n",
68 inter.firstv->pos.x, inter.firstv->pos.y,
69 after(inter.firstv)->pos.x, after(inter.firstv)->pos.y);
70 fprintf(stderr, "seg#2 : (%.3f, %.3f) (%.3f, %.3f)\n",
71 inter.secondv->pos.x, inter.secondv->pos.y,
72 after(inter.secondv)->pos.x, after(inter.secondv)->pos.y);
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 *)
Arithmetic helper functions.
static bool is_exactly_equal(double a, double b)
are two values precisely the same?
Definition gv_math.h:48
static int find_ints(vertex vertex_list[], size_t nvertices)
Definition legal.c:260
#define after(v)
Definition legal.c:27
type-generic dynamically expanding list
#define LIST_SIZE(list)
Definition list.h:80
#define LIST_FREE(list)
Definition list.h:370
#define LIST_GET(list, index)
Definition list.h:155
#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
double y
Definition simple.h:21
Definition legal.c:32
pointf pos
Definition legal.c:33
polygon * poly
Definition legal.c:34
static bool eq_pt(const struct position v, const struct intersection w)
Definition wrapper.c:22
int Plegal_arrangement(Ppoly_t **polys, size_t n_polys)
Definition wrapper.c:26