From 8a6ba8e08d72ef0070947e2534fcb72e9c551650 Mon Sep 17 00:00:00 2001 From: Sunil Shetye Date: Fri, 27 Dec 2024 11:45:47 +0530 Subject: cleanup code for simplicity --- blocks/Xcos/XmlParser.py | 36 ++++++++++------------------------- blocks/xcos2xml/replacesplitblocks.sh | 8 ++++++++ 2 files changed, 18 insertions(+), 26 deletions(-) diff --git a/blocks/Xcos/XmlParser.py b/blocks/Xcos/XmlParser.py index c17c94b2..da08dd5d 100755 --- a/blocks/Xcos/XmlParser.py +++ b/blocks/Xcos/XmlParser.py @@ -262,35 +262,19 @@ def check_point_on_array(array, point, left_right_direction=True): rightY = float(array[i + 1]['y']) # Check if the point lies on the line segment between array[i] and array[i + 1] - if -40 <= leftY - pointY <= 40 and \ - -40 <= rightY - pointY <= 40 and \ - leftX <= pointX <= rightX: - return True, array[:i + 1] + [point], [point] + array[i + 1:] - if -40 <= leftX - pointX <= 40 and \ - -40 <= rightX - pointX <= 40 and \ - leftY <= pointY <= rightY: - return True, array[:i + 1] + [point], [point] + array[i + 1:] - # if left_right_direction: - if -20 <= leftX - pointX <= 20 and \ - (leftY <= pointY <= rightY or leftY >= pointY >= rightY): - print('to the left / right') - return True, array[:i + 1] + [point], [point] + array[i + 1:] - # else: - if -20 <= leftY - pointY <= 20 and \ - (leftX <= pointX <= rightX or leftX >= pointX >= rightX): - print('on the up / down') - return True, array[:i + 1] + [point], [point] + array[i + 1:] + pointbetweenleftrightx = leftX <= pointX <= rightX or leftX >= pointX >= rightX + samey = -40 <= leftY - pointY <= 40 and -40 <= rightY - pointY <= 40 + sameleftorrighty = -20 <= leftY - pointY <= 20 or -20 <= rightY - pointY <= 20 - # if left_right_direction: - if -20 <= rightX - pointX <= 20 and \ - (leftY <= pointY <= rightY or leftY >= pointY >= rightY): - print('to the right / right') + if pointbetweenleftrightx and (samey or sameleftorrighty): return True, array[:i + 1] + [point], [point] + array[i + 1:] - # else: - if -20 <= rightY - pointY <= 20 and \ - (leftX <= pointX <= rightX or leftX >= pointX >= rightX): - print('on the up / down') + + pointbetweenleftrighty = leftY <= pointY <= rightY or leftY >= pointY >= rightY + samex = -40 <= leftX - pointX <= 40 and -40 <= rightX - pointX <= 40 + sameleftorrightx = -20 <= leftX - pointX <= 20 or -20 <= rightX - pointX <= 20 + + if pointbetweenleftrighty and (samex or sameleftorrightx): return True, array[:i + 1] + [point], [point] + array[i + 1:] # switch direction for the next waypoint diff --git a/blocks/xcos2xml/replacesplitblocks.sh b/blocks/xcos2xml/replacesplitblocks.sh index dfb4be89..784c0caf 100755 --- a/blocks/xcos2xml/replacesplitblocks.sh +++ b/blocks/xcos2xml/replacesplitblocks.sh @@ -102,13 +102,17 @@ done xsltproc "$XSL" "$INPUT1" >"$TMPFILE1" xmllint --format "$TMPFILE1" >"$TMPFILE2" INPUT1="$BASE-xcos2xml.xml" +echo "Creating $INPUT1" >&2 cp -f "$TMPFILE2" "$INPUT1" xsltproc "$GEOMETRYXSL" "$INPUT1" >"$TMPFILE1" xmllint --format "$TMPFILE1" >"$TMPFILE2" INPUT1="$BASE-geometry.xml" +echo "Creating $INPUT1" >&2 cp -f "$TMPFILE2" "$INPUT1" +rm -f "$BASE-geometry."*.xml + echo "Running Xcos/XmlParser.py $INPUT1" >&2 Xcos/XmlParser.py "$INPUT1" >&2 && rv=$? || rv=$? @@ -116,6 +120,7 @@ while test $rv -gt 0; do oldrv=$rv INPUT1="$BASE-geometry.$rv.xml" + echo "Created $INPUT1" >&2 xmllint --format "$INPUT1" >"$TMPFILE2" cp -f "$TMPFILE2" "$INPUT1" echo "Running Xcos/XmlParser.py $INPUT1" >&2 @@ -128,10 +133,13 @@ while test $rv -gt 0; do done INPUT1="$BASE-geometry.$rv.xml" +echo "Created $INPUT1" >&2 xmllint --format "$INPUT1" >"$TMPFILE2" cp -f "$TMPFILE2" "$INPUT1" echo "Running Xcos/MxGraphParser.py $INPUT1" >&2 Xcos/MxGraphParser.py "$INPUT1" >&2 +INPUT1="$BASE-geometry.$rv.xcos" +echo "Created $INPUT1" >&2 exit 0 -- cgit