From f20e9dd20102ab9db6a0fe8e9273b06a5fc431e3 Mon Sep 17 00:00:00 2001 From: David Tschumperle Date: Mon, 16 Sep 2024 18:26:33 +0200 Subject: [PATCH] Add optional argument to math parser function 'sort()' to specify sorting index. --- CImg.h | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/CImg.h b/CImg.h index 6b49bb3b..4b82e8ea 100644 --- a/CImg.h +++ b/CImg.h @@ -22434,23 +22434,28 @@ namespace cimg_library { _cimg_mp_op("Function 'sort()'"); s1 = ss5; while (s1::vector((ulongT)mp_sort,pos,arg1,p1,arg2,arg3,arg4).move_to(code); + CImg::vector((ulongT)mp_sort,pos,arg1,p1,arg2,arg3,arg4,arg5).move_to(code); return_comp = true; _cimg_mp_return(pos); } @@ -28556,7 +28561,8 @@ namespace cimg_library { const unsigned int siz = (unsigned int)mp.opcode[3], nb_elts = mp.opcode[5]==~0U?siz:(unsigned int)_mp_arg(5), - siz_elt = (unsigned int)_mp_arg(6); + siz_elt = (unsigned int)_mp_arg(6), + sort_index = std::min((unsigned int)_mp_arg(7),siz_elt - 1); const ulongT sn = siz_elt*nb_elts; if (sn>siz || siz_elt<1) throw CImgArgumentException("[" cimg_appname "_math_parser] CImg<%s>: Function 'sort()': " @@ -28564,7 +28570,7 @@ namespace cimg_library { "for sorting a vector of size %u.", mp.imgin.pixel_type(),_mp_arg(5),_mp_arg(6),siz); CImg(ptrd,siz_elt,nb_elts,1,1,true) = CImg(ptrs,siz_elt,nb_elts,1,1,true). - get_sort(is_increasing,siz_elt>1?'y':0); + shift(-(int)sort_index,0,0,0,2).get_sort(is_increasing,siz_elt>1?'y':0).shift((int)sort_index,0,0,0,2); if (sn(ptrd + sn,siz - sn,1,1,1,true) = CImg(ptrs + sn,siz - sn,1,1,1,true); return cimg::type::nan(); }