Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix-333-allow-dimension-based-distances #342

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/descent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,16 @@ DEBUG */
private random = new PseudoRandom();

public project: { (x0: number[], y0: number[], r: number[]): void }[] = null;
/** The dimension distance calculation (defaults to x[i][u]-x[i][v])
* @property dimensionDistance{(number[][], number, number, number) => number}
* Can be replaced with a custom function.
* For example replacing with (x, i, u, v) => i==0 ? (x[i][u]-x[i][v])/4 : x[i][u]-x[i][v];
* has the effect of making horizontal distances larger than vertical
* distances.
*/
public static dimensionDistance(x: number[][], i: number, u: number, v: number): number {
return x[i][u] - x[i][v];
}

/**
* @method constructor
Expand Down Expand Up @@ -214,7 +224,7 @@ DEBUG */
while (maxDisplaces--) {
distanceSquared = 0;
for (i = 0; i < this.k; ++i) {
const dx = d[i] = x[i][u] - x[i][v];
const dx = d[i] = Descent.dimensionDistance(x, i, u, v);
distanceSquared += d2[i] = dx * dx;
}
if (distanceSquared > 1e-9) break;
Expand Down