在处理中复制 PVectors
Copying PVectors in Processing
PVector a = new PVector(1, 2);
PVector b = a;
PVector c = a.copy();
PVector d = a.get();
不使用 .copy() 方法更改我的 drawing.Is b、c、d PVectors 之间有什么区别吗???
get()
和 copy()
在功能上是相同的——每个 returns 一个 PVector 的 深拷贝 。
PVector b = a;
创建一个引用 b
,它指向 a
指向的同一个 PVector
对象。
因此,b
和 c
& d
PVectors 之间存在差异。
让我们使用您的代码并在实例化其他变量后更改 a
的值,看看它们有何不同:
PVector a = new PVector(1, 2);
PVector b = a;
PVector c = a.copy();
PVector d = a.get();
a.x = 4;
println(a.x);
println(b.x);
println(c.x);
println(d.x);
输出:
4.0
4.0
1.0
1.0
PVector a = new PVector(1, 2);
PVector b = a;
PVector c = a.copy();
PVector d = a.get();
不使用 .copy() 方法更改我的 drawing.Is b、c、d PVectors 之间有什么区别吗???
get()
和 copy()
在功能上是相同的——每个 returns 一个 PVector 的 深拷贝 。
PVector b = a;
创建一个引用 b
,它指向 a
指向的同一个 PVector
对象。
因此,b
和 c
& d
PVectors 之间存在差异。
让我们使用您的代码并在实例化其他变量后更改 a
的值,看看它们有何不同:
PVector a = new PVector(1, 2);
PVector b = a;
PVector c = a.copy();
PVector d = a.get();
a.x = 4;
println(a.x);
println(b.x);
println(c.x);
println(d.x);
输出:
4.0
4.0
1.0
1.0