File: CLOSESTINDEX.c

package info (click to toggle)
qepcad 1.74%2Bds-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,848 kB
  • sloc: ansic: 27,242; cpp: 2,995; makefile: 1,287; perl: 91
file content (55 lines) | stat: -rw-r--r-- 1,039 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*
Closest index.

c : a ESCAD cell.
L : a list of ESCAD cells -- non-empty -- all of c's level.

cp: the ESCAD cell in L with index closest to c.

*/

#include "extlang.h"

static Word comp(Word u, Word v) __pure;

static Word comp(Word u, Word v)
{
  Word r,t,U,V,A,B,a,b;
  r = 0;
  for(t = 0, U = u, V = v; U != NIL && t == 0; U = RED(U), V = RED(V)) {
    a = FIRST(U); b = FIRST(V);
    A = absm(a);  B = absm(b);
    t = BDCOMP(A,B);
    if (!r)
      r = BDCOMP(a,b); }
  if (!t)
    t = r;
  return t;
}

Word CLOSESTINDEX(Word c, Word L)
{
  Word u,v,w,cp,q,Q;
  u = LELTI(LELTI(c,SC_REP),INDX);
  ADV(L,&cp,&Q);
  v = VECTOR_DIF(u,LELTI(LELTI(cp,SC_REP),INDX));
  while(Q != NIL) {
    ADV(Q,&q,&Q);
    w = VECTOR_DIF(u,LELTI(LELTI(q,SC_REP),INDX));
    if (comp(v,w) > 0) {
      v = w;
      cp = q; } }
  return cp;
}

Word ISCLOSEST2(Word c, Word L1, Word L2)
{
  Word c1,c2,c3;
  c1 = CLOSESTINDEX(c,L1);
  c2 = CLOSESTINDEX(c,L2);
  c3 = CLOSESTINDEX(c,LIST2(c1,c2));
  if (c3 == c1)
    return 1;
  else
    return 2;
}