ixfx
    Preparing search index...

    Function pointScaler

    • Convert an absolute point to relative, in different coordinate spaces.

      When calling the returned function, the input value must be in the same scale as the intended output scale.

      Viewport-relative is used by default.

      Parameters

      Returns (
          a: Readonly<number | number[] | Geometry.Point>,
          b?: number,
      ) => Readonly<{ x: number; y: number }>

      const f = pointScaler({ to: 'screen' });
      document.addEventListener('click', evt => {
      const screenRelative = f(evt.screenX, evt.screenY);
      // Yields {x,y} on 0..1 scale
      });
      const f = pointScaler({ to: 'viewport' });
      document.addEventListener('click', evt => {
      const viewportRelative = f(evt.clientX, evt.clientY);
      // Yields {x,y} on 0..1 scale
      });
      const f = pointScaler({ to: 'document' });
      document.addEventListener('click', evt => {
      const documentRelative = f(evt.pageX, evt.pageY);
      // Yields {x,y} on 0..1 scale
      });