quakeforge/ruamoko/gatest/metric.r
Bill Currie 68ca8c7016 [gatest] Switch to using e0 for the null vector
According to enki (bivector community) when there are more than one null
vector in a geometry, usually all vectors are null, and it was what to
do with multiple null vectors that caused me to balk at using e0 for the
null vector. However, using e0 for the null vector makes life much
easier, especially as that's what most of the literature does. There
are plenty of places, particularly in layout handling, that still need
adjustment for the change, but things seem to work (minus duals, but
they were broken in the first place, thus the discussion with enki).
2023-06-08 12:56:23 +09:00

37 lines
633 B
R

#include "metric.h"
@implementation Metric
+(Metric *)R:(int)p, int m, int z
{
Metric *metric = [[[Metric alloc] init] autorelease];
metric.plus = ((1 << p) - 1) << z;
metric.minus = ((1 << m) - 1) << (z + p);
metric.zero = (1 << z) - 1;
return metric;
}
static double
count_minus (unsigned minus)
{
double s = 1;
while (minus) {
if (minus & 1) {
s = -s;
}
minus >>= 1;
}
return s;
}
-(double)apply:(unsigned) a, unsigned b
{
// find all the squared elements
unsigned c = a & b;
// any elements that square to 0 result in 0
if (c & zero) {
return 0;
}
return count_minus (c & minus);
}
@end