@giro3d/giro3d
Version:
A JS/WebGL framework for 3D geospatial data visualization
47 lines (45 loc) • 1.19 kB
JavaScript
import { Vector2, Vector4 } from 'three';
/**
* Describes a transformation of a point in 2D space without rotation.
* Typically used for to transform texture coordinates.
*/
export default class OffsetScale extends Vector4 {
isOffsetScale = true;
get offsetX() {
return this.x;
}
get offsetY() {
return this.y;
}
get scaleX() {
return this.z;
}
get scaleY() {
return this.w;
}
constructor(offsetX, offsetY, scaleX, scaleY) {
super(offsetX, offsetY, scaleX, scaleY);
}
static identity() {
return new OffsetScale(0, 0, 1, 1);
}
/**
* Transforms the point.
* @param point - The point to transform.
* @param target - The target to fill with the transformed point.
* @returns The transformed point.
*/
transform(point, target = new Vector2()) {
target.x = point.x * this.scaleX + this.offsetX;
target.y = point.y * this.scaleY + this.offsetY;
return target;
}
combine(offsetScale, target = new OffsetScale()) {
target.copy(this);
target.x += offsetScale.x * target.z;
target.y += offsetScale.y * target.w;
target.z *= offsetScale.z;
target.w *= offsetScale.w;
return target;
}
}