void reverse_arcs(RawArray<CircleArc> arcs) { if(arcs.empty()) return; arcs.reverse(); const auto temp_q = arcs.front().q; for(int i = 0,j = 1; j<arcs.size(); i=j++) { arcs[i].q = -arcs[j].q; } arcs.back().q = -temp_q; }
template<int axis> static inline int spatial_partition(RawArray<Perturbed2> X, Random& random) { // We use exact arithmetic to perform the partition, which is important in case many points are coincident #define LESS(i,j) (i!=j && axis_less<axis>(X[i],X[j])) // We partition by picking three elements at random, and running partition based on the middle element. const int n = X.size(); int i0 = random.uniform<int>(0,n), i1 = random.uniform<int>(0,n), i2 = random.uniform<int>(0,n); if (!LESS(i0,i1)) swap(i0,i1); if (!LESS(i1,i2)) swap(i1,i2); if (!LESS(i0,i1)) swap(i0,i1); const auto Xmid = X[i1]; swap(X[i1],X.back()); // Perform the partition. We use the version of partition from Wikipedia: http://en.wikipedia.org/wiki/Quicksort#In-place_version int mid = 0; for (const int i : range(n-1)) if (axis_less<axis>(X[i],Xmid)) swap(X[i],X[mid++]); return mid; }
// Safely expose snap_divs to python for testing purposes static Array<Quantized> snap_divs_test(RawArray<mp_limb_t,2> values, const bool take_sqrt) { GEODE_ASSERT(values.m && !values.back().contains_only(0)); Array<Quantized> result(values.m-1); snap_divs(result,values,take_sqrt); return result; }