From 5e45b6fee89e38e2c514c5ac313013be2e895771 Mon Sep 17 00:00:00 2001 From: Alex Rand Date: Sun, 5 Jan 2020 06:35:14 -0600 Subject: [PATCH 1/3] Changing number of points slider to a log scale --- src/App.js | 2 +- src/ControlPanel.js | 13 ++++++++++++- src/ControlSettings.js | 5 ++--- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/App.js b/src/App.js index 2739f81..b973dcb 100644 --- a/src/App.js +++ b/src/App.js @@ -26,7 +26,7 @@ class App extends Component { constructor(props) { super(props); this.state = { - numPoints: 2500, + numPoints: 1000, backgroundColor:"#fdfdfd", // doesn't work with white or black -- strange circleSpacing: 3, shape: 'triangles', diff --git a/src/ControlPanel.js b/src/ControlPanel.js index 8088d36..4f91d44 100644 --- a/src/ControlPanel.js +++ b/src/ControlPanel.js @@ -110,7 +110,6 @@ class ControlPanel extends Component { break; case 'slider': - ele =
{ (control.getDisabled === undefined || (control.getDisabled !== undefined && !control.getDisabled(this.props.disabled[control.id]))) &&
@@ -122,6 +121,18 @@ class ControlPanel extends Component {
}
break; + case 'logslider': + ele =
+ { (control.getDisabled === undefined || (control.getDisabled !== undefined && !control.getDisabled(this.props.disabled[control.id]))) && +
+ + this.handleSliderChange(control.id, Math.round(Math.pow(10,(val/25+1)))) } onDragStop={ (e) => this.props.update(e, control.id, this.state[control.id]) } + defaultValue={ Math.log10(this.props.status[control.id])*25-25 } sliderStyle={ this.state.styles.slider } /> +
} +
+ break; case 'checkbox': ele =
{ (control.getDisabled === undefined || (control.getDisabled !== undefined && !control.getDisabled(this.props.disabled[control.id]))) && diff --git a/src/ControlSettings.js b/src/ControlSettings.js index c9368e8..ec4526b 100644 --- a/src/ControlSettings.js +++ b/src/ControlSettings.js @@ -24,11 +24,10 @@ const ControlSettings = [{ }] }, { id: 'numPoints', - type: 'slider', + type: 'logslider', getLabel: (num) => "# of Points: " + num, min: 10, - max: 50000, - step: 100 + max: 100000 }, { id: 'fitToScreen', From d1f6340483d7112be2c0cb6f280c8a315ccab39a Mon Sep 17 00:00:00 2001 From: Alex Rand Date: Sun, 5 Jan 2020 13:59:39 -0600 Subject: [PATCH 2/3] Tweaks to remove some compiler warnings --- src/App.js | 2 +- src/PolygonUtils.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/App.js b/src/App.js index b973dcb..7184bc2 100644 --- a/src/App.js +++ b/src/App.js @@ -193,7 +193,7 @@ class App extends Component { circleSpacing: this.state.shape !== "circles", smoothIters: this.state.smoothType === "none", contrastIters: this.state.smoothType === "none", - backgroundColor: this.state.shape != "circles" && this.state.fill ? true : false + backgroundColor: this.state.shape !== "circles" && this.state.fill ? true : false } return ( diff --git a/src/PolygonUtils.js b/src/PolygonUtils.js index 2218fb8..d03406d 100644 --- a/src/PolygonUtils.js +++ b/src/PolygonUtils.js @@ -169,7 +169,7 @@ const PolygonUtils = { let snappedAny = false; // Sites that edges of Voronoi cells that lie on the perimeter of // the polygon will be snapped to the perimeter. - diagram.edges.map(function(edge) { + diagram.edges.forEach(function(edge) { // Perimeter edges don't have a neighboring Voronoi site. if (typeof edge.right === 'undefined') { // If the site has already been snapped to the perimeter, skip it. From 53015cb817525b8fa360a41f5019cf3af852d9d1 Mon Sep 17 00:00:00 2001 From: Alex Rand Date: Mon, 6 Jan 2020 18:29:01 -0600 Subject: [PATCH 3/3] Removing some unecessary code. --- src/PolygonUtils.js | 44 +++++++++++++------------------------------- src/Resampler.js | 10 ++-------- 2 files changed, 15 insertions(+), 39 deletions(-) diff --git a/src/PolygonUtils.js b/src/PolygonUtils.js index d03406d..f95ca4d 100644 --- a/src/PolygonUtils.js +++ b/src/PolygonUtils.js @@ -123,38 +123,20 @@ const PolygonUtils = { let weight = 0; let counter = 0; for (let iW =0; iW < width; ++iW) { - if (iW % 2 === 0) { - for (let iH=0; iH < height; ++iH) { - weight = weights[counter]; - ++counter; // note: counter = iW*height+iH; but this is a little faster? - if (weight > 0.0) { - site = diagram.find(iW, iH).index; // find which polygon contains this pixels - if (weightedCentroidData[site][2] === 0.0) { - weightedCentroidData[site][0] = weight*iW; - weightedCentroidData[site][1] = weight*iH; - } else { - weightedCentroidData[site][0] += weight*iW; - weightedCentroidData[site][1] += weight*iH; - } - weightedCentroidData[site][2] += weight; + for (let iH=0; iH < height; ++iH) { + weight = weights[counter]; + ++counter; // note: counter = iW*height+iH; but this is a little faster? + if (weight > 0.0) { + site = diagram.find(iW, iH).index; // find which polygon contains this pixels + if (weightedCentroidData[site][2] === 0.0) { + weightedCentroidData[site][0] = weight*iW; + weightedCentroidData[site][1] = weight*iH; + } else { + weightedCentroidData[site][0] += weight*iW; + weightedCentroidData[site][1] += weight*iH; } - } - } else { - for (let iH=height-1; iH >= 0; --iH) { - weight = weights[counter]; - ++counter; // note: counter = iW*height+iH; but this is a little faster? - if (weight > 0.0) { - site = diagram.find(iW, iH).index; // find which polygon contains this pixel - if (weightedCentroidData[site][2] === 0.0) { - weightedCentroidData[site][0] = weight*iW; - weightedCentroidData[site][1] = weight*iH; - } else { - weightedCentroidData[site][0] += weight*iW; - weightedCentroidData[site][1] += weight*iH; - } - weightedCentroidData[site][2] += weight; - } - } + weightedCentroidData[site][2] += weight; + } } } diff --git a/src/Resampler.js b/src/Resampler.js index 3f2b980..860f9b7 100644 --- a/src/Resampler.js +++ b/src/Resampler.js @@ -113,14 +113,8 @@ class Resampler { this.weights = []; if (this.smoothType === 'contrastWeighted') { for (let iW =0; iW < this.width; ++iW) { - if (iW % 2 === 0) { - for (let iH=0; iH < this.height; ++iH) { - this.weights.push(this.approximateGradient(iW, iH, 1) + 1.0); - } - } else { - for (let iH=this.height-1; iH >= 0; --iH) { - this.weights.push(this.approximateGradient(iW, iH, 1) + 1.0); - } + for (let iH=0; iH < this.height; ++iH) { + this.weights.push(this.approximateGradient(iW, iH, 1) + 1.0); } } // only need to redo the smoothing if we are using weighted smoothing