查找 2 个数字范围重叠的节点

Find nodes where 2 number ranges overlap

我的节点具有以下属性

(n:User {valUpper:100, valLower:-100}) 
(m:User {valUpper:200, valLower: 0})

使用密码是否可以找到 (m) 的范围是否与 (n) 重叠?

这就是我在 js 中所做的..

if max(x2, y2) - min(x1, y1) < (x2 - x1) + (y2 - y1) {
     //Ranges Overlap
}

使用您 javascript 示例中的公式,您可以这样做

... here you match for n and m ...
WITH n.valUpper as x1, n.valLower as y1, m.valUpper as x2, m.valLower as y2
RETURN apoc.coll.max([x2, y2]) - apoc.coll.min([x1, y1]) < (x2 - x1) + (y2 - y1)

希望对您有所帮助。

此致, 汤姆

Apoc 是非常值得的选择。只想为不想启用 apoc 的人提及非 apoc 方式。

WITH n.valUpper as x1, n.valLower as y1, m.valUpper as x2, m.valLower as y2
RETURN 
  CASE WHEN x2 > y2 THEN x2 ELSE y2 END - 
  CASE WHEN x1 < y1 THEN x1 ELSE y1 END 
  < (x2 - x1) + (y2 - y1)