Skip to content

Commit

Permalink
Slim down Affine size
Browse files Browse the repository at this point in the history
  • Loading branch information
eanders-ms committed Oct 2, 2023
1 parent 3af3a8c commit f9cd9bb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 38 deletions.
40 changes: 8 additions & 32 deletions affine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,10 @@ namespace microcode {
export class Affine {
private localPos_: Vec2
private parent_: Affine
private dirty_: boolean
private worldPos_: Vec2
public tag: string

//% blockCombine block="dirty" callInDebugger
public get dirty(): boolean {
return (
this.dirty_ ||
this.localPos_.dirty ||
(this.parent && this.parent.dirty)
)
}

//% blockCombine block="worldPos" callInDebugger
public get worldPos() {
if (this.dirty) {
this.recalc()
}
return this.worldPos_
return this.computeWorldPos()
}

//% blockCombine block="localPos" callInDebugger
Expand All @@ -37,7 +22,6 @@ namespace microcode {
}
public set localPos(v: Vec2) {
this.localPos_.copyFrom(v)
this.dirty_ = true
}

//% blockCombine block="parent" callInDebugger
Expand All @@ -46,7 +30,6 @@ namespace microcode {
}
public set parent(p: Affine) {
this.parent_ = p
this.dirty_ = true
}

//% blockCombine block="root" callInDebugger
Expand All @@ -60,8 +43,6 @@ namespace microcode {

constructor() {
this.localPos_ = new Vec2()
this.worldPos_ = new Vec2()
this.dirty_ = true
}

public copyFrom(src: Affine): this {
Expand All @@ -75,19 +56,14 @@ namespace microcode {
return aff
}

public recalc(force = false) {
if (this.dirty || force) {
this.dirty_ = false
if (this.parent) {
Vec2.TranslateToRef(
this.localPos_,
this.parent.worldPos,
this.worldPos_
)
} else {
this.worldPos_.copyFrom(this.localPos)
}
private computeWorldPos(): Vec2 {
const pos = this.localPos_
let parent = this.parent_
while (parent) {
Vec2.TranslateToRef(pos, parent.localPos, pos)
parent = parent.parent
}
return pos
}

public transformToRef(v: Vec2, ref: Vec2): Vec2 {
Expand Down
6 changes: 0 additions & 6 deletions editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,6 @@ namespace microcode {
return
}

if (target.rootXfrm.tag === "hud") {
this.moveTo(target)
return
}

const occBounds = new Bounds({
left: Screen.LEFT_EDGE,
top: Screen.TOP_EDGE + TOOLBAR_HEIGHT + TOOLBAR_MARGIN,
Expand Down Expand Up @@ -259,7 +254,6 @@ namespace microcode {
)
this.hudroot = new Placeable()
this.hudroot.xfrm.localPos = new Vec2(0, Screen.TOP_EDGE)
this.hudroot.xfrm.tag = "hud"
this.scrollroot = new Placeable()
this.scrollroot.xfrm.localPos = new Vec2(
Screen.LEFT_EDGE,
Expand Down

0 comments on commit f9cd9bb

Please sign in to comment.