Graphviz 14.1.2~dev.20260118.1035
Loading...
Searching...
No Matches
geometry.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 <neatogen/geometry.h>
14#include <math.h>
15#include <stddef.h>
16
17double xmin, xmax, ymin, ymax; /* min and max x and y values of sites */
18double deltax; // xmax - xmin
19
20size_t nsites;
22
23void geominit(void)
24{
25 double sn;
26
27 sn = nsites + 4;
28 sqrt_nsites = (int) sqrt(sn);
29}
30
31double dist_2(Point pp, Point qp) {
32 const double dx = pp.x - qp.x;
33 const double dy = pp.y - qp.y;
34
35 return (dx * dx + dy * dy);
36}
37
38void subpt(Point * a, Point b, Point c)
39{
40 a->x = b.x - c.x;
41 a->y = b.y - c.y;
42}
43
44void addpt(Point * c, Point a, Point b)
45{
46 c->x = a.x + b.x;
47 c->y = a.y + b.y;
48}
49
50double area_2(Point a, Point b, Point c)
51{
52 return ((a.y - b.y) * (c.x - b.x) - (c.y - b.y) * (a.x - b.x));
53}
54
55int leftOf(Point a, Point b, Point c)
56{
57 return (area_2(a, b, c) > 0);
58}
59
61{
62 double s, t; /* The two parameters of the parametric eqns. */
63 double denom; /* Denominator of solutions. */
64
65 denom =
66 a.x * (d.y - c.y) +
67 b.x * (c.y - d.y) + d.x * (b.y - a.y) + c.x * (a.y - b.y);
68
69 /* If denom is zero, then the line segments are parallel. */
70 /* In this case, return false even though the segments might overlap. */
71 if (denom == 0.0)
72 return 0;
73
74 s = (a.x * (d.y - c.y) + c.x * (a.y - d.y) + d.x * (c.y - a.y)
75 ) / denom;
76 t = -(a.x * (c.y - b.y) + b.x * (a.y - c.y) + c.x * (b.y - a.y)
77 ) / denom;
78
79 p->x = a.x + s * (b.x - a.x);
80 p->y = a.y + s * (b.y - a.y);
81
82 if ((0.0 <= s) && (s <= 1.0) && (0.0 <= t) && (t <= 1.0))
83 return 1;
84 else
85 return 0;
86}
static float dy
Definition draw.c:43
static float dx
Definition draw.c:42
int leftOf(Point a, Point b, Point c)
Definition geometry.c:55
size_t nsites
Definition geometry.c:20
double deltax
Definition geometry.c:18
double xmax
Definition geometry.c:17
void geominit(void)
Definition geometry.c:23
double ymin
Definition geometry.c:17
void addpt(Point *c, Point a, Point b)
Definition geometry.c:44
void subpt(Point *a, Point b, Point c)
Definition geometry.c:38
double xmin
Definition geometry.c:17
int sqrt_nsites
Definition geometry.c:21
double dist_2(Point pp, Point qp)
distance squared between two points
Definition geometry.c:31
double ymax
Definition geometry.c:17
double area_2(Point a, Point b, Point c)
Definition geometry.c:50
double x
Definition geometry.h:24
double y
Definition geometry.h:24
Definition grammar.c:90