Skip to content

Commit

Permalink
fix: inverted weights
Browse files Browse the repository at this point in the history
  • Loading branch information
RoxaneBurri committed Mar 20, 2023
1 parent 8707e62 commit c9e3976
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 238 deletions.
229 changes: 0 additions & 229 deletions src/pseudocode.txt

This file was deleted.

18 changes: 9 additions & 9 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,14 @@ export const placeWordOnOuterCircle = (
passRect: Rectangle[],
weight: number[]
): Rectangle => {
const maxWeight = Math.max(...weight);

// Substract the max to each element to promote other interval
const invertedWeight = weight.map((a) => maxWeight - a);

// The cumulative weight allows to define intervals to select a random portion of circle to put our current rectangle, with
// different probabilities (here we want to favour portions of the circle with less rectangles already put)
const cumulativeWeight = cumulativeBins(weight);
const cumulativeWeight = cumulativeBins(invertedWeight);

const randomInter = randomInterval(
0,
Expand All @@ -136,11 +141,6 @@ export const placeWordOnOuterCircle = (
// Add to weights the position that has just been drawn
weight[inter] += 1;

const maxWeight = Math.max(...weight);

// Substract the max to each element to promote other interval
weight = weight.map((a) => maxWeight - a);

let angleInter = { x: 0, y: 360 };

if (inter === 0) {
Expand Down Expand Up @@ -189,7 +189,7 @@ export const futurPosition = (
): Rectangle => {
let isCollision = false;

// put the word in random place around the parent
// Put the word in random place around the parent
let movedWord = placeWordOnOuterCircle(word, passRect, weight);
let iter = 0;
let displacement = 0;
Expand All @@ -204,15 +204,15 @@ export const futurPosition = (
y: movedWord.y + (Math.abs(stepY) > 0.01 ? stepY : 0),
};

// test if the word can be move over the hypotenuse
// Test if the word can be move over the hypotenuse
if (allCollision(futurPosition, passRect)) {
const onlyMoveOverX = { ...futurPosition, y: movedWord.y };
const onlyMoveOverY = { ...futurPosition, x: movedWord.x };
const xColl = allCollision(onlyMoveOverX, passRect);
const yColl = allCollision(onlyMoveOverY, passRect);
if (xColl) {
if (yColl) {
// do not move anymore
// Do not move anymore
isCollision = true;
} else {
movedWord = { ...onlyMoveOverY };
Expand Down

0 comments on commit c9e3976

Please sign in to comment.