working hardcode line pair
parent
ec59e95b87
commit
cf69fee366
File diff suppressed because one or more lines are too long
Binary file not shown.
File diff suppressed because one or more lines are too long
|
@ -736,10 +736,6 @@ function cwrap(ident, returnType, argTypes, opts) {
|
|||
|
||||
// We used to include malloc/free by default in the past. Show a helpful error in
|
||||
// builds with assertions.
|
||||
function _free() {
|
||||
// Show a helpful error since we used to include free by default in the past.
|
||||
abort("free() called but not included in the build - add '_free' to EXPORTED_FUNCTIONS");
|
||||
}
|
||||
|
||||
var ALLOC_NORMAL = 0; // Tries to use _malloc()
|
||||
var ALLOC_STACK = 1; // Lives for the duration of the current function call
|
||||
|
@ -1199,7 +1195,7 @@ function updateGlobalBufferAndViews(buf) {
|
|||
var TOTAL_STACK = 5242880;
|
||||
if (Module['TOTAL_STACK']) assert(TOTAL_STACK === Module['TOTAL_STACK'], 'the stack size can no longer be determined at runtime')
|
||||
|
||||
var INITIAL_MEMORY = Module['INITIAL_MEMORY'] || 16777216;
|
||||
var INITIAL_MEMORY = Module['INITIAL_MEMORY'] || 134217728;
|
||||
if (!Object.getOwnPropertyDescriptor(Module, 'INITIAL_MEMORY')) {
|
||||
Object.defineProperty(Module, 'INITIAL_MEMORY', {
|
||||
configurable: true,
|
||||
|
@ -1217,7 +1213,7 @@ assert(typeof Int32Array !== 'undefined' && typeof Float64Array !== 'undefined'
|
|||
|
||||
// If memory is defined in wasm, the user can't provide it.
|
||||
assert(!Module['wasmMemory'], 'Use of `wasmMemory` detected. Use -s IMPORTED_MEMORY to define wasmMemory externally');
|
||||
assert(INITIAL_MEMORY == 16777216, 'Detected runtime INITIAL_MEMORY setting. Use -s IMPORTED_MEMORY to define wasmMemory dynamically');
|
||||
assert(INITIAL_MEMORY == 134217728, 'Detected runtime INITIAL_MEMORY setting. Use -s IMPORTED_MEMORY to define wasmMemory dynamically');
|
||||
|
||||
// include: runtime_init_table.js
|
||||
// In regular non-RELOCATABLE mode the table is exported
|
||||
|
@ -1615,7 +1611,7 @@ function createWasm() {
|
|||
// This assertion doesn't hold when emscripten is run in --post-link
|
||||
// mode.
|
||||
// TODO(sbc): Read INITIAL_MEMORY out of the wasm file in post-link mode.
|
||||
//assert(wasmMemory.buffer.byteLength === 16777216);
|
||||
//assert(wasmMemory.buffer.byteLength === 134217728);
|
||||
updateGlobalBufferAndViews(wasmMemory.buffer);
|
||||
|
||||
wasmTable = Module['asm']['__indirect_function_table'];
|
||||
|
@ -1767,6 +1763,100 @@ var ASM_CONSTS = {
|
|||
return demangleAll(js);
|
||||
}
|
||||
|
||||
var ExceptionInfoAttrs={DESTRUCTOR_OFFSET:0,REFCOUNT_OFFSET:4,TYPE_OFFSET:8,CAUGHT_OFFSET:12,RETHROWN_OFFSET:13,SIZE:16};
|
||||
function ___cxa_allocate_exception(size) {
|
||||
// Thrown object is prepended by exception metadata block
|
||||
return _malloc(size + ExceptionInfoAttrs.SIZE) + ExceptionInfoAttrs.SIZE;
|
||||
}
|
||||
|
||||
function _atexit(func, arg) {
|
||||
}
|
||||
function ___cxa_atexit(a0,a1
|
||||
) {
|
||||
return _atexit(a0,a1);
|
||||
}
|
||||
|
||||
function ExceptionInfo(excPtr) {
|
||||
this.excPtr = excPtr;
|
||||
this.ptr = excPtr - ExceptionInfoAttrs.SIZE;
|
||||
|
||||
this.set_type = function(type) {
|
||||
HEAP32[(((this.ptr)+(ExceptionInfoAttrs.TYPE_OFFSET))>>2)] = type;
|
||||
};
|
||||
|
||||
this.get_type = function() {
|
||||
return HEAP32[(((this.ptr)+(ExceptionInfoAttrs.TYPE_OFFSET))>>2)];
|
||||
};
|
||||
|
||||
this.set_destructor = function(destructor) {
|
||||
HEAP32[(((this.ptr)+(ExceptionInfoAttrs.DESTRUCTOR_OFFSET))>>2)] = destructor;
|
||||
};
|
||||
|
||||
this.get_destructor = function() {
|
||||
return HEAP32[(((this.ptr)+(ExceptionInfoAttrs.DESTRUCTOR_OFFSET))>>2)];
|
||||
};
|
||||
|
||||
this.set_refcount = function(refcount) {
|
||||
HEAP32[(((this.ptr)+(ExceptionInfoAttrs.REFCOUNT_OFFSET))>>2)] = refcount;
|
||||
};
|
||||
|
||||
this.set_caught = function (caught) {
|
||||
caught = caught ? 1 : 0;
|
||||
HEAP8[(((this.ptr)+(ExceptionInfoAttrs.CAUGHT_OFFSET))>>0)] = caught;
|
||||
};
|
||||
|
||||
this.get_caught = function () {
|
||||
return HEAP8[(((this.ptr)+(ExceptionInfoAttrs.CAUGHT_OFFSET))>>0)] != 0;
|
||||
};
|
||||
|
||||
this.set_rethrown = function (rethrown) {
|
||||
rethrown = rethrown ? 1 : 0;
|
||||
HEAP8[(((this.ptr)+(ExceptionInfoAttrs.RETHROWN_OFFSET))>>0)] = rethrown;
|
||||
};
|
||||
|
||||
this.get_rethrown = function () {
|
||||
return HEAP8[(((this.ptr)+(ExceptionInfoAttrs.RETHROWN_OFFSET))>>0)] != 0;
|
||||
};
|
||||
|
||||
// Initialize native structure fields. Should be called once after allocated.
|
||||
this.init = function(type, destructor) {
|
||||
this.set_type(type);
|
||||
this.set_destructor(destructor);
|
||||
this.set_refcount(0);
|
||||
this.set_caught(false);
|
||||
this.set_rethrown(false);
|
||||
}
|
||||
|
||||
this.add_ref = function() {
|
||||
var value = HEAP32[(((this.ptr)+(ExceptionInfoAttrs.REFCOUNT_OFFSET))>>2)];
|
||||
HEAP32[(((this.ptr)+(ExceptionInfoAttrs.REFCOUNT_OFFSET))>>2)] = value + 1;
|
||||
};
|
||||
|
||||
// Returns true if last reference released.
|
||||
this.release_ref = function() {
|
||||
var prev = HEAP32[(((this.ptr)+(ExceptionInfoAttrs.REFCOUNT_OFFSET))>>2)];
|
||||
HEAP32[(((this.ptr)+(ExceptionInfoAttrs.REFCOUNT_OFFSET))>>2)] = prev - 1;
|
||||
assert(prev > 0);
|
||||
return prev === 1;
|
||||
};
|
||||
}
|
||||
|
||||
var exceptionLast=0;
|
||||
|
||||
var uncaughtExceptionCount=0;
|
||||
function ___cxa_throw(ptr, type, destructor) {
|
||||
var info = new ExceptionInfo(ptr);
|
||||
// Initialize ExceptionInfo content after it was allocated in __cxa_allocate_exception.
|
||||
info.init(type, destructor);
|
||||
exceptionLast = ptr;
|
||||
uncaughtExceptionCount++;
|
||||
throw ptr + " - Exception catching is disabled, this exception cannot be caught. Compile with -s DISABLE_EXCEPTION_CATCHING=0 or DISABLE_EXCEPTION_CATCHING=2 to catch.";
|
||||
}
|
||||
|
||||
function _abort() {
|
||||
abort();
|
||||
}
|
||||
|
||||
function _emscripten_memcpy_big(dest, src, num) {
|
||||
HEAPU8.copyWithin(dest, src, src + num);
|
||||
}
|
||||
|
@ -1788,14 +1878,6 @@ var ASM_CONSTS = {
|
|||
exit(status);
|
||||
}
|
||||
|
||||
function flush_NO_FILESYSTEM() {
|
||||
// flush anything remaining in the buffers during shutdown
|
||||
if (typeof _fflush !== 'undefined') _fflush(0);
|
||||
var buffers = SYSCALLS.buffers;
|
||||
if (buffers[1].length) SYSCALLS.printChar(1, 10);
|
||||
if (buffers[2].length) SYSCALLS.printChar(2, 10);
|
||||
}
|
||||
|
||||
var SYSCALLS={mappings:{},buffers:[null,[],[]],printChar:function(stream, curr) {
|
||||
var buffer = SYSCALLS.buffers[stream];
|
||||
assert(buffer);
|
||||
|
@ -1818,6 +1900,22 @@ var ASM_CONSTS = {
|
|||
else assert(high === -1);
|
||||
return low;
|
||||
}};
|
||||
function _fd_close(fd) {
|
||||
abort('it should not be possible to operate on streams when !SYSCALLS_REQUIRE_FILESYSTEM');
|
||||
return 0;
|
||||
}
|
||||
|
||||
function _fd_seek(fd, offset_low, offset_high, whence, newOffset) {
|
||||
abort('it should not be possible to operate on streams when !SYSCALLS_REQUIRE_FILESYSTEM');
|
||||
}
|
||||
|
||||
function flush_NO_FILESYSTEM() {
|
||||
// flush anything remaining in the buffers during shutdown
|
||||
if (typeof _fflush !== 'undefined') _fflush(0);
|
||||
var buffers = SYSCALLS.buffers;
|
||||
if (buffers[1].length) SYSCALLS.printChar(1, 10);
|
||||
if (buffers[2].length) SYSCALLS.printChar(2, 10);
|
||||
}
|
||||
function _fd_write(fd, iov, iovcnt, pnum) {
|
||||
// hack to support printf in SYSCALLS_REQUIRE_FILESYSTEM=0
|
||||
var num = 0;
|
||||
|
@ -1866,9 +1964,15 @@ function intArrayToString(array) {
|
|||
|
||||
|
||||
var asmLibraryArg = {
|
||||
"__cxa_allocate_exception": ___cxa_allocate_exception,
|
||||
"__cxa_atexit": ___cxa_atexit,
|
||||
"__cxa_throw": ___cxa_throw,
|
||||
"abort": _abort,
|
||||
"emscripten_memcpy_big": _emscripten_memcpy_big,
|
||||
"emscripten_resize_heap": _emscripten_resize_heap,
|
||||
"exit": _exit,
|
||||
"fd_close": _fd_close,
|
||||
"fd_seek": _fd_seek,
|
||||
"fd_write": _fd_write,
|
||||
"setTempRet0": _setTempRet0
|
||||
};
|
||||
|
@ -1885,6 +1989,9 @@ var _main = Module["_main"] = createExportWrapper("main");
|
|||
/** @type {function(...*):?} */
|
||||
var _malloc = Module["_malloc"] = createExportWrapper("malloc");
|
||||
|
||||
/** @type {function(...*):?} */
|
||||
var _free = Module["_free"] = createExportWrapper("free");
|
||||
|
||||
/** @type {function(...*):?} */
|
||||
var ___errno_location = Module["___errno_location"] = createExportWrapper("__errno_location");
|
||||
|
||||
|
|
Binary file not shown.
|
@ -81,7 +81,7 @@ export class Sketcher extends THREE.Group {
|
|||
this.mode = "line"
|
||||
break;
|
||||
case 'b':
|
||||
this.writeBuff()
|
||||
this.solve()
|
||||
break;
|
||||
case '=':
|
||||
this.plane.applyMatrix4(new Matrix4().makeRotationY(0.1))
|
||||
|
@ -258,7 +258,7 @@ export class Sketcher extends THREE.Group {
|
|||
this.pointStart(e)
|
||||
}
|
||||
|
||||
writeBuff() {
|
||||
solve() {
|
||||
// const linesBuf = new Float32Array(this.linesArr.length * 4)
|
||||
// const xyOnly = [0,1,3,4];
|
||||
// let p = 0
|
||||
|
@ -274,12 +274,13 @@ export class Sketcher extends THREE.Group {
|
|||
ptsBuf[p++] = this.ptsArr[i].geometry.attributes.position.array[j]
|
||||
}
|
||||
}
|
||||
console.log(ptsBuf)
|
||||
|
||||
buffer = Module._malloc(ptsBuf.length * ptsBuf.BYTES_PER_ELEMENT)
|
||||
Module.HEAPF32.set(ptsBuf, buffer >> 2)
|
||||
|
||||
Module["_solver"](buffer)
|
||||
Module["_solver"](this.ptsArr.length/2, buffer)
|
||||
|
||||
Module._free(buffer)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
139
wasm/notes
139
wasm/notes
|
@ -1 +1,138 @@
|
|||
emcc ./wasm/solver.c ./wasm/libslvs.a -L./wasm/ -lslvs -o ./dist/solver.js -s TOTAL_MEMORY=134217728 -s EXPORTED_FUNCTIONS='[_main, _solver]'
|
||||
emcc ./wasm/solver.c ./wasm/libslvs.a -L./wasm/ -lslvs -o ./dist/solver.js -s TOTAL_MEMORY=134217728 -s EXPORTED_FUNCTIONS='[_main, _solver, _free]'
|
||||
|
||||
|
||||
|
||||
int solver(int nLines, float *ptr)
|
||||
{
|
||||
// for (int i=0; i<nLines ;i++) {
|
||||
// printf("%f\n",*ptr++);
|
||||
// }
|
||||
float *buf_pt_start = ptr;
|
||||
|
||||
Slvs_hGroup g;
|
||||
double qw, qx, qy, qz;
|
||||
|
||||
g = 1;
|
||||
/* First, we create our workplane. Its origin corresponds to the origin
|
||||
* of our base frame (x y z) = (0 0 0) */
|
||||
sys.param[sys.params++] = Slvs_MakeParam(1, g, 0.0);
|
||||
sys.param[sys.params++] = Slvs_MakeParam(2, g, 0.0);
|
||||
sys.param[sys.params++] = Slvs_MakeParam(3, g, 0.0);
|
||||
sys.entity[sys.entities++] = Slvs_MakePoint3d(101, g, 1, 2, 3);
|
||||
/* and it is parallel to the xy plane, so it has basis vectors (1 0 0)
|
||||
* and (0 1 0). */
|
||||
Slvs_MakeQuaternion(1, 0, 0,
|
||||
0, 1, 0, &qw, &qx, &qy, &qz);
|
||||
sys.param[sys.params++] = Slvs_MakeParam(4, g, qw);
|
||||
sys.param[sys.params++] = Slvs_MakeParam(5, g, qx);
|
||||
sys.param[sys.params++] = Slvs_MakeParam(6, g, qy);
|
||||
sys.param[sys.params++] = Slvs_MakeParam(7, g, qz);
|
||||
sys.entity[sys.entities++] = Slvs_MakeNormal3d(102, g, 4, 5, 6, 7);
|
||||
|
||||
sys.entity[sys.entities++] = Slvs_MakeWorkplane(200, g, 101, 102);
|
||||
|
||||
/* Now create a second group. We'll solve group 2, while leaving group 1
|
||||
* constant; so the workplane that we've created will be locked down,
|
||||
* and the solver can't move it. */
|
||||
g = 2;
|
||||
/* These points are represented by their coordinates (u v) within the
|
||||
* workplane, so they need only two parameters each. */
|
||||
|
||||
Slvs_hParam h = 8;
|
||||
Slvs_hParam pt_id = 301;
|
||||
Slvs_hParam line_id = 400;
|
||||
Slvs_hParam con_id = 0;
|
||||
int ptStart = sys.params;
|
||||
for (int i = 0; i < nLines; i++)
|
||||
{
|
||||
sys.param[sys.params++] = Slvs_MakeParam(h++, g, (float)*ptr++);
|
||||
sys.param[sys.params++] = Slvs_MakeParam(h++, g, (float)*ptr++);
|
||||
sys.entity[sys.entities++] = Slvs_MakePoint2d(pt_id++, g, 200, h - 2, h - 1);
|
||||
|
||||
if (i > 0)
|
||||
{
|
||||
sys.constraint[sys.constraints++] = Slvs_MakeConstraint(
|
||||
con_id++, g,
|
||||
SLVS_C_POINTS_COINCIDENT,
|
||||
200,
|
||||
0.0,
|
||||
pt_id - 1, pt_id - 2, 0, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
sys.constraint[sys.constraints++] = Slvs_MakeConstraint(
|
||||
con_id++, g,
|
||||
SLVS_C_POINTS_COINCIDENT,
|
||||
200,
|
||||
0.0,
|
||||
pt_id - 1, 101, 0, 0);
|
||||
}
|
||||
|
||||
printf("h:%i\n", h);
|
||||
|
||||
sys.param[sys.params++] = Slvs_MakeParam(h++, g, (float)*ptr++);
|
||||
sys.param[sys.params++] = Slvs_MakeParam(h++, g, (float)*ptr++);
|
||||
|
||||
sys.entity[sys.entities++] = Slvs_MakePoint2d(pt_id++, g, 200, h - 2, h - 1);
|
||||
|
||||
sys.entity[sys.entities++] = Slvs_MakeLineSegment(line_id++, g,
|
||||
200, pt_id - 1, pt_id - 2);
|
||||
|
||||
sys.constraint[sys.constraints++] = Slvs_MakeConstraint(
|
||||
con_id++, g,
|
||||
SLVS_C_PT_PT_DISTANCE,
|
||||
200,
|
||||
30.0,
|
||||
pt_id - 1, pt_id - 2, 0, 0);
|
||||
sys.constraint[sys.constraints++] = Slvs_MakeConstraint(
|
||||
con_id++, g,
|
||||
SLVS_C_VERTICAL,
|
||||
200,
|
||||
0.0,
|
||||
0, 0, line_id-1, 0);
|
||||
}
|
||||
|
||||
/* If the solver fails, then ask it to report which constraints caused
|
||||
* the problem. */
|
||||
sys.calculateFaileds = 1;
|
||||
|
||||
sys.dragged[0] = 10;
|
||||
sys.dragged[1] = 11;
|
||||
sys.dragged[2] = 14;
|
||||
sys.dragged[3] = 15;
|
||||
|
||||
/* And solve. */
|
||||
Slvs_Solve(&sys, g);
|
||||
|
||||
// printf("%i,wtf\n", sys.result);
|
||||
if (sys.result == SLVS_RESULT_OKAY)
|
||||
{
|
||||
printf("solved okay\n");
|
||||
|
||||
for (int i = 0; i < nLines * 4; i++)
|
||||
{
|
||||
// *buf_pt_start++ = (float)sys.param[ptStart++].val;
|
||||
printf("%f\n", sys.param[ptStart++].val);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
int i;
|
||||
printf("solve failed: problematic constraints are:");
|
||||
for (i = 0; i < sys.faileds; i++)
|
||||
{
|
||||
printf(" %d", sys.failed[i]);
|
||||
}
|
||||
printf("\n");
|
||||
if (sys.result == SLVS_RESULT_INCONSISTENT)
|
||||
{
|
||||
printf("system inconsistent\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("system nonconvergent\n");
|
||||
}
|
||||
}
|
||||
sys.params = sys.constraints = sys.entities = 0;
|
||||
return 0;
|
||||
}
|
141
wasm/solver.c
141
wasm/solver.c
|
@ -20,7 +20,8 @@ static Slvs_System sys;
|
|||
static void *CheckMalloc(size_t n)
|
||||
{
|
||||
void *r = malloc(n);
|
||||
if(!r) {
|
||||
if (!r)
|
||||
{
|
||||
printf("out of memory!\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
@ -60,20 +61,23 @@ void Example3d()
|
|||
|
||||
/* Let's tell the solver to keep the second point as close to constant
|
||||
* as possible, instead moving the first point. */
|
||||
sys.dragged[0] = 4;
|
||||
sys.dragged[1] = 5;
|
||||
sys.dragged[2] = 6;
|
||||
// sys.dragged[0] = 4;
|
||||
// sys.dragged[1] = 5;
|
||||
// sys.dragged[2] = 6;
|
||||
|
||||
/* Now that we have written our system, we solve. */
|
||||
Slvs_Solve(&sys, g);
|
||||
|
||||
if(sys.result == SLVS_RESULT_OKAY) {
|
||||
if (sys.result == SLVS_RESULT_OKAY)
|
||||
{
|
||||
printf("okay; now at (%.3f %.3f %.3f)\n"
|
||||
" (%.3f %.3f %.3f)\n",
|
||||
sys.param[0].val, sys.param[1].val, sys.param[2].val,
|
||||
sys.param[3].val, sys.param[4].val, sys.param[5].val);
|
||||
printf("%d DOF\n", sys.dof);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("solve failed");
|
||||
}
|
||||
}
|
||||
|
@ -157,7 +161,6 @@ void Example2d(float xx)
|
|||
sys.entity[sys.entities++] = Slvs_MakeCircle(402, g, 200,
|
||||
306, 102, 307);
|
||||
|
||||
|
||||
/* The length of our line segment is 30.0 units. */
|
||||
sys.constraint[sys.constraints++] = Slvs_MakeConstraint(
|
||||
1, g,
|
||||
|
@ -220,7 +223,8 @@ void Example2d(float xx)
|
|||
/* And solve. */
|
||||
Slvs_Solve(&sys, g);
|
||||
|
||||
if(sys.result == SLVS_RESULT_OKAY) {
|
||||
if (sys.result == SLVS_RESULT_OKAY)
|
||||
{
|
||||
printf("solved okay\n");
|
||||
printf("line from (%.3f %.3f) to (%.3f %.3f)\n",
|
||||
sys.param[7].val, sys.param[8].val,
|
||||
|
@ -235,34 +239,131 @@ void Example2d(float xx)
|
|||
sys.param[17].val, sys.param[18].val,
|
||||
sys.param[19].val);
|
||||
printf("%d DOF\n", sys.dof);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
int i;
|
||||
printf("solve failed: problematic constraints are:");
|
||||
for(i = 0; i < sys.faileds; i++) {
|
||||
for (i = 0; i < sys.faileds; i++)
|
||||
{
|
||||
printf(" %d", sys.failed[i]);
|
||||
}
|
||||
printf("\n");
|
||||
if(sys.result == SLVS_RESULT_INCONSISTENT) {
|
||||
if (sys.result == SLVS_RESULT_INCONSISTENT)
|
||||
{
|
||||
printf("system inconsistent\n");
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("system nonconvergent\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int solver(float *ptr)
|
||||
int solver(int nLines, float *ptr)
|
||||
{
|
||||
// for (int i=0; i<nLines ;i++) {
|
||||
// printf("%f\n",*ptr++);
|
||||
// }
|
||||
float *buf_pt_start = ptr;
|
||||
|
||||
// Example2d(150.0);
|
||||
// sys.params = sys.constraints = sys.entities = 0;
|
||||
for (int i=0; i<10 ;i++) {
|
||||
printf("%f\n",*ptr++);
|
||||
Slvs_hGroup g;
|
||||
double qw, qx, qy, qz;
|
||||
|
||||
g = 1;
|
||||
/* First, we create our workplane. Its origin corresponds to the origin
|
||||
* of our base frame (x y z) = (0 0 0) */
|
||||
sys.param[sys.params++] = Slvs_MakeParam(1, g, 0.0);
|
||||
sys.param[sys.params++] = Slvs_MakeParam(2, g, 0.0);
|
||||
sys.param[sys.params++] = Slvs_MakeParam(3, g, 0.0);
|
||||
sys.entity[sys.entities++] = Slvs_MakePoint3d(101, g, 1, 2, 3);
|
||||
/* and it is parallel to the xy plane, so it has basis vectors (1 0 0)
|
||||
* and (0 1 0). */
|
||||
Slvs_MakeQuaternion(1, 0, 0,
|
||||
0, 1, 0, &qw, &qx, &qy, &qz);
|
||||
sys.param[sys.params++] = Slvs_MakeParam(4, g, qw);
|
||||
sys.param[sys.params++] = Slvs_MakeParam(5, g, qx);
|
||||
sys.param[sys.params++] = Slvs_MakeParam(6, g, qy);
|
||||
sys.param[sys.params++] = Slvs_MakeParam(7, g, qz);
|
||||
sys.entity[sys.entities++] = Slvs_MakeNormal3d(102, g, 4, 5, 6, 7);
|
||||
|
||||
sys.entity[sys.entities++] = Slvs_MakeWorkplane(200, g, 101, 102);
|
||||
|
||||
/* Now create a second group. We'll solve group 2, while leaving group 1
|
||||
* constant; so the workplane that we've created will be locked down,
|
||||
* and the solver can't move it. */
|
||||
g = 2;
|
||||
/* These points are represented by their coordinates (u v) within the
|
||||
* workplane, so they need only two parameters each. */
|
||||
|
||||
int ptStart = sys.params;
|
||||
|
||||
sys.param[sys.params++] = Slvs_MakeParam(11, g, (float)*ptr++);
|
||||
sys.param[sys.params++] = Slvs_MakeParam(12, g, (float)*ptr++);
|
||||
sys.entity[sys.entities++] = Slvs_MakePoint2d(301, g, 200, 11, 12);
|
||||
|
||||
sys.param[sys.params++] = Slvs_MakeParam(13, g, (float)*ptr++);
|
||||
sys.param[sys.params++] = Slvs_MakeParam(14, g, (float)*ptr++);
|
||||
sys.entity[sys.entities++] = Slvs_MakePoint2d(302, g, 200, 13, 14);
|
||||
|
||||
/* And we create a line segment with those endpoints. */
|
||||
sys.entity[sys.entities++] = Slvs_MakeLineSegment(400, g,
|
||||
200, 301, 302);
|
||||
|
||||
sys.param[sys.params++] = Slvs_MakeParam(15, g, (float)*ptr++);
|
||||
sys.param[sys.params++] = Slvs_MakeParam(16, g, (float)*ptr++);
|
||||
sys.entity[sys.entities++] = Slvs_MakePoint2d(303, g, 200, 15, 16);
|
||||
|
||||
sys.param[sys.params++] = Slvs_MakeParam(17, g, (float)*ptr++);
|
||||
sys.param[sys.params++] = Slvs_MakeParam(18, g, (float)*ptr++);
|
||||
sys.entity[sys.entities++] = Slvs_MakePoint2d(304, g, 200, 17, 18);
|
||||
|
||||
sys.entity[sys.entities++] = Slvs_MakeLineSegment(401, g,
|
||||
200, 303, 304);
|
||||
|
||||
sys.constraint[sys.constraints++] = Slvs_MakeConstraint(
|
||||
421, g,
|
||||
SLVS_C_POINTS_COINCIDENT,
|
||||
200,
|
||||
0.0,
|
||||
302, 303, 0, 0);
|
||||
|
||||
/* And solve. */
|
||||
Slvs_Solve(&sys, g);
|
||||
|
||||
// printf("%i,wtf\n", sys.result);
|
||||
if (sys.result == SLVS_RESULT_OKAY)
|
||||
{
|
||||
printf("solved okay\n");
|
||||
|
||||
for (int i = 0; i < nLines * 4; i++)
|
||||
{
|
||||
// *buf_pt_start++ = (float)sys.param[ptStart++].val;
|
||||
printf("%f\n", sys.param[ptStart++].val);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
int i;
|
||||
printf("solve failed: problematic constraints are:");
|
||||
for (i = 0; i < sys.faileds; i++)
|
||||
{
|
||||
printf(" %d", sys.failed[i]);
|
||||
}
|
||||
printf("\n");
|
||||
if (sys.result == SLVS_RESULT_INCONSISTENT)
|
||||
{
|
||||
printf("system inconsistent\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("system nonconvergent\n");
|
||||
}
|
||||
}
|
||||
sys.params = sys.constraints = sys.entities = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
sys.param = CheckMalloc(50 * sizeof(sys.param[0]));
|
||||
|
@ -272,10 +373,8 @@ int main(int argc, char *argv[])
|
|||
sys.failed = CheckMalloc(50 * sizeof(sys.failed[0]));
|
||||
sys.faileds = 50;
|
||||
|
||||
|
||||
// Example2d(150.0);
|
||||
|
||||
printf("hello\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue