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