# Commits

committed ae9e1f5 Draft

Simplify constraints

• Participants
• Parent commits 4c51435

# File part.c

` Partsys *sys;`
` `
` enum {`
`-	Debug = 1`
`+	Debug = 0`
` };`
` `
` void*`
` {`
` 	int i;`
` 	Vect r, max;`
`+	Part *p;`
` 	float k;`
` `
`-	/* `
`-	 * todo: when the particle is very close to the bounds, `
`-	 * after bouncing, it oscillates with the bounds as center.`
`-	 * how do we solve this in a reasonable way?`
`-	 */`
` 	for(i=0; i < sys->nparts; i++){`
`-		k = sys->part[i].k;`
`-		if(sys->part[i].r.y+3*k >= sys->box[1].y ||`
`-			sys->part[i].r.y-3*k <= sys->box[0].y){`
`-			if(Debug)`
`-				printf("diff: %g\n", fabs(sys->part[i].r.y - sys->box[1].y));`
`-			if(fabs(sys->part[i].r.y - sys->box[1].y) < 4*k)`
`-				if(k > 0)`
`-					k -= 0.1;`
`-			sys->part[i].v.y = -k*sys->part[i].v.y;`
`+		p = &sys->part[i];`
`+		k = p->k;`
`+		if(p->r.y > sys->box[1].y-Border){`
`+			p->v.y = -k*p->v.y;`
`+			p->r.y = sys->box[1].y-Border;`
` 		}`
`-		if(sys->part[i].r.x+3*k >= sys->box[1].x ||`
`-			sys->part[i].r.x-3*k <= sys->box[0].x){`
`-			if(Debug)`
`-				printf("diff: %g\n", fabs(sys->part[i].r.x - sys->box[1].x));`
`-			if(fabs(sys->part[i].r.x - sys->box[1].x) < 4*k)`
`-				if(k > 0)`
`-					k -= 0.1;`
`-			sys->part[i].v.x = -k*sys->part[i].v.x;`
`+		if(p->r.x > sys->box[1].x-Border){`
`+			p->v.x = -k*p->v.x;`
`+			p->r.x = sys->box[1].x-Border;`
` 		}`
`-`
`-`
`-		vmax(&max, &sys->part[i].r, &sys->box[0]);`
`-		vmin(&r, &max, &sys->box[1]);`
`-		vcopy(&sys->part[i].r, &r);`
`-		`
`-		if(Debug)`
`-			printf("cons: (%g,%g,%g)\n", r.x, r.y, r.z);`
`-		sys->part[i].k = k;`
` 	}`
` }`
` `