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