Skip to content

Commit

Permalink
Assuming the arms are CCW, make the movements in the correct order
Browse files Browse the repository at this point in the history
  • Loading branch information
dabreegster committed Jul 31, 2024
1 parent ed80cca commit 61c121b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/routes/route_check/jat_check/EditJunction.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@
</p>
{#if $state.jat[junctionIdx][stage].arms.length > 0}
<SecondaryButton on:click={autogenerateMovements}>
Generate movements between all arms (1st arm is the center)
Generate cycling movements between all arms (1st arm is the center)
</SecondaryButton>
{/if}
{#each $state.jat[junctionIdx][stage].movements as movement, idx}
Expand Down
47 changes: 36 additions & 11 deletions src/routes/route_check/jat_check/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,30 @@ export function generateMovements(center: Arm, arms: Arm[]): Movement[] {
.coordinates as Position;
};

// TODO Need arms to be sorted CCW

/*for (let i = 0; i < arms.length; i++) {
for (let j = 0; j < arms.length; j++) {
if (i != j) {
let arm1 = arms[i];
let arm2 = arms[j];
let b = normalize(bearing(arm1.point, arm2.point));
console.log(`bearing from ${arm1.name} to ${arm2.name} is ${b}`);
}
}
}*/
// Sort by angle from arm1
//let destinations = arms.filter((a) => a.point != arm1.point).toSorted((a1, a2) => normalize(bearing(arm1.point, a1.point)) - normalize(bearing(arm1.point, a2.point)));

let movements = [];
for (let i = 0; i < arms.length; i++) {
let arm1 = arms[i];
let angleStartToCenter = bearing(arm1.point, center.point);

// Continue in order
let toCount = 1;
// TODO Order by clockwise
for (let j = 0; j < arms.length; j++) {
if (i == j) {
continue;
}
let arm1 = arms[i];
for (let j of order(i, arms.length)) {
let arm2 = arms[j];

let angleStartToCenter = bearing(arm1.point, center.point);
let angleCenterToEnd = bearing(center.point, arm2.point);
// Start at the arm, far from the junction
let point1 = jitter(i, toCount++);
Expand All @@ -44,13 +56,26 @@ export function generateMovements(center: Arm, arms: Arm[]): Movement[] {
point2,
point3,
kind: "cycling" as const,
score: "0" as const,
score: "X" as const,
name: `${arm1.name} to ${arm2.name}`,
notes: "",
});
}
// Just work on one for now
//break;
}
return movements;
}

function normalize(b: number): number {
return (b + 360) % 360;
}

function order(i: number, n: number): number[] {
let out = [];
for (let x = i + 1; x < n; x++) {
out.push(x);
}
for (let x = 0; x < i; x++) {
out.push(x);
}
return out;
}

0 comments on commit 61c121b

Please sign in to comment.