format
This commit is contained in:
@@ -8,32 +8,32 @@ abstract Canvas(Array<Array<Pixel>>) to Array<Array<Pixel>> {
|
||||
this = [[]];
|
||||
}
|
||||
|
||||
public inline function set(i:Vec2<Int>,pixel:Pixel) {
|
||||
if (this[i.y] == null){
|
||||
public inline function set(i:Vec2<Int>, pixel:Pixel) {
|
||||
if (this[i.y] == null) {
|
||||
this[i.y] = [];
|
||||
}
|
||||
|
||||
this[i.y][i.x] = pixel;
|
||||
}
|
||||
|
||||
public inline function get(i:Vec2<Int>): Pixel {
|
||||
public inline function get(i:Vec2<Int>):Pixel {
|
||||
return this[i.y][i.x];
|
||||
}
|
||||
|
||||
public function keyValueIterator(): KeyValueIterator<Vec2<Int>,Pixel>{
|
||||
public function keyValueIterator():KeyValueIterator<Vec2<Int>, Pixel> {
|
||||
return new CanvasKeyValueIterator(this);
|
||||
}
|
||||
|
||||
public function combine(other: Canvas,offset: Vec2<Int>) {
|
||||
public function combine(other:Canvas, offset:Vec2<Int>) {
|
||||
for (key => value in other) {
|
||||
if (value == null){
|
||||
if (value == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
var y = offset.y + key.y;
|
||||
var x = offset.x + key.x;
|
||||
|
||||
if (this[y] == null){
|
||||
|
||||
if (this[y] == null) {
|
||||
this[y] = [];
|
||||
}
|
||||
|
||||
@@ -41,14 +41,14 @@ abstract Canvas(Array<Array<Pixel>>) to Array<Array<Pixel>> {
|
||||
}
|
||||
}
|
||||
|
||||
public function hight(): Int {
|
||||
public function hight():Int {
|
||||
return this.length;
|
||||
}
|
||||
|
||||
public function maxWidth() {
|
||||
var max = 0;
|
||||
for (i in 0...this.length){
|
||||
if (this[i].length > max){
|
||||
for (i in 0...this.length) {
|
||||
if (this[i].length > max) {
|
||||
max = this[i].length;
|
||||
}
|
||||
}
|
||||
@@ -57,28 +57,28 @@ abstract Canvas(Array<Array<Pixel>>) to Array<Array<Pixel>> {
|
||||
}
|
||||
}
|
||||
|
||||
class CanvasKeyValueIterator{
|
||||
class CanvasKeyValueIterator {
|
||||
private final canvas:Array<Array<Pixel>>;
|
||||
private var index:Vec2<Int> = {x: 0,y: 0};
|
||||
private var index:Vec2<Int> = {x: 0, y: 0};
|
||||
|
||||
@:allow(lib.ui.Canvas)
|
||||
private function new(canvas: Array<Array<Pixel>>) {
|
||||
private function new(canvas:Array<Array<Pixel>>) {
|
||||
this.canvas = canvas;
|
||||
}
|
||||
|
||||
public function hasNext():Bool{
|
||||
public function hasNext():Bool {
|
||||
return index.y < canvas.length && index.x <= canvas[index.y].length;
|
||||
}
|
||||
|
||||
public function next():{key:Vec2<Int>, value:Pixel}{
|
||||
var oldIndex: Vec2<Int> = this.index;
|
||||
public function next():{key:Vec2<Int>, value:Pixel} {
|
||||
var oldIndex:Vec2<Int> = this.index;
|
||||
|
||||
if (index.x >= canvas[index.y].length){
|
||||
if (index.x >= canvas[index.y].length) {
|
||||
// Goto next line
|
||||
index = {x:0,y: index.y + 1};
|
||||
}else{
|
||||
index = {x: 0, y: index.y + 1};
|
||||
} else {
|
||||
// Goto next pixel in line
|
||||
index = {x:index.x + 1,y: index.y};
|
||||
index = {x: index.x + 1, y: index.y};
|
||||
}
|
||||
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user