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