Skip to content

Commit

Permalink
#17 - filter in SH.getAroundCellsItems() by radius
Browse files Browse the repository at this point in the history
  • Loading branch information
TheLucifurry committed Mar 6, 2021
1 parent e1aa0f8 commit 6fa88db
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/algorithm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ function adjustSprings(store: TStore, updatedPids: number[], dt: number) {
})
}
function doubleDensityRelaxation(store: TStore, i: TLiquidParticle, dt: number) {
const kNear = store.radius / 4 // stiffness near (вроде, влияет на текучесть)
const kNear = store.radius / 3 // stiffness near (вроде, влияет на текучесть)

let p = 0;
let pNear = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/cycles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export function foreachIds(particles: TLiquidParticle[], pids: number[], callbac
export function getNeighbors(store: TStore, part: TLiquidParticle) {
// const Math.sqrt((x1-x0)*(x1-x0) + (y1-y0)*(y1-y0)) < r
// const x = part[PARTICLE_PROPS.X], y = part[PARTICLE_PROPS.Y];
return store.spatialHash.getAroundCellsItems(part[PARTICLE_PROPS.X], part[PARTICLE_PROPS.Y])
return store.spatialHash.getAroundCellsItems(part[PARTICLE_PROPS.X], part[PARTICLE_PROPS.Y], store.particles)
// .filter(neighborPid=>{
// const nPart = store.particles[neighborPid];
// const nx = nPart[PARTICLE_PROPS.X], ny = nPart[PARTICLE_PROPS.Y];
Expand Down
19 changes: 15 additions & 4 deletions src/spatialHash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ export default class SpatialHash{
this._delete(item, cellid);
}

getAroundCellsItems(x: number, y: number){
// Special
getAroundCellsItems(x: number, y: number, particles: TLiquidParticle[]){
const centerCellX = trunc(x, this.cellSize);
const centerCellY = trunc(y, this.cellSize);
const selfItemId = getIndex(centerCellX, centerCellY);
Expand All @@ -102,10 +103,20 @@ export default class SpatialHash{
const x = centerCellX + aroundCellRelatives[i], y = centerCellY + aroundCellRelatives[i+1];
res.push(...(this.hash[getIndex(x, y)] || []))
}
return res;
}

// Special
// Filter only parts in radius
const filteredRes: TSHItem[] = [];
for (let i = 0; i < res.length; i++) {
const pid = res[i];
const part = particles[pid];
const partX: number = trunc(part[PARTICLE_PROPS.X], this.cellSize), partY: number = trunc(part[PARTICLE_PROPS.Y], this.cellSize);
if((partX - centerCellX) ** 2 + (partY - centerCellY) ** 2 <= 1){
filteredRes.push(pid);
}
}

return filteredRes;
}
fill(particles: TLiquidParticle[]){
particles.forEach((part, pid)=>{
const x = part[PARTICLE_PROPS.X], y = part[PARTICLE_PROPS.Y];
Expand Down

0 comments on commit 6fa88db

Please sign in to comment.