Sorting an array

// https://Discourse.processing.org/t/sorting-an-array/20992/3
// GoToLoop (2020/May/17)

import java.util.Collections;
import java.util.List;

final PVector[] vecs = {
  new PVector(100, -100), 
  new PVector(-130, 65), 
  new PVector(135, 155)
};

final List<VecHead> points = new ArrayList<VecHead>(vecs.length);

void setup() {
  for (final PVector v : vecs)  points.add(new VecHead(v));
  println(points);

  Collections.sort(points);
  println(points);

  exit();
}

static class VecHead extends PVector implements Comparable<VecHead> {
  float heading;

  VecHead(final PVector vec) {
    heading = set(vec).heading();
  }

  VecHead reheading() {
    heading = heading();
    return this;
  }

  @Override int compareTo(final VecHead v) { // ascending
    return (int) Math.signum(heading - v.heading);
  }

  @Override String toString() {
    return super.toString() + " (heading: " + heading + ')';
  }
}