import { Fraction } from "./Fraction" ; import { Couple } from "./Couple" ; import { Vector } from "./Vector" ; import type { Sign } from "./types" ; import type { Rational } from "./Fraction" ; /**
 *  IPoint 介面是抽象化的二維點，不包含任何內部實作。
  export interface IPoint { x : number ; y : number ; } /**
 *  Point 代表的是平面幾何上的一個點。
  export class Point extends Couple implements IPoint { /** 傳回一個原點的新實體 */ public static get ZERO ( ) : Point { return new Point ( 0 , 0 ) ; } /**Create a  Point object  constructor ( ) ; constructor ( c ) ; constructor ( p ) ; constructor ( x , y ) ; constructor ( ... p ) { if ( p . length == 1 ) super ( p [ 0 ] . x , p [ 0 ] . y ) ; else super ( ... p ) ; } /** Distance to another  Point public $dist ( p ) { return this . sub ( p ) . $length ; } public sub ( v ) ; public sub ( p ) ; public sub ( c ) { if ( c instanceof Vector ) return new Point ( this . _x . sub ( c . _x ) , this . _y . sub ( c . _y ) ) ; else if ( c instanceof Point ) return new Vector ( this . _x . sub ( c . _x ) , this . _y . sub ( c . _y ) ) ; else return new Vector ( this . _x . sub ( new Fraction ( c . x ) ) , this . _y . sub ( new Fraction ( c . y ) ) ) ; } public subBy ( v ) { this . _x . s ( v . _x ) ; this . _y . s ( v . _y ) ; return this ; } public $toPaper ( ) { return new paper . Point ( this . x , this . y ) ; } /**  Point 類別的比較允許跟  IPoint 進行  public eq ( p ) ; public eq ( p ? ) ; public eq ( p ? ) { if ( p instanceof Point || ! p ) return super . eq ( p ) ; return this . x == p . x && this . y == p . y ; } public get $isIntegral ( ) : boolean { return this . _x . isIntegral && this . _y . isIntegral ; } /** 根據指定的相位進行變換 */ public $transform ( fx , fy ) { return new Point ( this . _x . fac ( fx ) , this . _y . fac ( fy ) ) ; } }