/** * Returns a new transform representing a rotation in the xy plane, around a * given point. The rotation is given is half turns. The actual rotation is * {@code halfTurns * 180}. The tile corner flags change the point to be the * tile corner or edge instead of the center. When both flags are false, the * center is used. When only one is true the edge on the opposite axis to * the flag is used. When both are true the upper corner is used. * * @param halfTurns The number of half turns in this rotation * @param point The point of rotation, as tile coordinates * @param tileCornerX Whether or not to use the corner of the tile instead * of the center on the x axis * @param tileCornerY Whether or not to use the corner of the tile instead * of the center on the y axis * @return The new rotation transform */ public static DiscreteTransform2 fromRotation(int halfTurns, Vector2i point, boolean tileCornerX, boolean tileCornerY) { Vector2d pointDouble = point.toDouble(); if (tileCornerX) { pointDouble = pointDouble.add(0.5, 0); } if (tileCornerY) { pointDouble = pointDouble.add(0, 0.5); } return new DiscreteTransform2( Matrix3d.createTranslation(pointDouble.negate()).rotate(Complexd.fromAngleDeg(halfTurns * 180)).translate(pointDouble)); }
/** * Adds a a rotation to this transform, in the xy plane, around a given * point, and returns it as a new transform. The rotation is given is half * turns. The actual rotation is {@code halfTurns * 180}. The tile corner * flags change the point to be the tile corner or edge instead of the * center. When both flags are false, the center is used. When only one is * true the edge on the opposite axis to the flag is used. When both are * true the upper corner is used. * * @param halfTurns The number of half turns in this rotation * @param point The point of rotation, as tile coordinates * @param tileCornerX Whether or not to use the corner of the tile instead * of the center on the x axis * @param tileCornerY Whether or not to use the corner of the tile instead * of the center on the y axis * @return The rotated transform as a copy */ public DiscreteTransform2 withRotation(int halfTurns, Vector2i point, boolean tileCornerX, boolean tileCornerY) { Vector2d pointDouble = point.toDouble(); if (tileCornerX) { pointDouble = pointDouble.add(0.5, 0); } if (tileCornerY) { pointDouble = pointDouble.add(0, 0.5); } return new DiscreteTransform2( this.matrix.translate(pointDouble.negate()).rotate(Complexd.fromAngleDeg(halfTurns * 180)).translate(pointDouble)); }
/** * Returns a new transform representing a rotation in the xy plane, around a * given point. The rotation is given is quarter turns. The actual rotation * is {@code quarterTurns * 90}. The tile corner flag change the point to be * the tile corner instead of the center. * * @param quarterTurns The number of quarter turns in this rotation * @param point The point of rotation, as tile coordinates * @param tileCorner Whether or not to use the corner of the tile instead of * the center * @return The new rotation transform */ public static DiscreteTransform2 fromRotation(int quarterTurns, Vector2i point, boolean tileCorner) { Vector2d pointDouble = point.toDouble(); if (tileCorner) { pointDouble = pointDouble.add(0.5, 0.5); } return new DiscreteTransform2( Matrix3d.createTranslation(pointDouble.negate()).rotate(Complexd.fromAngleDeg(quarterTurns * 90)).translate(pointDouble)); }
/** * Adds a a rotation to this transform, in the xy plane, around a given * point, and returns it as a new transform. The rotation is given is * quarter turns. The actual rotation is {@code quarterTurns * 90}. The tile * corner flag changes the point to be the tile upper corner instead of the * center. * * @param quarterTurns The number of quarter turns in this rotation * @param point The point of rotation, as tile coordinates * @param tileCorner Whether or not to use the corner of the tile instead of * the center * @return The rotated transform as a copy */ public DiscreteTransform2 withRotation(int quarterTurns, Vector2i point, boolean tileCorner) { Vector2d pointDouble = point.toDouble(); if (tileCorner) { pointDouble = pointDouble.add(0.5, 0.5); } return new DiscreteTransform2( this.matrix.translate(pointDouble.negate()).rotate(Complexd.fromAngleDeg(quarterTurns * 90)).translate(pointDouble)); }
public Vector2d add(Vector2d v) { return add(v.x, v.y); }
public Vector2d add(float x, float y) { return add((double) x, (double) y); }
public Vector2d add(float x, float y) { return add((double) x, (double) y); }
public Vector2d add(Vector2d v) { return add(v.x, v.y); }
/** * Calculates the linear interpolation between a and b with the given percent * * @param a The first know value * @param b The second know value * @param percent The percent * @return the interpolated vector */ public static Vector2d lerp(Vector2d a, Vector2d b, double percent) { return a.mul(1 - percent).add(b.mul(percent)); }
/** * Calculates the linear interpolation between a and b with the given percent * * @param a The first know value * @param b The second know value * @param percent The percent * @return the interpolated vector */ public static Vector2d lerp(Vector2d a, Vector2d b, double percent) { return a.mul(1 - percent).add(b.mul(percent)); }
/** * Adds a a rotation to this transform, in the xy plane, around a given * point, and returns it as a new transform. The rotation is given is half * turns. The actual rotation is {@code halfTurns * 180}. The tile corner * flags change the point to be the tile corner or edge instead of the * center. When both flags are false, the center is used. When only one is * true the edge on the opposite axis to the flag is used. When both are * true the upper corner is used. * * @param halfTurns The number of half turns in this rotation * @param point The point of rotation, as tile coordinates * @param tileCornerX Whether or not to use the corner of the tile instead * of the center on the x axis * @param tileCornerY Whether or not to use the corner of the tile instead * of the center on the y axis * @return The rotated transform as a copy */ public DiscreteTransform2 withRotation(int halfTurns, Vector2i point, boolean tileCornerX, boolean tileCornerY) { Vector2d pointDouble = point.toDouble(); if (tileCornerX) { pointDouble = pointDouble.add(0.5, 0); } if (tileCornerY) { pointDouble = pointDouble.add(0, 0.5); } return new DiscreteTransform2( this.matrix.translate(pointDouble.negate()).rotate(Complexd.fromAngleDeg(halfTurns * 180)).translate(pointDouble)); }
/** * Returns a new transform representing a rotation in the xy plane, around a * given point. The rotation is given is half turns. The actual rotation is * {@code halfTurns * 180}. The tile corner flags change the point to be the * tile corner or edge instead of the center. When both flags are false, the * center is used. When only one is true the edge on the opposite axis to * the flag is used. When both are true the upper corner is used. * * @param halfTurns The number of half turns in this rotation * @param point The point of rotation, as tile coordinates * @param tileCornerX Whether or not to use the corner of the tile instead * of the center on the x axis * @param tileCornerY Whether or not to use the corner of the tile instead * of the center on the y axis * @return The new rotation transform */ public static DiscreteTransform2 fromRotation(int halfTurns, Vector2i point, boolean tileCornerX, boolean tileCornerY) { Vector2d pointDouble = point.toDouble(); if (tileCornerX) { pointDouble = pointDouble.add(0.5, 0); } if (tileCornerY) { pointDouble = pointDouble.add(0, 0.5); } return new DiscreteTransform2( Matrix3d.createTranslation(pointDouble.negate()).rotate(Complexd.fromAngleDeg(halfTurns * 180)).translate(pointDouble)); }
/** * Returns a new transform representing a rotation in the xy plane, around a * given point. The rotation is given is quarter turns. The actual rotation * is {@code quarterTurns * 90}. The tile corner flag change the point to be * the tile corner instead of the center. * * @param quarterTurns The number of quarter turns in this rotation * @param point The point of rotation, as tile coordinates * @param tileCorner Whether or not to use the corner of the tile instead of * the center * @return The new rotation transform */ public static DiscreteTransform2 fromRotation(int quarterTurns, Vector2i point, boolean tileCorner) { Vector2d pointDouble = point.toDouble(); if (tileCorner) { pointDouble = pointDouble.add(0.5, 0.5); } return new DiscreteTransform2( Matrix3d.createTranslation(pointDouble.negate()).rotate(Complexd.fromAngleDeg(quarterTurns * 90)).translate(pointDouble)); }
/** * Adds a a rotation to this transform, in the xy plane, around a given * point, and returns it as a new transform. The rotation is given is * quarter turns. The actual rotation is {@code quarterTurns * 90}. The tile * corner flag changes the point to be the tile upper corner instead of the * center. * * @param quarterTurns The number of quarter turns in this rotation * @param point The point of rotation, as tile coordinates * @param tileCorner Whether or not to use the corner of the tile instead of * the center * @return The rotated transform as a copy */ public DiscreteTransform2 withRotation(int quarterTurns, Vector2i point, boolean tileCorner) { Vector2d pointDouble = point.toDouble(); if (tileCorner) { pointDouble = pointDouble.add(0.5, 0.5); } return new DiscreteTransform2( this.matrix.translate(pointDouble.negate()).rotate(Complexd.fromAngleDeg(quarterTurns * 90)).translate(pointDouble)); }