【发布时间】:2009-08-23 02:45:36
【问题描述】:
下图说明了我在创建曼哈顿图时遇到的问题:
框包围了与现有行重叠的大部分行 [(tx,midy)-(sx,midy)](在下面的代码中由 psegment 表示)。我已经删除了重叠的箭头(和尾巴),并且对如何检查重叠有点困惑。
这是有问题的代码:
Line2D.Double segment = new Line2D.Double( sx, midy, tx, midy );
// Associate the middle-y point with the bounds of the target object.
// On subsequent draws of targets with a similar mid-y, make sure that
// there are no overlapping lines.
//
if( midPointMap.put( midy, segment ) != null ) {
//if( midy == 90 ) {
// New Line.
//
System.err.printf( "NEW: (%3.2f, %3d)-(%3.2f, %3d)\n", sx, midy, tx,
midy );
for( Line2D.Double psegment : midPointMap.getValues( midy ) ) {
// Previous Line.
//
System.err.printf( "OLD: (%3.2f, %3d)-(%3.2f, %3d)\n",
psegment.getX1(), midy, psegment.getX2(), midy );
}
//}
}
// Line for the bus.
//
result.moveTo( sx, midy );
result.lineTo( tx, midy );
这是另一个示例图片,可让您了解曼哈顿布局:
在上图中,Dialog 和 Window 之间的线已重叠(在此缩放下不太明显)。该图说明了如何存在多个子类,因此检测重叠必须考虑沿同一 y 中线的多个源 (sx, sy) 的多个目标 (tx, ty)。
midPointMap 变量是一个哈希集,每个键可以包含多个值:
private MultiValueMap<Integer, Line2D.Double> midPointMap =
new MultiValueMap<Integer, Line2D.Double>();
这会将中间值映射到一组线段。
如果线条与现有线段重叠,有什么想法如何不画线?
更新 #1
请注意,每个“总线”的线段没有特定的顺序。
【问题讨论】: