From bf68fd5809ced8bcae8be34e0d3ed516024d28ea Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Fri, 13 Jan 2023 19:04:50 +0800 Subject: [PATCH] feat: add links between cases --- svg-demo/svg_dump.py | 47 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 37 insertions(+), 10 deletions(-) diff --git a/svg-demo/svg_dump.py b/svg-demo/svg_dump.py index ed579f6..46392c5 100755 --- a/svg-demo/svg_dump.py +++ b/svg-demo/svg_dump.py @@ -1,15 +1,17 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- -CASE_WIDTH = 24 -CASE_HEIGHT = 36 +CASE_WIDTH = 48 +CASE_HEIGHT = 72 -CASE_DISTANCE_X = 40 -CASE_DISTANCE_Y = 20 +CASE_DISTANCE_X = 80 +CASE_DISTANCE_Y = 40 MAIN_MARGIN_X = 10 MAIN_MARGIN_Y = 8 +LINK_OFFSET = 1 + layer = [ ["603EDF5CAFFF5E2"], # layer 0 ["61BEC75CAFFF5E2","0C3EDF5CAFFF5E2"], # layer 1 @@ -61,24 +63,49 @@ def case_address(layer_num: int, layer_index: int) -> (int, int): ) +def link_address(start_layer_num: int, start_layer_index: int, end_layer_num: int, end_layer_index: int) -> (int, int, int, int): + + x1, y1 = case_address(start_layer_num, start_layer_index) + x2, y2 = case_address(end_layer_num, end_layer_index) + + return ( + x1 + int(CASE_WIDTH / 2), + y1 + CASE_HEIGHT + LINK_OFFSET, + x2 + int(CASE_WIDTH / 2), + y2 - LINK_OFFSET, + ) + + def svg_rect(left: int, top: int, width: int, height: int): return '' % ( left, top, width, height ) -print('') +def svg_line(start_x: int, start_y: int, end_x: int, end_y: int): + return '' % ( + start_x, start_y, end_x, end_y + ) + +MAIN_WIDTH = MAX_CASE_X * CASE_WIDTH + (MAX_CASE_X - 1) * CASE_DISTANCE_X + MAIN_MARGIN_X * 2 +MAIN_HEIGHT = MAX_CASE_Y * CASE_HEIGHT + (MAX_CASE_Y - 1) * CASE_DISTANCE_Y + MAIN_MARGIN_Y * 2 + +print('' % (MAIN_WIDTH, MAIN_HEIGHT)) for layer_num in range(0, len(layer)): for layer_index in range(0, len(layer[layer_num])): x, y = case_address(layer_num, layer_index) print(' ', svg_rect(x, y, CASE_WIDTH, CASE_HEIGHT)) +for layer_num in range(0, len(link)): + for layer_index in range(0, len(link[layer_num])): + for next_index in range(0, len(link[layer_num][layer_index])): + + # print('(%d, %d) -> (%d, %d)' % (layer_num, layer_index, layer_num + 1, next_index)) + x1, y1, x2, y2 = link_address(layer_num, layer_index, layer_num + 1, next_index) + print(' ', svg_line(x1, y1, x2, y2)) -# for case in [(0, 0), (1, 0), (1, 1)]: # (layer_num, layer_index) -# x, y = case_address(case[0], case[1]) -# -# print(' ', svg_rect(x, y, CASE_WIDTH, CASE_HEIGHT)) - # print(case_address(case[0], case[1])) +# x1, y1, x2, y2 = link_address(0, 0, 1, 0) +# print(' ', svg_line(x1, y1, x2, y2)) print('')