Iosevka/support/transform.ptl
2016-02-04 07:32:04 +08:00

36 lines
1.0 KiB
Plaintext

import './point' as Point
export all : class Transform
public [new xx yx xy yy x y] : begin
this.xx = xx
this.yx = yx
this.xy = xy
this.yy = yy
this.x = x
this.y = y
public [inverse] : Transform.inverse this
static [Id] : new Transform 1 0 0 1 0 0
static [transformPoint tfm pt] : new Point
* pt.x * tfm.xx + pt.y * tfm.yx + tfm.x
* pt.x * tfm.xy + pt.y * tfm.yy + tfm.y
* pt.onCurve
* pt.cubic
* pt.subdivided
static [inverse tfm] : begin
local denom : tfm.xx * tfm.yy - tfm.xy * tfm.yx
return : new Transform
* tfm.yy / denom; * -tfm.yx / denom
* -tfm.xy / denom; * tfm.xx / denom
* -(tfm.x * tfm.yy - tfm.y * tfm.yx) / denom
* -(-tfm.x * tfm.xy + tfm.y * tfm.xx) / denom
static [untransform tfm pt] : begin
local xx : pt.x - tfm.x
local yy : pt.y - tfm.y
local denom : tfm.xx * tfm.yy - tfm.xy * tfm.yx
return : new Point
* (xx * tfm.yy - yy * tfm.yx) / denom
* (yy * tfm.xx - xx * tfm.xy) / denom
* pt.onCurve
* pt.cubic
* pt.subdivided