From 96a0aebe3a89c1cacd0b4983af8f8c6cf7bda5b7 Mon Sep 17 00:00:00 2001 From: Sei Lisa Date: Wed, 18 Oct 2017 17:40:25 +0200 Subject: [PATCH] Fix the logic in llDetectedTouchST/UV. They were returning TOUCH_INVALID_TEXCOORD for num <= idx <= 15 in detection events which were not touch events. That is incorrect. Now it correctly returns: - ZERO_VECTOR when idx < 0 or idx > 15 or the event is known not to be a detection event. - TOUCH_INVALID_TEXCOORD when idx == 0 and the event is known to be a detection event that is not a touch event. - Raises ELSLCantCompute otherwise. --- lslopt/lslextrafuncs.py | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/lslopt/lslextrafuncs.py b/lslopt/lslextrafuncs.py index 1432f2e..33d5364 100644 --- a/lslopt/lslextrafuncs.py +++ b/lslopt/lslextrafuncs.py @@ -142,17 +142,27 @@ def llDetectedTouchPos(idx, event=None): def llDetectedTouchST(idx, event=None): idx = fi(idx) - if 0 <= idx <= 15 and (event in TouchEvents or event is None): + if 0 <= idx <= 15 and (event is None or event in DetectionEvents): + # In detection events that are not touch events, it returns + # TOUCH_INVALID_TEXCOORD if idx < num, else ZERO_VECTOR, + # but we only know that num >= 1. + if idx == 0 and event is not None and event not in TouchEvents: + # index 0 always exists, so we know the result + return TOUCH_INVALID_TEXCOORD raise ELSLCantCompute - return TOUCH_INVALID_TEXCOORD if event in DetectionEvents \ - and 0 <= idx <= 15 else ZERO_VECTOR + return ZERO_VECTOR def llDetectedTouchUV(idx, event=None): idx = fi(idx) - if 0 <= idx <= 15 and (event in TouchEvents or event is None): + if 0 <= idx <= 15 and (event is None or event in DetectionEvents): + # In detection events that are not touch events, it returns + # TOUCH_INVALID_TEXCOORD if idx < num, else ZERO_VECTOR, + # but we only know that num >= 1. + if idx == 0 and event is not None and event not in TouchEvents: + # index 0 always exists, so we know the result + return TOUCH_INVALID_TEXCOORD raise ELSLCantCompute - return TOUCH_INVALID_TEXCOORD if event in DetectionEvents \ - and 0 <= idx <= 15 else ZERO_VECTOR + return ZERO_VECTOR def llDetectedType(idx, event=None): idx = fi(idx)