• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Keine Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

作図ソフト dia の改良版


Commit MetaInfo

Revisionfc773583c62a5fda06cd4e501a46410907d1458a (tree)
Zeit2012-10-04 04:57:18
AutorHans Breuer <hans@breu...>
CommiterHans Breuer

Log Message

[substitute] improve auto-routing to avoid intersects

The auto-routing algorithm now prefers intersection-free
routes between the connected objects.

Ändern Zusammenfassung

Diff

--- a/lib/autoroute.c
+++ b/lib/autoroute.c
@@ -60,6 +60,23 @@ static Point *autolayout_unnormalize_points(guint dir,
6060 Point *points,
6161 guint num_points);
6262
63+static int
64+autolayout_calc_intersects (const Rectangle *r1, const Rectangle *r2,
65+ const Point *points, guint num_points)
66+{
67+ guint i, n = 0;
68+
69+ /* ignoring the first and last line assuming a proper 'outer' algorithm */
70+ for (i = 1; i < num_points - 2; ++i) {
71+ Rectangle rt = { points[i].x, points[i].y, points[i+1].x, points[i+1].y };
72+ if (r1)
73+ n += (rectangle_intersects (r1, &rt) ? 1 : 0);
74+ if (r2)
75+ n += (rectangle_intersects (r2, &rt) ? 1 : 0);
76+ }
77+
78+ return n;
79+}
6380 /*!
6481 * \brief Apply a good route (or none) to the given _OrthConn
6582 *
@@ -84,6 +101,8 @@ autoroute_layout_orthconn(OrthConn *conn,
84101 ConnectionPoint *startconn, ConnectionPoint *endconn)
85102 {
86103 real min_badness = MAX_BADNESS;
104+ guint best_intersects = G_MAXINT;
105+ guint intersects;
87106 Point *best_layout = NULL;
88107 guint best_num_points = 0;
89108 int startdir, enddir;
@@ -144,24 +163,33 @@ autoroute_layout_orthconn(OrthConn *conn,
144163 &this_layout);
145164 }
146165 if (this_layout != NULL) {
147- if (this_badness-min_badness < -0.00001) {
166+ /* this_layout is eaten by unnormalize */
167+ Point *unnormalized = autolayout_unnormalize_points(startdir, startpoint,
168+ this_layout, this_num_points);
169+
170+ intersects = autolayout_calc_intersects (
171+ startconn ? dia_object_get_bounding_box (startconn->object) : NULL,
172+ endconn ? dia_object_get_bounding_box (endconn->object) : NULL,
173+ unnormalized, this_num_points);
174+
175+ if ( intersects <= best_intersects
176+ && this_badness-min_badness < -0.00001) {
148177 /*
149178 printf("Dir %d to %d badness %f < %f\n", startdir, enddir,
150179 this_badness, min_badness);
151180 */
152181 min_badness = this_badness;
153182 if (best_layout != NULL) g_free(best_layout);
154- best_layout = autolayout_unnormalize_points(startdir, startpoint,
155- this_layout,
156- this_num_points);
183+ best_layout = unnormalized;
157184 best_num_points = this_num_points;
158185 /* revert adjusting start and end point */
159186 autolayout_adjust_for_arrow(&best_layout[0], startdir,
160187 -conn->extra_spacing.start_trans);
161188 autolayout_adjust_for_arrow(&best_layout[best_num_points-1], enddir,
162189 -conn->extra_spacing.end_trans);
190+ best_intersects = intersects;
163191 } else {
164- g_free(this_layout);
192+ g_free(unnormalized);
165193 }
166194 }
167195 }
Binary files /dev/null and b/samples/substitute-test.dia differ