Skip to content

Commit 8a6ba8e

Browse files
committed
cleanup code for simplicity
1 parent 318dead commit 8a6ba8e

File tree

2 files changed

+18
-26
lines changed

2 files changed

+18
-26
lines changed

blocks/Xcos/XmlParser.py

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -262,35 +262,19 @@ def check_point_on_array(array, point, left_right_direction=True):
262262
rightY = float(array[i + 1]['y'])
263263

264264
# Check if the point lies on the line segment between array[i] and array[i + 1]
265-
if -40 <= leftY - pointY <= 40 and \
266-
-40 <= rightY - pointY <= 40 and \
267-
leftX <= pointX <= rightX:
268-
return True, array[:i + 1] + [point], [point] + array[i + 1:]
269-
if -40 <= leftX - pointX <= 40 and \
270-
-40 <= rightX - pointX <= 40 and \
271-
leftY <= pointY <= rightY:
272-
return True, array[:i + 1] + [point], [point] + array[i + 1:]
273265

274-
# if left_right_direction:
275-
if -20 <= leftX - pointX <= 20 and \
276-
(leftY <= pointY <= rightY or leftY >= pointY >= rightY):
277-
print('to the left / right')
278-
return True, array[:i + 1] + [point], [point] + array[i + 1:]
279-
# else:
280-
if -20 <= leftY - pointY <= 20 and \
281-
(leftX <= pointX <= rightX or leftX >= pointX >= rightX):
282-
print('on the up / down')
283-
return True, array[:i + 1] + [point], [point] + array[i + 1:]
266+
pointbetweenleftrightx = leftX <= pointX <= rightX or leftX >= pointX >= rightX
267+
samey = -40 <= leftY - pointY <= 40 and -40 <= rightY - pointY <= 40
268+
sameleftorrighty = -20 <= leftY - pointY <= 20 or -20 <= rightY - pointY <= 20
284269

285-
# if left_right_direction:
286-
if -20 <= rightX - pointX <= 20 and \
287-
(leftY <= pointY <= rightY or leftY >= pointY >= rightY):
288-
print('to the right / right')
270+
if pointbetweenleftrightx and (samey or sameleftorrighty):
289271
return True, array[:i + 1] + [point], [point] + array[i + 1:]
290-
# else:
291-
if -20 <= rightY - pointY <= 20 and \
292-
(leftX <= pointX <= rightX or leftX >= pointX >= rightX):
293-
print('on the up / down')
272+
273+
pointbetweenleftrighty = leftY <= pointY <= rightY or leftY >= pointY >= rightY
274+
samex = -40 <= leftX - pointX <= 40 and -40 <= rightX - pointX <= 40
275+
sameleftorrightx = -20 <= leftX - pointX <= 20 or -20 <= rightX - pointX <= 20
276+
277+
if pointbetweenleftrighty and (samex or sameleftorrightx):
294278
return True, array[:i + 1] + [point], [point] + array[i + 1:]
295279

296280
# switch direction for the next waypoint

blocks/xcos2xml/replacesplitblocks.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,20 +102,25 @@ done
102102
xsltproc "$XSL" "$INPUT1" >"$TMPFILE1"
103103
xmllint --format "$TMPFILE1" >"$TMPFILE2"
104104
INPUT1="$BASE-xcos2xml.xml"
105+
echo "Creating $INPUT1" >&2
105106
cp -f "$TMPFILE2" "$INPUT1"
106107

107108
xsltproc "$GEOMETRYXSL" "$INPUT1" >"$TMPFILE1"
108109
xmllint --format "$TMPFILE1" >"$TMPFILE2"
109110
INPUT1="$BASE-geometry.xml"
111+
echo "Creating $INPUT1" >&2
110112
cp -f "$TMPFILE2" "$INPUT1"
111113

114+
rm -f "$BASE-geometry."*.xml
115+
112116
echo "Running Xcos/XmlParser.py $INPUT1" >&2
113117
Xcos/XmlParser.py "$INPUT1" >&2 && rv=$? || rv=$?
114118

115119
while test $rv -gt 0; do
116120
oldrv=$rv
117121

118122
INPUT1="$BASE-geometry.$rv.xml"
123+
echo "Created $INPUT1" >&2
119124
xmllint --format "$INPUT1" >"$TMPFILE2"
120125
cp -f "$TMPFILE2" "$INPUT1"
121126
echo "Running Xcos/XmlParser.py $INPUT1" >&2
@@ -128,10 +133,13 @@ while test $rv -gt 0; do
128133
done
129134

130135
INPUT1="$BASE-geometry.$rv.xml"
136+
echo "Created $INPUT1" >&2
131137
xmllint --format "$INPUT1" >"$TMPFILE2"
132138
cp -f "$TMPFILE2" "$INPUT1"
133139

134140
echo "Running Xcos/MxGraphParser.py $INPUT1" >&2
135141
Xcos/MxGraphParser.py "$INPUT1" >&2
142+
INPUT1="$BASE-geometry.$rv.xcos"
143+
echo "Created $INPUT1" >&2
136144

137145
exit 0

0 commit comments

Comments
 (0)