PVector.random2D() 问题

PVector.random2D() issue

如果我的粒子(class)的位置在边缘,则尝试 return 一个 PVector。这将打印错误 "The method must return a result of type PVector"

PVector edges() {
if (pos.x < 0 + 10 || pos.x > width - 10 || pos.y > 0 +10 || pos.y < height - 10) {
    return PVector.random2D();
 }
}

您的函数不处理边缘测试的其他分支,在这种情况下,返回的位置可能应该是相同的:

PVector edges() {
if (pos.x < 0 + 10 || pos.x > width - 10 || pos.y > 0 +10 || pos.y < height - 10) {
    return PVector.random2D();
 }else{
    return pos;
 }
}