Add stress test file
This commit is contained in:
parent
a039dbbccd
commit
423e7e389d
|
@ -41,7 +41,7 @@ document.querySelectorAll("svg").forEach(function(svg) {
|
|||
}
|
||||
svg.querySelectorAll("path").forEach(function(path) {
|
||||
// Get circles on path for collision checking
|
||||
let num = Math.floor(path.getTotalLength() / 5)
|
||||
let num = Math.floor(path.getTotalLength() * 2 / rad)
|
||||
for (let i = 0; i <= num; i++) {
|
||||
const p = path.getPointAtLength(i / num * path.getTotalLength())
|
||||
a.cm.x += p.x
|
||||
|
@ -113,10 +113,10 @@ function collide(a, b, c, n) {
|
|||
|
||||
// Collision of object a with wall at position k and direction d
|
||||
function wallCollide(a, k, d) {
|
||||
if ((d == 0 && Math.abs(a.x - k) < a.r + rad) || (d == 1 && Math.abs(a.y - k) < a.r + rad)) {
|
||||
if ((!d && Math.abs(a.x - k) < a.r + rad) || (d && Math.abs(a.y - k) < a.r + rad)) {
|
||||
let c = {x: 0, y: 0, cnt: 0}
|
||||
for (const p of a.p.map(x => rot(a, x))) {
|
||||
if ((d == 0 && Math.abs(p.x - k) < rad) || (d == 1 && Math.abs(p.y - k) < rad)) {
|
||||
if ((!d && Math.abs(p.x - k) < rad) || (d && Math.abs(p.y - k) < rad)) {
|
||||
c.x += p.x
|
||||
c.y += p.y
|
||||
c.cnt++
|
||||
|
|
25
stress.html
Normal file
25
stress.html
Normal file
|
@ -0,0 +1,25 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Dumb physics engine</title>
|
||||
<meta name="description" content="Converts SVGs into a set of circles and use those circles for dumb collision checking">
|
||||
<link rel="stylesheet" href="style.css">
|
||||
</head>
|
||||
<body>
|
||||
<svg id="d"></svg>
|
||||
<svg id="u"></svg>
|
||||
<svg id="m"></svg>
|
||||
<svg id="b"></svg>
|
||||
<svg id="hiragana-ni"></svg>
|
||||
<svg id="hiragana-small-ya"></svg>
|
||||
<svg id="hiragana-a"></svg>
|
||||
<svg id="d"></svg>
|
||||
<svg id="u"></svg>
|
||||
<svg id="m"></svg>
|
||||
<svg id="b"></svg>
|
||||
<svg id="hiragana-ni"></svg>
|
||||
<svg id="hiragana-small-ya"></svg>
|
||||
<svg id="hiragana-a"></svg>
|
||||
<script src="script.js"></script>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in a new issue