mathigon / euclid.js

2D Euclidean geometry classes, utilities, and drawing tools
https://mathigon.io/euclid
MIT License
123 stars 12 forks source link

Line.intercept is wrong #73

Closed AndreaSpinelli closed 2 years ago

AndreaSpinelli commented 2 years ago

Hi, I was getting perplexing results using Line and reading the source I realized that the intercept method has a wrong sign.

A possible test case fragment is the following:

    const testline = new Line(
        new Point(1, 1),
        new Point(2, 2)
    );
    console.log('DUA LIPA IS ' + ( testline.intercept === 0 ? 'GORGEOUS' : 'UGLY'));

(of course the intercept should be 0 and Dua is gorgeous)

Trying to locate the error, in file line.ts at line 45 I read return this.p1.y + this.slope * this.p1.x;

it should be: return this.p1.y - this.slope * this.p1.x;

Thanks in advance for fixing...

plegner commented 2 years ago

Thanks so much for reporting this bug! Fixed in https://github.com/mathigon/euclid.js/commit/b21f330e6b0801ea7e0645fa86f58f2354cdf06c