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
Conversation
Code Coverage Summary
|
Code Coverage Summary
|
Code Coverage Summary
|
Code Coverage Summary
|
Code Coverage Summary
|
Code Coverage Summary
|
Code Coverage Summary
|
Code Coverage Summary
|
Code Coverage Summary
|
Code Coverage Summary
|
Code Coverage Summary
|
There was a problem hiding this 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) => { |
There was a problem hiding this comment.
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?
src/intersection.class.ts
Outdated
* @chainable | ||
*/ | ||
appendPoint(point) { | ||
if (!this.contains(point)) { |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
append only unique points
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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'); |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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
Code Coverage Summary
|
case when polygons are the same, one has more points
Code Coverage Summary
|
Code Coverage Summary
|
Code Coverage Summary
|
There was a problem hiding this 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Coverage Summary
|
Code Coverage Summary
|
Code Coverage Summary
|
Code Coverage Summary
|
Code Coverage Summary
|
first merge #8120 and update from mastercode remarks:
Should we create classes instead of the static methods?
new LinePolygonIntersection(...args).status
Changes
line
andsegment
(line
is infinite) - BREAKING, older versions should renameLine
toSegment
(what was namedLine
was a finite line which is now called a segment)??
Is
segment
the best naming? Interval seems to be the correct math naming...