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 /** \file connectionpoint.c ConnectionPoint implmentation */
22 #include "connectionpoint.h"
24 /** Returns the available directions on a slope.
25 * The right-hand side of the line is assumed to be within the object,
26 * and thus not available.
27 * @param from Beginning of the slope line.
28 * @param to End of the slope line.
29 * @returns The directions open (@see connectionpoint.h) open on the left-hand
33 find_slope_directions(Point from
, Point to
)
38 if (fabs(from
.y
-to
.y
) < 0.0000001)
39 return (from
.x
> to
.x
?DIR_SOUTH
:DIR_NORTH
);
40 if (fabs(from
.x
-to
.x
) < 0.0000001)
41 return (from
.y
> to
.y
?DIR_WEST
:DIR_EAST
);
43 point_sub(&to
, &from
);
44 slope
= fabs(to
.y
/to
.x
);
47 if (slope
< 2) { /* Flat enough to allow north-south */
48 if (to
.x
> 0) { /* The outside is north, not south */
54 if (slope
> .5) { /* Steep enough to allow east-west */
55 if (to
.y
> 0) { /* The outside is east, not west */
65 /** Update the object-settable parts of a connectionpoints.
66 * @param p A ConnectionPoint pointer (non-NULL).
67 * @param x The x coordinate of the connectionpoint.
68 * @param y The y coordinate of the connectionpoint.
69 * @param dirs The directions that are open for connections on this point.
72 connpoint_update(ConnectionPoint
*p
, real x
, real y
, gint dirs
)
79 /** Returns TRUE if the given connection point is non-null and autogapped.
80 * @param cp A connectionpoint.
81 * @returns TRUE if the given connection point is non-null and has the
82 * CP_FLAG_AUTOGAP flag set (i.e. lines connecting to it should try to end
83 * at the border of the object instead of at the connection point.
86 connpoint_is_autogap(ConnectionPoint
*cp
)
88 return cp
!= NULL
&& (cp
->flags
& CP_FLAG_AUTOGAP
);