-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Convert Vec2 to Vec3 and vice versa #13994
Comments
In any case, these transformations should not be perceived by the user, but should be placed within your system for transformations |
@AnkoGo123 these parameter are passed in by developers, how to not be perceived by the user? Could you please describe it in more detail? Thanks. |
How about add a toVec3 in vec2 & toVec2 in vec3? @minggo |
It seems good to me. Could you please add function prototype? |
不明白为什么你觉得 toVecX 比构造更好点,那么比如 cc.Rect 这种数据结构呢?如果用 |
@1226085293 we do not want to use duck type as possible. Duck type is bad for performance. |
那么直接在构造内针对类型单独处理如何?示例如下 class Vec2 {
x: number;
y: number;
}
class Vec3 {
x: number;
y: number;
z: number;
constructor(value_: { x?: number; y?: number; z?: number }) {
if (value_ instanceof Vec2) {
this.x = value_.x;
this.y = value_.y;
this.z = 0;
} else {
this.x = value_.x ?? 0;
this.y = value_.y ?? 0;
this.z = value_.z ?? 0;
}
}
} |
I think it is duck type too. Am i right? |
如果把初始化参数改成对象类型甚至还提高了性能,但是按照你们对兼容性的做法估计也不会改,按照现有的构造参数类型去改就会是你说的性能浪费
|
So i think it is still better to implement it as static functions. |
Sorry, i mean to implement it as member functions. |
Some API returns Vec2, and some API accepts Vec3. It is not convenient. So need a way to convert types between Vec2 and Vec3. There are two ways to achieve it:
I think add constructors is better.
Can refer to this forum topic for detail information.
The text was updated successfully, but these errors were encountered: