| 1 |
package org.sepy.geom |
|---|
| 2 |
{ |
|---|
| 3 |
public class Matrix2d extends Array2d |
|---|
| 4 |
{ |
|---|
| 5 |
private var _identity:Array; |
|---|
| 6 |
|
|---|
| 7 |
public function Matrix2d(w:uint, h:uint) |
|---|
| 8 |
{ |
|---|
| 9 |
super(w, h); |
|---|
| 10 |
|
|---|
| 11 |
_identity = null; |
|---|
| 12 |
} |
|---|
| 13 |
|
|---|
| 14 |
public function get IDENTITY():Array |
|---|
| 15 |
{ |
|---|
| 16 |
if(_identity == null) |
|---|
| 17 |
{ |
|---|
| 18 |
_identity = new Array(_w * _h); |
|---|
| 19 |
for(var y:uint = 0; y < _h; ++y) |
|---|
| 20 |
for(var x:uint = 0; x < _w; ++x) |
|---|
| 21 |
_identity[(y * _w) + x] = (x == y) ? 1 : 0; |
|---|
| 22 |
} |
|---|
| 23 |
|
|---|
| 24 |
return _identity; |
|---|
| 25 |
} |
|---|
| 26 |
|
|---|
| 27 |
protected override function setFlatData(new_data:Array, copy:Boolean=false):void |
|---|
| 28 |
{ |
|---|
| 29 |
// Fix the matrix to the given bounds |
|---|
| 30 |
if(new_data.length < length) |
|---|
| 31 |
new_data = new_data.slice(0, new_data.length).concat(IDENTITY.slice(new_data.length, length)); |
|---|
| 32 |
else if(new_data.length > length) |
|---|
| 33 |
new_data = new_data.slice(0, length); |
|---|
| 34 |
|
|---|
| 35 |
super.setFlatData(new_data, copy); |
|---|
| 36 |
} |
|---|
| 37 |
} |
|---|
| 38 |
} |
|---|