Commit 647d1514 by Александр Committed by Alexander Kryklia

support both regions and rectangles

parent b4fb0cc4
...@@ -1724,14 +1724,15 @@ class ImageResponse(LoncapaResponse): ...@@ -1724,14 +1724,15 @@ class ImageResponse(LoncapaResponse):
Each <imageinput> should specify a rectangle(s) or region(s), given as an Each <imageinput> should specify a rectangle(s) or region(s), given as an
attribute, defining the correct answer. attribute, defining the correct answer.
Rectangle(s) are more prioritized over regions due to simplicity and
backward compatibility. In this example regions will be ignored:
<imageinput src="/static/images/Lecture2/S2_p04.png" width="811" height="610" <imageinput src="/static/images/Lecture2/S2_p04.png" width="811" height="610"
rectangle="(10,10)-(20,30);(12,12)-(40,60)" rectangle="(10,10)-(20,30);(12,12)-(40,60)"
regions='[[[10,10], [20,30], [40, 10]], [[100,100], [120,130], [110,150]]]'/> regions='[[[10,10], [20,30], [40, 10]], [[100,100], [120,130], [110,150]]]'/>
Regions is list of lists [region1, region2, region3, ...] where regionN Regions is list of lists [region1, region2, region3, ...] where regionN
is ordered list of points: [[1,1], [100,100], [50,50], [20, 70]]. is ordered list of points: [[1,1], [100,100], [50,50], [20, 70]].
Returns:
True, if click is inside any region or rectangle. Otherwise False.
""" """
snippets = [{'snippet': '''<imageresponse> snippets = [{'snippet': '''<imageresponse>
<imageinput src="image1.jpg" width="200" height="100" <imageinput src="image1.jpg" width="200" height="100"
...@@ -1792,7 +1793,6 @@ class ImageResponse(LoncapaResponse): ...@@ -1792,7 +1793,6 @@ class ImageResponse(LoncapaResponse):
if (llx <= gx <= urx) and (lly <= gy <= ury): if (llx <= gx <= urx) and (lly <= gy <= ury):
correct_map.set(aid, 'correct') correct_map.set(aid, 'correct')
break break
else: # rectangles are more prioretized for same id
if regions[aid]: if regions[aid]:
parsed_region = json.loads(regions[aid]) parsed_region = json.loads(regions[aid])
for region in parsed_region: for region in parsed_region:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment