From 82d4cb5114a9d5f341dba84cbee51fcfe1504de6 Mon Sep 17 00:00:00 2001 From: Gau o fthe Veldt Date: Sun, 17 Jul 2016 16:43:10 -0700 Subject: [PATCH] Added slicing operation to DVector via DVector.subarray(int start,int end) method. Negative indices index from the end of the array. Indices are range checked before attempting and return appropriate error when out of range. Binding for RawArray in gdscript to access DVector.subarray() provided. Documentation of RawArray.subarray() in classes.xml provided. --- core/dvector.h | 28 ++++++++++++++++++++++++++++ core/variant_call.cpp | 2 ++ doc/base/classes.xml | 11 +++++++++++ 3 files changed, 41 insertions(+) diff --git a/core/dvector.h b/core/dvector.h index a5519ed6041..9a546416177 100644 --- a/core/dvector.h +++ b/core/dvector.h @@ -262,6 +262,34 @@ public: w[bs+i]=r[i]; } + DVector subarray(int p_from, int p_to) { + + if (p_from<0) { + p_from=size()+p_from; + } + if (p_to<0) { + p_to=size()+p_to; + } + if (p_from<0 || p_from>=size()) { + DVector& aux=*((DVector*)0); // nullreturn + ERR_FAIL_COND_V(p_from<0 || p_from>=size(),aux) + } + if (p_to<0 || p_to>=size()) { + DVector& aux=*((DVector*)0); // nullreturn + ERR_FAIL_COND_V(p_to<0 || p_to>=size(),aux) + } + + DVector slice; + int span=1 + p_to - p_from; + slice.resize(span); + Read r = read(); + Write w = slice.write(); + for (int i=0; i + + + + + + + + + Returns the slice of the [RawArray] between indices (inclusive) as a new [RawArray]. Any negative index is considered to be from the end of the array. + +