[qfcc] Add a failing test case for dags

I'm not yet sure what went wrong, but the introduction of dags broke
something in my set_transform function (perhaps the dual?), but it's
something to do with the symbol being dagged (I guess because it's
required for everything else to dag). However, the strangest thing is
the error shows up with 155a8cbcda which
is before dags had any direct effect on the geometric algebra code. I
have a sneaking suspicion it's yet another convert_name issue.
This commit is contained in:
Bill Currie 2023-09-26 11:57:31 +09:00
parent 9c258b02e8
commit 198cec6df8
2 changed files with 97 additions and 0 deletions

View file

@ -51,6 +51,7 @@ test_progs_dat=\
tools/qfcc/test/ptrfunc.dat \
tools/qfcc/test/ptrstructcast.dat \
tools/qfcc/test/motor-point.dat \
tools/qfcc/test/motor-xform.dat \
tools/qfcc/test/quaternion.dat \
tools/qfcc/test/return-ivar.dat \
tools/qfcc/test/return-postop.dat \
@ -621,6 +622,16 @@ tools/qfcc/test/motor-point.run: $(qfcc_test_run_deps)
include $(motor_point_dep) # am--include-marker
r_depfiles_remade += $(motor_point_dep)
tools_qfcc_test_motor_xform_dat_SOURCES=tools/qfcc/test/motor-xform.r
motor_xform_obj=$(tools_qfcc_test_motor_xform_dat_SOURCES:.r=.o)
motor_xform_dep=$(call qcautodep,$(tools_qfcc_test_motor_xform_dat_SOURCES))
tools/qfcc/test/motor-xform.dat$(EXEEXT): $(motor_xform_obj) $(QFCC_DEP)
$(V_QFCCLD)$(QLINK) -o $@ $(motor_xform_obj)
tools/qfcc/test/motor-xform.run: $(qfcc_test_run_deps)
@$(top_srcdir)/tools/qfcc/test/build-run $@
include $(motor_xform_dep) # am--include-marker
r_depfiles_remade += $(motor_xform_dep)
tools_qfcc_test_quaternion_dat_SOURCES=tools/qfcc/test/quaternion.r
quaternion_obj=$(tools_qfcc_test_quaternion_dat_SOURCES:.r=.o)
quaternion_dep=$(call qcautodep,$(tools_qfcc_test_quaternion_dat_SOURCES))

View file

@ -0,0 +1,86 @@
#include "test-harness.h"
typedef @algebra(float(3,0,1)) PGA;
typedef PGA.group_mask(0xa) bivector_t;
typedef PGA.group_mask(0x1e) motor_t;
typedef PGA.tvec point_t;
typedef PGA.vec plane_t;
typedef struct {
vec4 trans;
vec4 rot;
} xform_t;
motor_t
make_motor (vec4 translation, vec4 rotation)
{
@algebra(PGA) {
auto dt = (PGA.group_mask (0x18)) translation;
auto q = (PGA.group_mask(0x06)) rotation;
motor_t t = { .scalar = 1, .bvecp = -dt.bvecp / 2 };
motor_t r = { .scalar = q.scalar, .bvect = q.bvect };
motor_t m = t * r;
return m;
}
}
xform_t
set_transform (motor_t m, int p)
{
@algebra (PGA) {
auto r =(m * e0123);
auto t = (m *(m * e0123)).bvecp;
vec4 rot = (vec4) r;
vec4 trans = [(vec3)t * -2, 1];
if (p) printf ("set_transform: %q %q\n", rot, trans);
return {trans, rot};
}
}
PGA.scalar rh = 0.7071067811865476;
int
main()
{
motor_t start = make_motor ({ 10, 4, -1.5, 0 }, { 0, 0, 0, 1 });
vec3 bvt = { 0, 0, rh };
vec3 bvp = { 0, -6*rh, 0 };
motor_t delta = {
.scalar = rh,
.bvect = (PGA.bvect) bvt,
.bvecp = (PGA.bvecp) bvp,
};
motor_t testm = delta * start;
printf ("start: %g %v %v %g\n",
start.scalar, start.bvect, start.bvecp, start.qvec);
printf ("delta: %g %v %v %g\n",
delta.scalar, delta.bvect, delta.bvecp, delta.qvec);
printf ("testm: %g %v %v %g\n",
testm.scalar, testm.bvect, testm.bvecp, testm.qvec);
auto xform = set_transform (testm, 1);
printf ("xform: %.9q %.9q\n", xform.trans, xform.rot);
if (start.scalar != 1 || (vec3) start.bvect != '0 0 0'
|| (vec3) start.bvecp != '-5 -2 0.75'
|| (PGA.scalar) start.qvec != 0) {
printf ("start incorrect\n");
return 1;
}
if (delta.scalar != rh || (vec3) delta.bvect != '0 0 0.7071067811865476'
|| (vec3) delta.bvecp != '0 -4.242640687119285 0'
|| (PGA.scalar) delta.qvec != 0) {
printf ("delta incorrect\n");
return 1;
}
if (testm.scalar != rh || (vec3) testm.bvect != '0 0 0.7071067811865476'
|| (vec3) testm.bvecp != '-4.949747468305833 -2.1213203435596424 0.5303300858899106'
|| (PGA.scalar) testm.qvec != 0.5303300858899106) {
printf ("testm incorrect\n");
return 1;
}
if (xform.trans != '10 -4 -1.49999988 1'
|| xform.rot != '0 0 -0.7071067811865476 0.7071067811865476') {
printf ("xform incorrect\n");
return 1;
}
return 0;
}