import { interpolate } from "d3-interpolate" ; import { Animation } from "./animation" ; import { ANIME , EASE_TYPE } from "../cubicons/constants" ; import { xGtoW , yGtoW } from "../math/convertUnit" ; import { Geometry } from "../cubicons/geometry" ; /**
 * Rotate a geometric cubicon by a specified angle.
 */ export class Rotate extends Animation { degree : number ; constructor ( params ) { super ( { cubicon : params . cubicon , duration : params . duration ?? ANIME . ROTATE , ease : params . ease , } ) ; this . degree = params . degree ; } play ( sleepTime ) { this . rotate ( this . cubicon , this . degree , sleepTime ) ; } private rotate ( cubicon , degree , sleepTime ) { if ( cubicon . constructor . name === "Vector" || cubicon . constructor . name === "Line" ) { this . duration = 2000 ; } cubicon . moveAngle += degree ; const v = cubicon . moveVector ; cubicon . g_cubiconWrapper . transition ( ) . ease ( this . ease ) . delay ( cubicon . elapsedTime + sleepTime ) . duration ( this . duration ) . attrTween ( "transform" , ( ) => interpolate ( `translate(${ xGtoW ( v . x ) }, ${ yGtoW ( v . y ) }) rotate(${ cubicon . angle })` , `translate(${ xGtoW ( v . x ) }, ${ yGtoW ( v . y ) }) rotate(${ cubicon . angle + degree })` ) ) . on ( "end" , ( ) => ( cubicon . angle += degree ) ) ; cubicon . elapsedTime += this . duration + sleepTime ; } }