tapspace
Version:
A zoomable user interface lib for web apps
31 lines (26 loc) • 822 B
JavaScript
module.exports = function (orient, pivot) {
// @TransformerComponent:setOrientation(orient[, pivot])
//
// Rotate this basis so that its orientation matches the given orientation.
// The rotation is performed around the given pivot point.
// Use to match orientation between components.
//
// Parameters:
// orient
// an Orientation
// pivot
// optional Point, the transform origin for the rotation.
//
// Return
// this, for chaining
//
// Normalize
if (orient.transitRawOuter) {
orient = orient.transitRawOuter(this)
}
const currentRot = Math.atan2(this.tran.b, this.tran.a)
const targetRot = Math.atan2(orient.b, orient.a)
// Think like: revert current rotation (-currentRot) and then apply.
this.rotateBy(targetRot - currentRot, pivot)
return this
}