2005-09-05 Inaki Larranaga <dooteo@euskalgnu.org>
[dia.git] / lib / connectionpoint.c
blob900d27fb8c2912adf8ae3a78eaec3f5ad99e0d33
1 /* Dia -- an diagram creation/manipulation program
2 * Copyright (C) 1998 Alexander Larsson
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 #include "config.h"
20 #include "connectionpoint.h"
22 /* Returns the available directions on a slope.
23 * The right-hand side of the line is assumed to be within the object,
24 * and thus not available. */
25 gint
26 find_slope_directions(Point from, Point to)
28 gint dirs;
29 gint slope;
31 if (fabs(from.y-to.y) < 0.0000001)
32 return (from.x > to.x?DIR_SOUTH:DIR_NORTH);
33 if (fabs(from.x-to.x) < 0.0000001)
34 return (from.y > to.y?DIR_WEST:DIR_EAST);
36 point_sub(&to, &from);
37 slope = fabs(to.y/to.x);
39 dirs = 0;
40 if (slope < 2) { /* Flat enough to allow north-south */
41 if (to.x > 0) { /* The outside is north, not south */
42 dirs |= DIR_NORTH;
43 } else {
44 dirs |= DIR_SOUTH;
47 if (slope > .5) { /* Steep enough to allow east-west */
48 if (to.y > 0) { /* The outside is east, not west */
49 dirs |= DIR_EAST;
50 } else {
51 dirs |= DIR_WEST;
54 return dirs;
58 /** Update the object-settable parts of a connectionpoints.
59 * p: A ConnectionPoint pointer (non-NULL).
60 * x: The x coordinate of the connectionpoint.
61 * y: The y coordinate of the connectionpoint.
62 * dirs: The directions that are open for connections on this point.
64 void
65 connpoint_update(ConnectionPoint *p, real x, real y, gint dirs)
67 p->pos.x = x;
68 p->pos.y = y;
69 p->directions = dirs;
72 /** Returns TRUE if the given connection point is non-null and autogapped.
74 gboolean
75 connpoint_is_autogap(ConnectionPoint *cp) {
76 return cp != NULL && (cp->flags & CP_FLAG_AUTOGAP);