import { ReadonlyVector2 , Vector2 } from "./Vector2" ; /**
 * A line connecting two vertices.
 */ export class Line2 { private normal : Vector2 | null = null ; private center : Vector2 | null = null ; param start param end public constructor ( public start , public end ) { } return public getNormal ( ) { return ( this . normal ?? ( this . normal = new Vector2 ( ) ) ) . setComponents ( this . end . y - this . start . y , this . start . x - this . end . x ) . normalize ( ) ; } return public getCenter ( ) { return ( this . center ?? ( this . center = new Vector2 ( ) ) ) . setComponents ( ( this . start . x + this . end . x ) / 2 , ( this . start . y + this . end . y ) / 2 ) ; } param ctx public draw ( ctx ) { const { start : a , end : b } = this ; ctx . moveTo ( a . x , a . x ) ; ctx . lineTo ( b . x , a . y ) ; return this ; } param ctx param len public drawNormal ( ctx , len = 25 ) { const normal = this . getNormal ( ) ; const center = this . getCenter ( ) ; ctx . moveTo ( center . x , center . y ) ; ctx . lineTo ( center . x + normal . x * len , center . y + normal . y * len ) ; return this ; } }