处理 - 管理 ArrayLists

Processing - Managing ArrayLists

我正在努力解决这个问题 ArrayList。基本上我有一个 ArrayListPVector 对象——在我的代码中有两对 (x,y) 变量进入数组。我想知道如何分别管理这两对。我需要知道哪个是 (x1,y1),哪个是 (x2,y2),并可能命名它们。我该怎么做?

Blob(float x, float y) {
  minx = x;
  miny = y;
  maxx = x;
  maxy = y;
  points = new ArrayList<PVector>();
  points.add(new PVector(x, y));
}

根据你的问题,我不完全确定你想要实现什么,但是如果你想从你的 blob 函数创建 2 个 PVector 对象并将它们添加到你的 ArrayList,然后再向函数添加 2 个参数。例如:

void blob(float x1, float y1, float x2, float y2) {
  minx = x1;
  miny = y1;
  maxx = x2;
  maxy = y2;
  points = new ArrayList<PVector>();
  points.add(new PVector(minx, miny));
  points.add(new PVector(maxx, maxy));
}

然后您可以使用 ArrayListindex 来识别这两个 PVector 对象,并为它们命名,您可以将它们分配给变量。例如:

PVector firstPoint = points.get(0);
PVector secondPoint = points.get(1);