v1.3.11: 全局更名为 EDC|易得; 更新下载屏幕常亮+防误触退出; 连线法向箭头+多线避让+平板拖动优化(线段拖动/磁吸虚线/抓取光标/实时预览)
This commit is contained in:
@@ -761,6 +761,153 @@ void main() {
|
||||
});
|
||||
});
|
||||
|
||||
group('连线法向与自动避让', () {
|
||||
test('水平相邻:出口水平、箭头垂直射入目标左边', () {
|
||||
const ArchShape a = ArchShape(
|
||||
id: 'A',
|
||||
type: ArchShapeType.rect,
|
||||
rect: Rect.fromLTWH(0, 0, 100, 80));
|
||||
const ArchShape b = ArchShape(
|
||||
id: 'B',
|
||||
type: ArchShapeType.rect,
|
||||
rect: Rect.fromLTWH(300, 40, 100, 80));
|
||||
final ArchDoc doc =
|
||||
ArchDoc.empty.copyWith(shapes: <ArchShape>[a, b]);
|
||||
final ArchConnector conn = ArchConnector(
|
||||
id: 'C1',
|
||||
fromId: 'A',
|
||||
from: a.rect.center,
|
||||
toId: 'B',
|
||||
to: b.rect.center,
|
||||
);
|
||||
final ArchConnGeometry g = archConnectorGeometry(doc, conn);
|
||||
expect(g.start.dx, closeTo(100, 0.5));
|
||||
expect(g.end.dx, closeTo(300, 0.5));
|
||||
expect((g.pts[1].dy - g.start.dy).abs(), lessThan(0.5),
|
||||
reason: '出口应沿法向(水平)');
|
||||
final Offset lastD = g.end - g.pts[g.pts.length - 2];
|
||||
expect(lastD.dy.abs(), lessThan(0.5), reason: '箭头应水平射入');
|
||||
expect(lastD.dx, greaterThan(0));
|
||||
});
|
||||
|
||||
test('垂直相邻:出口垂直、箭头垂直射入目标上边', () {
|
||||
const ArchShape a = ArchShape(
|
||||
id: 'A',
|
||||
type: ArchShapeType.rect,
|
||||
rect: Rect.fromLTWH(0, 0, 100, 80));
|
||||
const ArchShape b = ArchShape(
|
||||
id: 'B',
|
||||
type: ArchShapeType.rect,
|
||||
rect: Rect.fromLTWH(60, 300, 100, 80));
|
||||
final ArchDoc doc =
|
||||
ArchDoc.empty.copyWith(shapes: <ArchShape>[a, b]);
|
||||
final ArchConnector conn = ArchConnector(
|
||||
id: 'C1',
|
||||
fromId: 'A',
|
||||
from: a.rect.center,
|
||||
toId: 'B',
|
||||
to: b.rect.center,
|
||||
);
|
||||
final ArchConnGeometry g = archConnectorGeometry(doc, conn);
|
||||
expect(g.start.dy, closeTo(80, 0.5));
|
||||
expect(g.end.dy, closeTo(300, 0.5));
|
||||
expect((g.pts[1].dx - g.start.dx).abs(), lessThan(0.5),
|
||||
reason: '出口应沿法向(垂直)');
|
||||
final Offset lastD = g.end - g.pts[g.pts.length - 2];
|
||||
expect(lastD.dx.abs(), lessThan(0.5), reason: '箭头应垂直射入');
|
||||
expect(lastD.dy, greaterThan(0));
|
||||
});
|
||||
|
||||
test('多条连线贴同一条边:自动错开(槽位避让)', () {
|
||||
const ArchShape hub = ArchShape(
|
||||
id: 'H',
|
||||
type: ArchShapeType.rect,
|
||||
rect: Rect.fromLTWH(0, 0, 100, 240));
|
||||
const ArchShape b1 = ArchShape(
|
||||
id: 'B1',
|
||||
type: ArchShapeType.rect,
|
||||
rect: Rect.fromLTWH(320, 0, 80, 60));
|
||||
const ArchShape b2 = ArchShape(
|
||||
id: 'B2',
|
||||
type: ArchShapeType.rect,
|
||||
rect: Rect.fromLTWH(320, 90, 80, 60));
|
||||
const ArchShape b3 = ArchShape(
|
||||
id: 'B3',
|
||||
type: ArchShapeType.rect,
|
||||
rect: Rect.fromLTWH(320, 180, 80, 60));
|
||||
final List<ArchConnector> conns = <ArchConnector>[
|
||||
ArchConnector(
|
||||
id: 'C1',
|
||||
fromId: 'H',
|
||||
from: hub.rect.center,
|
||||
toId: 'B1',
|
||||
to: b1.rect.center),
|
||||
ArchConnector(
|
||||
id: 'C2',
|
||||
fromId: 'H',
|
||||
from: hub.rect.center,
|
||||
toId: 'B2',
|
||||
to: b2.rect.center),
|
||||
ArchConnector(
|
||||
id: 'C3',
|
||||
fromId: 'H',
|
||||
from: hub.rect.center,
|
||||
toId: 'B3',
|
||||
to: b3.rect.center),
|
||||
];
|
||||
final ArchDoc doc = ArchDoc.empty.copyWith(
|
||||
shapes: <ArchShape>[hub, b1, b2, b3],
|
||||
connectors: conns,
|
||||
);
|
||||
final List<double> ys = <double>[
|
||||
for (final ArchConnector cn in conns)
|
||||
archConnectorGeometry(doc, cn).start.dy,
|
||||
];
|
||||
// 起点互不相同、均落在 hub 右边框内,并保持自然顺序。
|
||||
expect(ys[0], lessThan(ys[1]));
|
||||
expect(ys[1], lessThan(ys[2]));
|
||||
for (final double y in ys) {
|
||||
expect(y, greaterThan(0));
|
||||
expect(y, lessThan(240));
|
||||
}
|
||||
for (final ArchConnector cn in conns) {
|
||||
final ArchConnGeometry g = archConnectorGeometry(doc, cn);
|
||||
expect(g.start.dx, closeTo(100, 0.5), reason: '起点应贴 hub 右边框');
|
||||
}
|
||||
});
|
||||
|
||||
test('带折点:最后一段仍沿法向射入目标边', () {
|
||||
const ArchShape a = ArchShape(
|
||||
id: 'A',
|
||||
type: ArchShapeType.rect,
|
||||
rect: Rect.fromLTWH(0, 0, 100, 80));
|
||||
const ArchShape b = ArchShape(
|
||||
id: 'B',
|
||||
type: ArchShapeType.rect,
|
||||
rect: Rect.fromLTWH(300, 200, 100, 80));
|
||||
final ArchDoc doc =
|
||||
ArchDoc.empty.copyWith(shapes: <ArchShape>[a, b]);
|
||||
final ArchConnector conn = ArchConnector(
|
||||
id: 'C1',
|
||||
fromId: 'A',
|
||||
from: a.rect.center,
|
||||
toId: 'B',
|
||||
to: b.rect.center,
|
||||
mids: const <Offset>[Offset(150, 90)],
|
||||
);
|
||||
final ArchConnGeometry g = archConnectorGeometry(doc, conn);
|
||||
final Offset lastD = g.end - g.pts[g.pts.length - 2];
|
||||
expect(lastD.dx.abs() < 0.5 || lastD.dy.abs() < 0.5, isTrue,
|
||||
reason: '最后一段应横平竖直(法向)');
|
||||
const Rect br = Rect.fromLTWH(300, 200, 100, 80);
|
||||
final bool onBorder = (g.end.dx - br.left).abs() < 0.5 ||
|
||||
(g.end.dx - br.right).abs() < 0.5 ||
|
||||
(g.end.dy - br.top).abs() < 0.5 ||
|
||||
(g.end.dy - br.bottom).abs() < 0.5;
|
||||
expect(onBorder, isTrue, reason: '终点应落在目标边框上');
|
||||
});
|
||||
});
|
||||
|
||||
group('橡皮擦', () {
|
||||
test('连续擦除计入一次撤销', () {
|
||||
final AppController c = AppController(project: Project.demo());
|
||||
|
||||
Reference in New Issue
Block a user