Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore(TS): migrate Intersection #8121

Merged
merged 27 commits into from Aug 30, 2022
Merged

Chore(TS): migrate Intersection #8121

merged 27 commits into from Aug 30, 2022

Conversation

ShaMan123
Copy link
Contributor

@ShaMan123 ShaMan123 commented Aug 4, 2022

first merge #8120 and update from master

code remarks:
Should we create classes instead of the static methods?
new LinePolygonIntersection(...args).status

Changes

  • fixes coincident logic
  • exposed line and segment (line is infinite) - BREAKING, older versions should rename Line to Segment (what was named Line was a finite line which is now called a segment)

??

Is segment the best naming? Interval seems to be the correct math naming...

@github-actions
Copy link
Contributor

github-actions bot commented Aug 4, 2022

Code Coverage Summary

> fabric@5.1.0 coverage:report
> nyc report --reporter=lcov --reporter=text

-----------|---------|----------|---------|---------|-----------------------------------------------
File       | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s                             
-----------|---------|----------|---------|---------|-----------------------------------------------
All files  |   82.11 |    74.56 |   84.37 |   80.68 |                                               
 fabric.js |   82.11 |    74.56 |   84.37 |   80.68 | ...,27450,27460-27504,27612,27699,27903,28044 
-----------|---------|----------|---------|---------|-----------------------------------------------

@ShaMan123 ShaMan123 requested a review from asturur August 4, 2022 15:06
@github-actions
Copy link
Contributor

github-actions bot commented Aug 4, 2022

Code Coverage Summary

> fabric@5.1.0 coverage:report
> nyc report --reporter=lcov --reporter=text

-----------|---------|----------|---------|---------|-----------------------------------------------
File       | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s                             
-----------|---------|----------|---------|---------|-----------------------------------------------
All files  |    82.1 |    74.53 |   84.37 |   80.67 |                                               
 fabric.js |    82.1 |    74.53 |   84.37 |   80.67 | ...,27451,27461-27505,27613,27700,27904,28045 
-----------|---------|----------|---------|---------|-----------------------------------------------

@github-actions
Copy link
Contributor

github-actions bot commented Aug 5, 2022

Code Coverage Summary

> fabric@5.1.0 coverage:report
> nyc report --reporter=lcov --reporter=text

-----------|---------|----------|---------|---------|-----------------------------------------------
File       | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s                             
-----------|---------|----------|---------|---------|-----------------------------------------------
All files  |   82.09 |    74.49 |   84.47 |   80.66 |                                               
 fabric.js |   82.09 |    74.49 |   84.47 |   80.66 | ...,27475,27485-27529,27637,27724,27928,28069 
-----------|---------|----------|---------|---------|-----------------------------------------------

@github-actions
Copy link
Contributor

github-actions bot commented Aug 5, 2022

Code Coverage Summary

> fabric@5.1.0 coverage:report
> nyc report --reporter=lcov --reporter=text

-----------|---------|----------|---------|---------|-----------------------------------------------
File       | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s                             
-----------|---------|----------|---------|---------|-----------------------------------------------
All files  |   82.13 |    74.58 |   84.49 |    80.7 |                                               
 fabric.js |   82.13 |    74.58 |   84.49 |    80.7 | ...,27503,27513-27557,27665,27752,27956,28097 
-----------|---------|----------|---------|---------|-----------------------------------------------

@github-actions
Copy link
Contributor

github-actions bot commented Aug 5, 2022

Code Coverage Summary

> fabric@5.1.0 coverage:report
> nyc report --reporter=lcov --reporter=text

-----------|---------|----------|---------|---------|-----------------------------------------------
File       | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s                             
-----------|---------|----------|---------|---------|-----------------------------------------------
All files  |   82.17 |    74.58 |    84.5 |   80.76 |                                               
 fabric.js |   82.17 |    74.58 |    84.5 |   80.76 | ...,27518,27528-27572,27680,27767,27971,28112 
-----------|---------|----------|---------|---------|-----------------------------------------------

@github-actions
Copy link
Contributor

github-actions bot commented Aug 5, 2022

Code Coverage Summary

> fabric@5.1.0 coverage:report
> nyc report --reporter=lcov --reporter=text

