コード例 #1
0
  _getTransformMatrix: function(sourceProjection, destinationProjection, origin) {
    const { source, destination } = this.controlPoints;
    var sourcePoints = this._projectControlPoints(source, sourceProjection, origin);
    var destinationPoints = this._projectControlPoints(destination, destinationProjection, origin);

    var transform;
    var matrix = new Matrix(3, 3);
    if (sourcePoints.length >= 3) {
      // When we have 3 or more control points, use the affineFit library which produces better transforms.
      transform = affineFit(sourcePoints, destinationPoints);
      matrix.setData([
        /*      a      */  /*      c      */  /*      e      */
        transform.M[0][3], transform.M[1][3], transform.M[2][3],
        /*      b      */  /*      d      */  /*      f      */
        transform.M[0][4], transform.M[1][4], transform.M[2][4],
        0, 0, 1,
      ]);
    } else {
      // When we have less than 3 control points, use Nudged which accepts any number of points.
      transform = nudged.estimate("TSR", sourcePoints, destinationPoints);
      const { a, b, c, d, e, f } = transform.getMatrix();
      matrix.setData([
        a, c, e,
        b, d, f,
        0, 0, 1,
      ]);
    }
    return matrix;
  },
コード例 #2
0
  _transformPoint: function(matrix, point) {
    const pointVector = new Matrix(3, 1);
    pointVector.setData([point.x, point.y, 1]);

    const [x, y] = matrix.clone().multiply(pointVector).toArray();
    return { x, y };
  },