MCPcopy Index your code
hub / github.com/plotly/plotly.js / cutEdges

Function cutEdges

stackgl_modules/index.js:8965–9056  ·  view source on GitHub ↗
(floatPoints, edges, crossings, junctions, useColor)

Source from the content-addressed store, hash-verified

8963
8964// Cut edges along crossings/tjunctions
8965function cutEdges (floatPoints, edges, crossings, junctions, useColor) {
8966 var i, e
8967
8968 // Convert crossings into tjunctions by constructing rational points
8969 var ratPoints = floatPoints.map(function(p) {
8970 return [
8971 rat(p[0]),
8972 rat(p[1])
8973 ]
8974 })
8975 for (i = 0; i < crossings.length; ++i) {
8976 var crossing = crossings[i]
8977 e = crossing[0]
8978 var f = crossing[1]
8979 var ee = edges[e]
8980 var ef = edges[f]
8981 var x = solveIntersection(
8982 ratVec(floatPoints[ee[0]]),
8983 ratVec(floatPoints[ee[1]]),
8984 ratVec(floatPoints[ef[0]]),
8985 ratVec(floatPoints[ef[1]]))
8986 if (!x) {
8987 // Segments are parallel, should already be handled by t-junctions
8988 continue
8989 }
8990 var idx = floatPoints.length
8991 floatPoints.push([ratToFloat(x[0]), ratToFloat(x[1])])
8992 ratPoints.push(x)
8993 junctions.push([e, idx], [f, idx])
8994 }
8995
8996 // Sort tjunctions
8997 junctions.sort(function (a, b) {
8998 if (a[0] !== b[0]) {
8999 return a[0] - b[0]
9000 }
9001 var u = ratPoints[a[1]]
9002 var v = ratPoints[b[1]]
9003 return ratCmp(u[0], v[0]) || ratCmp(u[1], v[1])
9004 })
9005
9006 // Split edges along junctions
9007 for (i = junctions.length - 1; i >= 0; --i) {
9008 var junction = junctions[i]
9009 e = junction[0]
9010
9011 var edge = edges[e]
9012 var s = edge[0]
9013 var t = edge[1]
9014
9015 // Check if edge is not lexicographically sorted
9016 var a = floatPoints[s]
9017 var b = floatPoints[t]
9018 if (((a[0] - b[0]) || (a[1] - b[1])) < 0) {
9019 var tmp = s
9020 s = t
9021 t = tmp
9022 }

Callers 1

snapRoundFunction · 0.85

Calls 1

solveIntersectionFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…