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.
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 * @param from Beginning of the slope line.
26 * @param to End of the slope line.
27 * @returns The directions open (@see connectionpoint.h) open on the left-hand
31 find_slope_directions(Point from
, Point to
)
36 if (fabs(from
.y
-to
.y
) < 0.0000001)
37 return (from
.x
> to
.x
?DIR_SOUTH
:DIR_NORTH
);
38 if (fabs(from
.x
-to
.x
) < 0.0000001)
39 return (from
.y
> to
.y
?DIR_WEST
:DIR_EAST
);
41 point_sub(&to
, &from
);
42 slope
= fabs(to
.y
/to
.x
);
45 if (slope
< 2) { /* Flat enough to allow north-south */
46 if (to
.x
> 0) { /* The outside is north, not south */
52 if (slope
> .5) { /* Steep enough to allow east-west */
53 if (to
.y
> 0) { /* The outside is east, not west */
63 /** Update the object-settable parts of a connectionpoints.
64 * @param p A ConnectionPoint pointer (non-NULL).
65 * @param x The x coordinate of the connectionpoint.
66 * @param y The y coordinate of the connectionpoint.
67 * @param dirs The directions that are open for connections on this point.
70 connpoint_update(ConnectionPoint
*p
, real x
, real y
, gint dirs
)
77 /** Returns TRUE if the given connection point is non-null and autogapped.
78 * @param cp A connectionpoint.
79 * @returns TRUE if the given connection point is non-null and has the
80 * CP_FLAG_AUTOGAP flag set (i.e. lines connecting to it should try to end
81 * at the border of the object instead of at the connection point.
84 connpoint_is_autogap(ConnectionPoint
*cp
)
86 return cp
!= NULL
&& (cp
->flags
& CP_FLAG_AUTOGAP
);