import { isBetween } from '@mathigon/fermat' ; import { Point } from './point' ; import { Rectangle } from './rectangle' ; export class Bounds { constructor ( public xMin , public xMax , public yMin , public yMax ) { } contains ( p ) { return this . containsX ( p ) && this . containsY ( p ) ; } containsX ( p ) { return isBetween ( p . x , this . xMin , this . xMax ) ; } containsY ( p ) { return isBetween ( p . y , this . yMin , this . yMax ) ; } resize ( dx , dy ) { return new Bounds ( this . xMin , this . xMax + dx , this . yMin , this . yMax + dy ) ; } get dx ( ) { return this . xMax - this . xMin ; } get dy ( ) { return this . yMax - this . yMin ; } get xRange ( ) : [ number , number ] { return [ this . xMin , this . xMax ] ; } get yRange ( ) : [ number , number ] { return [ this . yMin , this . yMax ] ; } get rect ( ) { return new Rectangle ( new Point ( this . xMin , this . yMin ) , this . dx , this . dy ) ; } get center ( ) { return new Point ( this . xMin + this . dx / 2 , this . yMin + this . dy / 2 ) ; } get flip ( ) { return new Bounds ( this . yMin , this . yMax , this . xMin , this . xMax ) ; } }