我同意評論,不要爲自己實施公式而付出努力。
import java.awt.geom.{AffineTransform => JTransform}
object AffineTransform {
implicit def toJava(at: AffineTransform): JTransform = at.toJava
implicit def fromJava(j: JTransform): AffineTransform = {
import j._
AffineTransform(getScaleX, getShearY,
getShearX, getScaleY,
getTranslateX, getTranslateY)
}
val identity: AffineTransform = new JTransform()
}
final case class AffineTransform(scaleX: Double, shearY: Double,
shearX: Double, scaleY: Double,
translateX: Double, translateY: Double) {
def toJava: JTransform = new JTransform(scaleX, shearY,
shearX, scaleY,
translateX, translateY)
override def toString = "AffineTransform[[" +
scaleX + ", " + shearX + ", " + translateX + "], [" +
shearY + ", " + scaleY + ", " + translateY + "]]"
def scale(sx: Double, sy: Double): AffineTransform = {
val j = toJava; j.scale(sx, sy); j
}
// ... etc
}
測試:
AffineTransform.identity.scale(0.5, 1.0)
我建議包AWT的的AffineTransform。這肯定比自己的時間少得多。 – Rogach