Count the Unique Rectangles! In my last challenge, you were asked to find all rectangles given a m x n grid of them. However, it turned out to be very trivial as there actually was a mathematical formula I did not even know about to solve the problem! So now, for a little bit more of a challenge, how about calculating the number of unique rectangles, i.e. find the number rectangles that are all of different dimensions?

For example, consider 4 horizontal, or y lines at [-250,-50,50,250] and 4 vertical, or x lines at [-250,-70,70,250]. Graphing these on a coordinate plane with infinite dimensions results in the following 500 x 500 pixel closed grid, in which the length of each segment in pixels and the lines corresponding to their respected values from the arrays are shown:



which contains the 16 unique rectangles shown in this animated GIF:



However, if the topmost line (y = 250) were to be removed, there would only be 12 unique rectangles, as the top 3 rectangles would be factored out since they each won't be fully closed without the y = 250 line.

Task

So, as shown above, the task is counting the number of rectangles rectangles with different dimensions. In other words, given an input of 2 arrays, with the first one containing all equations of all x lines, and the latter containing those of all y lines, output the total number of rectangles of different dimensions created when the lines corresponding to those equations are graphed on a coordinate plane.

Rules


The use of any built-ins that directly solve this problem is explicitly disallowed.
If either of the arrays have less than 2 elements, the output should be 0, since if there are less than 4 lines on the plane, there are no closed, 4 sided figures.
The input arrays are not guaranteed to be sorted.
You can assume that there are not any repeated values in either of the the input arrays.
A n x m rectangle is the same as a m x n rectangle. For example, a 300 x 200 rectangle is the same as a 200 x 300 one.
Standard loopholes are prohibited.


Test Cases

Given in the format Comma Separated Arrays Input -&gt; Integer output:

[],[] -&gt; 0
[-250,-50,50,250],[-250,-70,70,250] -&gt; 16 (Visualized above)
[-250,-50,50,250],[-250,-70,70] -&gt; 12
[-40, 40],[-80, 50] -&gt; 1
[10],[10] -&gt; 0
[60, -210, -60, 180, 400, -400], [250, -150] -&gt; 12
[0,300,500],[0,300,500] -&gt; 6
[0,81,90],[0,90,100] -&gt; 9


Remember, this is code-golf, so shortest code wins!
JavaScript (ES6), 99

(X,Y,Z=new Set)=&gt;X.map(v=&gt;X.map(t=&gt;t&gt;v&amp;&amp;Y.map(w=&gt;Y.map(u=&gt;u&gt;w&amp;&amp;Z.add([u-w,t-v].sort()+0)))))|Z.size

Note: sort is not numeric but lexicographic, but in this specific case I don't care
Less golfed
(X, Y, Z = new Set) =&gt;
  X.map(
    v =&gt; X.map(
      t =&gt; t&gt;v &amp;&amp; Y.map(
        w =&gt; Y.map(
          u =&gt; u&gt;w &amp;&amp; Z.add([u-w, t-v].sort() + 0)
        )
      )
    )
  ) | Z.size

Test


F=(X,Y,Z=new Set)=&gt;X.map(v=&gt;X.map(t=&gt;t&gt;v&amp;&amp;Y.map(w=&gt;Y.map(u=&gt;u&gt;w&amp;&amp;Z.add([u-w,t-v].sort()+0)))))|Z.size
  
;[
 [[],[], 0]
,[[-250,-50,50,250],[-250,-70,70,250], 16]
,[[-250,-50,50,250],[-250,-70,70], 12]
,[[-40, 40],[-80, 50], 1]
,[[10],[10], 0]
,[[60, -210, -60, 180, 400, -400], [250, -150], 12]
,[[0,300,500],[0,300,500], 6]
].forEach(t=&gt;{
  var a=t[0],b=t[1],k=t[2],r=F(a,b)
  
  console.log(r==k?'OK':'KO','['+a+']','['+b+']',r)
})