module Webglimpse { export class BoundsUnmodifiable { private bounds : Bounds ; constructor ( bounds ) { this . bounds = bounds ; } get iStart ( ) : number { return this . bounds . iStart ; } get jStart ( ) : number { return this . bounds . jStart ; } get iEnd ( ) : number { return this . bounds . iEnd ; } get jEnd ( ) : number { return this . bounds . jEnd ; } get i ( ) : number { return this . bounds . i ; } get j ( ) : number { return this . bounds . j ; } get w ( ) : number { return this . bounds . w ; } get h ( ) : number { return this . bounds . h ; } xFrac ( i ) { return this . bounds . xFrac ( i ) ; } yFrac ( j ) { return this . bounds . yFrac ( j ) ; } contains ( i , j ) { return this . bounds . contains ( i , j ) ; } } export class Bounds { private _iStart : number ; private _jStart : number ; private _iEnd : number ; private _jEnd : number ; private _unmod : BoundsUnmodifiable ; constructor ( ) { this . _iStart = 0 ; this . _jStart = 0 ; this . _iEnd = 0 ; this . _jEnd = 0 ; this . _unmod = new BoundsUnmodifiable ( this ) ; } get iStart ( ) : number { return this . _iStart ; } get jStart ( ) : number { return this . _jStart ; } get iEnd ( ) : number { return this . _iEnd ; } get jEnd ( ) : number { return this . _jEnd ; } get i ( ) : number { return this . _iStart ; } get j ( ) : number { return this . _jStart ; } get w ( ) : number { return this . _iEnd - this . _iStart ; } get h ( ) : number { return this . _jEnd - this . _jStart ; } get unmod ( ) : BoundsUnmodifiable { return this . _unmod ; } xFrac ( i ) { return ( i - this . _iStart ) / ( this . _iEnd - this . _iStart ) ; } yFrac ( j ) { return ( j - this . _jStart ) / ( this . _jEnd - this . _jStart ) ; } contains ( i , j ) { return ( this . _iStart <= i && i < this . _iEnd && this . _jStart <= j && j < this . _jEnd ) ; } setEdges ( iStart , iEnd , jStart , jEnd ) { this . _iStart = iStart ; this . _jStart = jStart ; this . _iEnd = iEnd ; this . _jEnd = jEnd ; } setRect ( i , j , w , h ) { this . setEdges ( i , i + w , j , j + h ) ; } setBounds ( bounds ) { this . setEdges ( bounds . iStart , bounds . iEnd , bounds . jStart , bounds . jEnd ) ; } cropToEdges ( iCropStart , iCropEnd , jCropStart , jCropEnd ) { this . _iStart = clamp ( iCropStart , iCropEnd , this . _iStart ) ; this . _jStart = clamp ( jCropStart , jCropEnd , this . _jStart ) ; this . _iEnd = clamp ( iCropStart , iCropEnd , this . _iEnd ) ; this . _jEnd = clamp ( jCropStart , jCropEnd , this . _jEnd ) ; } cropToRect ( iCrop , jCrop , wCrop , hCrop ) { this . cropToEdges ( iCrop , iCrop + wCrop , jCrop , jCrop + hCrop ) ; } cropToBounds ( cropBounds ) { this . cropToEdges ( cropBounds . iStart , cropBounds . iEnd , cropBounds . jStart , cropBounds . jEnd ) ; } } export function newBoundsFromRect ( i , j , w , h ) { var b = new Bounds ( ) ; b . setRect ( i , j , w , h ) ; return b ; } export function newBoundsFromEdges ( iStart , iEnd , jStart , jEnd ) { var b = new Bounds ( ) ; b . setEdges ( iStart , iEnd , jStart , jEnd ) ; return b ; } export interface Size { w : number ; h : number ; } }