-----------|---------|----------|---------|---------|-----------------------------------------------
File       | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s                             
-----------|---------|----------|---------|---------|-----------------------------------------------
All files  |   82.17 |    74.58 |    84.5 |   80.76 |                                               
 fabric.js |   82.17 |    74.58 |    84.5 |   80.76 | ...,27517,27527-27571,27679,27766,27970,28111 
-----------|---------|----------|---------|---------|-----------------------------------------------

@github-actions
Copy link
Contributor

github-actions bot commented Aug 5, 2022

Code Coverage Summary

> fabric@5.1.0 coverage:report
> nyc report --reporter=lcov --reporter=text

-----------|---------|----------|---------|---------|-----------------------------------------------
File       | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s                             
-----------|---------|----------|---------|---------|-----------------------------------------------
All files  |   82.13 |    74.64 |   84.53 |   80.72 |                                               
 fabric.js |   82.13 |    74.64 |   84.53 |   80.72 | ...,27543,27553-27597,27705,27792,27996,28137 
-----------|---------|----------|---------|---------|-----------------------------------------------

@github-actions
Copy link
Contributor

github-actions bot commented Aug 5, 2022

Code Coverage Summary

> fabric@5.1.0 coverage:report
> nyc report --reporter=lcov --reporter=text

-----------|---------|----------|---------|---------|-----------------------------------------------
File       | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s                             
-----------|---------|----------|---------|---------|-----------------------------------------------
All files  |   82.13 |    74.62 |   84.55 |   80.71 |                                               
 fabric.js |   82.13 |    74.62 |   84.55 |   80.71 | ...,27546,27556-27600,27708,27795,27999,28140 
-----------|---------|----------|---------|---------|-----------------------------------------------

@github-actions
Copy link
Contributor

github-actions bot commented Aug 5, 2022

Code Coverage Summary

> fabric@5.1.0 coverage:report
> nyc report --reporter=lcov --reporter=text

-----------|---------|----------|---------|---------|-----------------------------------------------
File       | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s                             
-----------|---------|----------|---------|---------|-----------------------------------------------
All files  |   82.12 |    74.62 |   84.48 |   80.72 |                                               
 fabric.js |   82.12 |    74.62 |   84.48 |   80.72 | ...,27542,27552-27596,27704,27791,27995,28136 
-----------|---------|----------|---------|---------|-----------------------------------------------

@github-actions
Copy link
Contributor

github-actions bot commented Aug 5, 2022

Code Coverage Summary

> fabric@5.1.0 coverage:report
> nyc report --reporter=lcov --reporter=text

-----------|---------|----------|---------|---------|-----------------------------------------------
File       | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s                             
-----------|---------|----------|---------|---------|-----------------------------------------------
All files  |   82.18 |    74.65 |   84.54 |   80.78 |                                               
 fabric.js |   82.18 |    74.65 |   84.54 |   80.78 | ...,27545,27555-27599,27707,27794,27998,28139 
-----------|---------|----------|---------|---------|-----------------------------------------------

@github-actions
Copy link
Contributor

github-actions bot commented Aug 5, 2022

Code Coverage Summary

> fabric@5.1.0 coverage:report
> nyc report --reporter=lcov --reporter=text

-----------|---------|----------|---------|---------|-----------------------------------------------
File       | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s                             
-----------|---------|----------|---------|---------|-----------------------------------------------
All files  |   82.13 |    74.62 |   84.54 |   80.72 |                                               
 fabric.js |   82.13 |    74.62 |   84.54 |   80.72 | ...,27551,27561-27605,27713,27800,28004,28145 
-----------|---------|----------|---------|---------|-----------------------------------------------

Copy link
Contributor Author

@ShaMan123 ShaMan123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK
This demanded much more work than I thought

Fixed 2 bugs regarding coincident

READY

I am very happy about this

* @param B
* @returns true if `T` is contained
*/
const isContainedInInterval = (T: Point, A: Point, B: Point) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am afraid future misuse of the method because it is meant to be used in a very specific context as mentioned in the comment

Any suggestions?

