Skip to content

Commit

Permalink
cleanup code for simplicity
Browse files Browse the repository at this point in the history
  • Loading branch information
sunilshetye committed Dec 27, 2024
1 parent 318dead commit 8a6ba8e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 26 deletions.
36 changes: 10 additions & 26 deletions blocks/Xcos/XmlParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions blocks/xcos2xml/replacesplitblocks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -102,20 +102,25 @@ 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=$?

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
Expand All @@ -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

0 comments on commit 8a6ba8e

Please sign in to comment.