-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Contour line labels #1815
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
Contour line labels #1815
Changes from 1 commit
468ef5d
88cc33c
ee7a839
b56f4ea
d534fb2
d1e3448
b8c75c0
2f3a712
6299303
99f39f8
d518c83
27f8cfe
221b124
ca1cced
d52cfba
0f37648
62156dd
539ca22
2116a12
e1880c1
14c832e
1bbdf59
e5a2f91
cbdf795
4db549c
fb4b690
b0f9bb2
e1caa9e
0ff2dc4
f5873f1
b5a674f
1f85a6f
6c2043e
bbb9574
9495dee
7f086e0
49b8141
8934038
dbeecd0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -487,15 +487,15 @@ function drawRaw(gd, options, index, subplotId, xa, ya) { | |
// to get the parity of the number of intersections. | ||
if(edges.reduce(function(a, x) { | ||
return a ^ | ||
!!lineIntersect(headX, headY, headX + 1e6, headY + 1e6, | ||
!!Lib.segmentsIntersect(headX, headY, headX + 1e6, headY + 1e6, | ||
x[0], x[1], x[2], x[3]); | ||
}, false)) { | ||
// no line or arrow - so quit drawArrow now | ||
return; | ||
} | ||
|
||
edges.forEach(function(x) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is |
||
var p = lineIntersect(tailX, tailY, headX, headY, | ||
var p = Lib.segmentsIntersect(tailX, tailY, headX, headY, | ||
x[0], x[1], x[2], x[3]); | ||
if(p) { | ||
tailX = p.x; | ||
|
@@ -701,24 +701,3 @@ function drawRaw(gd, options, index, subplotId, xa, ya) { | |
} | ||
else annText.call(textLayout); | ||
} | ||
|
||
// look for intersection of two line segments | ||
// (1->2 and 3->4) - returns array [x,y] if they do, null if not | ||
function lineIntersect(x1, y1, x2, y2, x3, y3, x4, y4) { | ||
var a = x2 - x1, | ||
b = x3 - x1, | ||
c = x4 - x3, | ||
d = y2 - y1, | ||
e = y3 - y1, | ||
f = y4 - y3, | ||
det = a * f - c * d; | ||
// parallel lines? intersection is undefined | ||
// ignore the case where they are colinear | ||
if(det === 0) return null; | ||
var t = (b * f - c * e) / det, | ||
u = (b * d - a * e) / det; | ||
// segments do not intersect? | ||
if(u < 0 || u > 1 || t < 0 || t > 1) return null; | ||
|
||
return {x: x1 + a * t, y: y1 + d * t}; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/** | ||
* Copyright 2012-2017, Plotly, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
/* | ||
* look for intersection of two line segments | ||
* (1->2 and 3->4) - returns array [x,y] if they do, null if not | ||
*/ | ||
exports.segmentsIntersect = function segmentsIntersect(x1, y1, x2, y2, x3, y3, x4, y4) { | ||
var a = x2 - x1, | ||
b = x3 - x1, | ||
c = x4 - x3, | ||
d = y2 - y1, | ||
e = y3 - y1, | ||
f = y4 - y3, | ||
det = a * f - c * d; | ||
// parallel lines? intersection is undefined | ||
// ignore the case where they are colinear | ||
if(det === 0) return null; | ||
var t = (b * f - c * e) / det, | ||
u = (b * d - a * e) / det; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I were really going to nitpick, I'd suggest comparing bounding boxes first and here multiplying through by |
||
// segments do not intersect? | ||
if(u < 0 || u > 1 || t < 0 || t > 1) return null; | ||
|
||
return {x: x1 + a * t, y: y1 + d * t}; | ||
}; |
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.
Not part of this PR and I'm sure no meaningful performance hit, but is
reduce
necessary here? Seems likewould be more concise and readable and would bail out early when it can.
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.
Unless that equates to an
all
condition where you actually need to check all. Not 100% sure. The^
is a bit confusing.