* @chainable
*/
appendPoint(point) {
if (!this.contains(point)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

append only unique points

*/
appendPoints(points) {
this.points = this.points.concat(points.filter(point => {
return !this.contains(point);
Copy link
Contributor Author

@ShaMan123 ShaMan123 Aug 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

append only unique points

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this hot code? why does it matters? If this is used during render i don't really want to do it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hot code? What's that?

Copy link
Contributor Author

@ShaMan123 ShaMan123 Aug 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How damaging is this loop?
we can make it a map instead (I think it is insignificant)
consider that most case points intersection is <=2

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only 2 polygons that are almost identical will have <= n-1

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hot code? What's that?

ahh code used by the dev?
yes, getting intersection points in crucial for ui displaying these points

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with hot code i mean code we use in tight loops during rendering. Goint to check how many intersections we use

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok is fine, the Intersection is just a fancy container for points, the math to find the point didn't change. I'm good with this.

uaT = (b2.x - b1.x) * (a1.y - b1.y) - (b2.y - b1.y) * (a1.x - b1.x),
ubT = (a2.x - a1.x) * (a1.y - b1.y) - (a2.y - a1.y) * (a1.x - b1.x),
uB = (b2.y - b1.y) * (a2.x - a1.x) - (b2.x - b1.x) * (a2.y - a1.y);
static intersectLineLine(a1, a2, b1, b2, aIinfinite = true, bIinfinite = true) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added option for infinite line check

let result;
const uaT = (b2.x - b1.x) * (a1.y - b1.y) - (b2.y - b1.y) * (a1.x - b1.x),
ubT = (a2.x - a1.x) * (a1.y - b1.y) - (a2.y - a1.y) * (a1.x - b1.x),
uB = (b2.y - b1.y) * (a2.x - a1.x) - (b2.x - b1.x) * (a2.y - a1.y);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

who ever wrote this knows their algerba
I can't understand it exactly, just the main concept

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some matrix det/cross clever calculation
well done who ever you are

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some of those can be probably grouped in smaller const, i m not sure the extra const are worth the subtraction saved.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought of it too.
Wasn't sure how to name what...

const segmentsCoincide = aIinfinite || bIinfinite
|| isContainedInInterval(a1, b1, b2) || isContainedInInterval(a2, b1, b2)
|| isContainedInInterval(b1, a1, a2) || isContainedInInterval(b2, a1, a2);
result = new Intersection(segmentsCoincide ? 'Coincident' : undefined);
Copy link
Contributor Author

@ShaMan123 ShaMan123 Aug 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If segments intersection => check that coincident happens in range
fixed!


inter = Intersection.intersectLineLine(a1, a2, b1, b2, infinite, false);
if (inter.status === 'Coincident') {
return inter;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed detection coincident (someone left a note about it)


result.appendPoints(inter.points);
if (coincidents.length > 0 && coincidents.length === points1.length && coincidents.length === points2.length) {
return new Intersection('Coincident');
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same fix of TODO comment

* @return {Intersection} thisArg
* @chainable
*/
private append(...points) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

refactored appendPoint appendPoints to append es6!
I don't consider it breaking as this method is private

@github-actions
Copy link
Contributor

github-actions bot commented Aug 5, 2022

Code Coverage Summary

> fabric@5.1.0 coverage:report
> nyc report --reporter=lcov --reporter=text

-----------|---------|----------|---------|---------|-----------------------------------------------
File       | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s                             
-----------|---------|----------|---------|---------|-----------------------------------------------
All files  |   82.12 |    74.59 |   84.53 |    80.7 |                                               
 fabric.js |   82.12 |    74.59 |   84.53 |    80.7 | ...,27539,27549-27593,27701,27788,27992,28133 
-----------|---------|----------|---------|---------|-----------------------------------------------

case when polygons are the same, one has more points
@github-actions
Copy link
Contributor

github-actions bot commented Aug 8, 2022

Code Coverage Summary

> fabric@5.1.0 coverage:report
> nyc report --reporter=lcov --reporter=text

-----------|---------|----------|---------|---------|-----------------------------------------------
File       | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s                             
-----------|---------|----------|---------|---------|-----------------------------------------------
All files  |   82.08 |    74.62 |   84.54 |   80.67 |                                               
 fabric.js |   82.08 |    74.62 |   84.54 |   80.67 | ...,27572,27582-27626,27734,27821,28025,28166 
-----------|---------|----------|---------|---------|-----------------------------------------------

@github-actions
Copy link
Contributor

github-actions bot commented Aug 8, 2022

Code Coverage Summary

> fabric@5.1.0 coverage:report
> nyc report --reporter=lcov --reporter=text

-----------|---------|----------|---------|---------|-----------------------------------------------
File       | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s                             
-----------|---------|----------|---------|---------|-----------------------------------------------
All files  |   82.08 |    74.62 |   84.54 |   80.67 |                                               
 fabric.js |   82.08 |    74.62 |   84.54 |   80.67 | ...,27572,27582-27626,27734,27821,28025,28166 
-----------|---------|----------|---------|---------|-----------------------------------------------

@github-actions
Copy link
Contributor

github-actions bot commented Aug 17, 2022

Code Coverage Summary

> fabric@5.1.0 coverage:report
> nyc report --reporter=lcov --reporter=text

-----------|---------|----------|---------|---------|-----------------------------------------------
File       | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s                             
-----------|---------|----------|---------|---------|-----------------------------------------------
All files  |   82.05 |    74.62 |   84.45 |   80.64 |                                               
 fabric.js |   82.05 |    74.62 |   84.45 |   80.64 | ...,27521,27579,27589-27633,27741,27828,28032 
-----------|---------|----------|---------|---------|-----------------------------------------------

Copy link
Contributor Author

@ShaMan123 ShaMan123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reviewed again and fixed some more stuff

READY set go

@@ -124,10 +124,14 @@ export class Intersection {

/**
* Checks if line intersects polygon
*
* @todo account for stroke
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@github-actions
Copy link
Contributor

github-actions bot commented Aug 17, 2022

Code Coverage Summary

> fabric@5.1.0 coverage:report
> nyc report --reporter=lcov --reporter=text

-----------|---------|----------|---------|---------|-----------------------------------------------
File       | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s                             
-----------|---------|----------|---------|---------|-----------------------------------------------
All files  |   82.06 |    74.65 |   84.45 |   80.65 |                                               
 fabric.js |   82.06 |    74.65 |   84.45 |   80.65 | ...,27518,27576,27586-27630,27738,27825,28029 
-----------|---------|----------|---------|---------|-----------------------------------------------

@github-actions
Copy link
Contributor

github-actions bot commented Aug 17, 2022

Code Coverage Summary

> fabric@5.1.0 coverage:report
> nyc report --reporter=lcov --reporter=text

-----------|---------|----------|---------|---------|-----------------------------------------------
File       | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s                             
-----------|---------|----------|---------|---------|-----------------------------------------------
All files  |   82.05 |    74.62 |   84.45 |   80.64 |                                               
 fabric.js |   82.05 |    74.62 |   84.45 |   80.64 | ...,27518,27576,27586-27630,27738,27825,28029 
-----------|---------|----------|---------|---------|-----------------------------------------------

@github-actions
Copy link
Contributor

github-actions bot commented Aug 24, 2022

Code Coverage Summary

> fabric@5.1.0 coverage:report
> nyc report --reporter=lcov --reporter=text

-----------|---------|----------|---------|---------|-----------------------------------------------
File       | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s                             
-----------|---------|----------|---------|---------|-----------------------------------------------
All files  |   82.08 |    74.63 |   84.46 |   80.68 |                                               
 fabric.js |   82.08 |    74.63 |   84.46 |   80.68 | ...,27523,27581,27591-27635,27743,27830,28034 
-----------|---------|----------|---------|---------|-----------------------------------------------

@github-actions
Copy link
Contributor

github-actions bot commented Aug 25, 2022

Code Coverage Summary

> fabric@5.1.0 coverage:report
> nyc report --reporter=lcov --reporter=text

-----------|---------|----------|---------|---------|-----------------------------------------------
File       | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s                             
-----------|---------|----------|---------|---------|-----------------------------------------------
All files  |    82.1 |    74.67 |   84.51 |   80.71 |                                               
 fabric.js |    82.1 |    74.67 |   84.51 |   80.71 | ...,27520,27578,27588-27632,27740,27827,28031 
-----------|---------|----------|---------|---------|-----------------------------------------------

@github-actions
Copy link
Contributor

github-actions bot commented Aug 26, 2022

Code Coverage Summary

> fabric@5.1.0 coverage:report
> nyc report --reporter=lcov --reporter=text

-----------|---------|----------|---------|---------|-----------------------------------------------
File       | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s                             
-----------|---------|----------|---------|---------|-----------------------------------------------
All files  |   82.14 |    74.75 |    84.4 |   80.76 |                                               
 fabric.js |   82.14 |    74.75 |    84.4 |   80.76 | ...-27740,27856-27857,27878-27919,27934-28093 
-----------|---------|----------|---------|---------|-----------------------------------------------

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants