Skip to content

Commit

Permalink
Normalize some spaces and tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
Gaming32 committed Jul 3, 2021
1 parent fd87546 commit 318d784
Show file tree
Hide file tree
Showing 78 changed files with 3,192 additions and 3,153 deletions.
39 changes: 39 additions & 0 deletions space_tab_verify.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import os


def count_spaces_tabs(path):
try:
with open(path, encoding='utf-8') as fp:
content = fp.read()
except UnicodeDecodeError:
print(f'Unable to decode {path}. Skipping...')
return None, None
spaces = content.count(' ')
tabs = content.count('\t')
return spaces, tabs


def print_spaces_tabs(path, spaces, tabs, force=False):
if not force and (spaces == 0 or tabs == 0):
return
total = spaces + tabs
percent_spaces = round(spaces / total * 100, 1)
percent_tabs = round(tabs / total * 100, 1)
if tabs > spaces:
print(f'{path} has {percent_tabs:.1f}% tabs/{percent_spaces:.1f}% spaces ({tabs}/{spaces})')
else:
print(f'{path} has {percent_spaces:.1f}% spaces/{percent_tabs:.1f}% tabs ({spaces}/{tabs})')


def main():
for (cur, dirs, files) in os.walk('src'):
for file in files:
file = os.path.join(cur, file)
spaces, tabs = count_spaces_tabs(file)
if spaces is None:
continue
print_spaces_tabs(file, spaces, tabs)


if __name__ == '__main__':
main()
154 changes: 77 additions & 77 deletions src/main/ArrayVisualizer.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ final public class ArrayVisualizer {

final int[] array;
final int[] stabilityTable;
final int[] indexTable;
final int[] indexTable;
final ArrayList<int[]> arrays;

private SortPair[] AllSorts; // First row of Comparison/DistributionSorts arrays consists of class names
Expand Down Expand Up @@ -300,11 +300,11 @@ public void run() {
this.array = new int[this.MAX_ARRAY_VAL];
this.stabilityTable = new int[this.MAX_ARRAY_VAL];
this.indexTable = new int[this.MAX_ARRAY_VAL];
this.sortLength = this.MAX_ARRAY_VAL;
this.resetStabilityTable();
this.resetIndexTable();
this.sortLength = this.MAX_ARRAY_VAL;
this.resetStabilityTable();
this.resetIndexTable();
this.arrays = new ArrayList<>();
this.arrays.add(this.array);

Expand Down Expand Up @@ -397,7 +397,7 @@ public void run() {
int coltmp = 255;

ArrayVisualizer.this.visualClasses = new Visual[15];
ArrayVisualizer.this.visualClasses[0] = new BarGraph(ArrayVisualizer.this);
ArrayVisualizer.this.visualClasses[1] = new Rainbow(ArrayVisualizer.this);
ArrayVisualizer.this.visualClasses[2] = new DisparityBarGraph(ArrayVisualizer.this);
Expand All @@ -408,11 +408,11 @@ public void run() {
ArrayVisualizer.this.visualClasses[7] = new ScatterPlot(ArrayVisualizer.this);
ArrayVisualizer.this.visualClasses[8] = new WaveDots(ArrayVisualizer.this);
ArrayVisualizer.this.visualClasses[9] = new CustomImage(ArrayVisualizer.this);
ArrayVisualizer.this.visualClasses[10] = new SineWave(ArrayVisualizer.this);
ArrayVisualizer.this.visualClasses[11] = new HoopStack(ArrayVisualizer.this);
ArrayVisualizer.this.visualClasses[12] = new PixelMesh(ArrayVisualizer.this);
ArrayVisualizer.this.visualClasses[13] = new Spiral(ArrayVisualizer.this);
ArrayVisualizer.this.visualClasses[14] = new SpiralDots(ArrayVisualizer.this);
ArrayVisualizer.this.visualClasses[10] = new SineWave(ArrayVisualizer.this);
ArrayVisualizer.this.visualClasses[11] = new HoopStack(ArrayVisualizer.this);
ArrayVisualizer.this.visualClasses[12] = new PixelMesh(ArrayVisualizer.this);
ArrayVisualizer.this.visualClasses[13] = new Spiral(ArrayVisualizer.this);
ArrayVisualizer.this.visualClasses[14] = new SpiralDots(ArrayVisualizer.this);

while(ArrayVisualizer.this.visualsEnabled) {
if (ArrayVisualizer.this.updateVisualsForced == 0) {
Expand Down Expand Up @@ -539,44 +539,44 @@ else if (this.benchmarking) {
return this.benchmarking;
}

public int getStabilityValue(int n) {
n = Math.max(0, Math.min(n, this.sortLength-1));
return this.stabilityTable[n];
}
public int getStabilityValue(int n) {
n = Math.max(0, Math.min(n, this.sortLength-1));
return this.stabilityTable[n];
}
public int[] getStabilityTable() {
return this.stabilityTable;
}
public void resetStabilityTable() {
public void resetStabilityTable() {
for(int i = 0; i < this.sortLength; i++) {
this.stabilityTable[i] = i;
}
}
public int getIndexValue(int n) {
n = Math.max(0, Math.min(n, this.sortLength-1));
return this.indexTable[n];
}
public int[] getIndexTable() {
return this.indexTable;
}
public void setIndexTable() {
public int getIndexValue(int n) {
n = Math.max(0, Math.min(n, this.sortLength-1));
return this.indexTable[n];
}
public int[] getIndexTable() {
return this.indexTable;
}
public void setIndexTable() {
for(int i = 0; i < this.sortLength; i++) {
this.indexTable[array[i]] = i;
}
}
public void resetIndexTable() {
public void resetIndexTable() {
for(int i = 0; i < this.sortLength; i++) {
this.indexTable[i] = i;
}
}
public boolean isSorted() {
return this.statSnapshot.findSegments(this.array, this.sortLength, this.REVERSED)[0] == 1;
}
Expand Down Expand Up @@ -747,7 +747,7 @@ public int getCurrentLength() {
}
public void setCurrentLength(int newLength) {
this.sortLength = newLength;
this.Delays.setSleepRatio(this.sortLength/1024d);
this.Delays.setSleepRatio(this.sortLength/1024d);
}

public void setUniqueItems(int newCount) {
Expand Down Expand Up @@ -845,23 +845,23 @@ public int windowXCoordinate() {
public int windowYCoordinate() {
return this.cy;
}
public Color getHighlightColor() {
if(this.colorEnabled()) {
if(this.analysisEnabled())
return Color.LIGHT_GRAY;
else
return Color.WHITE;
}
else {
if(this.analysisEnabled())
return Color.BLUE;
else
return Color.RED;
}
}
public Color getHighlightColor() {
if(this.colorEnabled()) {
if(this.analysisEnabled())
return Color.LIGHT_GRAY;
else
return Color.WHITE;
}
else {
if(this.analysisEnabled())
return Color.BLUE;
else
return Color.RED;
}
}

public void createVolatileImage() {
this.img = this.window.getGraphicsConfiguration().createCompatibleVolatileImage(this.cw, this.ch);
Expand Down Expand Up @@ -935,11 +935,11 @@ public int halfCircle() {
public synchronized void verifySortAndSweep() {
this.Highlights.toggleFancyFinish(true);
this.Highlights.resetFancyFinish();
this.Delays.setSleepRatio(1);

double sleepRatio = 256d/this.sortLength;
long tempComps = this.Reads.getComparisons();
long tempComps = this.Reads.getComparisons();
this.Reads.setComparisons(0);

String temp = this.heading;
Expand All @@ -948,29 +948,29 @@ public synchronized void verifySortAndSweep() {
int cmpVal = this.REVERSED ? -1 : 1;

boolean success = true, stable = true;
int idx = 0;
int idx = 0;
for(int i = 0; i < this.sortLength + this.getLogBaseTwoOfLength(); i++) {
if(i < this.sortLength) this.Highlights.markArray(1, i);
this.Highlights.incrementFancyFinishPosition();

if(i < this.sortLength - 1) {
if(stable && this.Reads.compareOriginalValues(this.array[i], this.array[i + 1]) == cmpVal) {
stable = false;
idx = i;
}
if(stable && this.Reads.compareOriginalValues(this.array[i], this.array[i + 1]) == cmpVal) {
stable = false;
idx = i;
}
if(this.Reads.compareValues(this.array[i], this.array[i + 1]) == cmpVal) {
this.Highlights.clearMark(1);

boolean tempSound = this.Sounds.isEnabled();
boolean tempSound = this.Sounds.isEnabled();
this.Sounds.toggleSound(false);
this.Highlights.toggleFancyFinish(false);

for(int j = i + 1; j < this.sortLength; j++) {
this.Highlights.markArray(j, j);
this.Delays.sleep(sleepRatio);
}
JOptionPane.showMessageDialog(this.window, "The sort was unsuccessful;\nIndices " + i + " and " + (i + 1) + " are out of order!", "Error", JOptionPane.OK_OPTION, null);
success = false;

Expand All @@ -990,21 +990,21 @@ public synchronized void verifySortAndSweep() {

// if (tempStability && success)
// JOptionPane.showMessageDialog(this.window, "This sort is stable!", "Information", JOptionPane.OK_OPTION, null);
if(this.STABILITY && success && !stable) {
boolean tempSound = this.Sounds.isEnabled();
this.Sounds.toggleSound(false);
this.Highlights.toggleFancyFinish(false);
for(int j = idx + 1; j < this.sortLength; j++) {
this.Highlights.markArray(j, j);
this.Delays.sleep(sleepRatio);
}
JOptionPane.showMessageDialog(this.window, "This sort is not stable;\nIndices " + idx + " and " + (idx + 1) + " are out of order!", "Error", JOptionPane.OK_OPTION, null);
this.Highlights.clearAllMarks();
if(this.STABILITY && success && !stable) {
boolean tempSound = this.Sounds.isEnabled();
this.Sounds.toggleSound(false);
this.Highlights.toggleFancyFinish(false);
for(int j = idx + 1; j < this.sortLength; j++) {
this.Highlights.markArray(j, j);
this.Delays.sleep(sleepRatio);
}
JOptionPane.showMessageDialog(this.window, "This sort is not stable;\nIndices " + idx + " and " + (idx + 1) + " are out of order!", "Error", JOptionPane.OK_OPTION, null);
this.Highlights.clearAllMarks();
this.Sounds.toggleSound(tempSound);
}
}

this.heading = temp;
this.Reads.setComparisons(tempComps);
Expand Down
24 changes: 12 additions & 12 deletions src/prompts/ViewPrompt.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public void reposition(){
private void initComponents() {

this.jLabel1 = new javax.swing.JLabel();
this.barGraph = new javax.swing.JButton();
this.dotGraph = new javax.swing.JButton();
this.colorCircle = new javax.swing.JButton();
Expand All @@ -89,15 +89,15 @@ private void initComponents() {
this.customImage = new javax.swing.JButton();
this.sineWave = new javax.swing.JButton();
this.waveDots = new javax.swing.JButton();
this.hoopStack = new javax.swing.JButton();
this.disparityBarGraph = new javax.swing.JButton();
this.disparityChords = new javax.swing.JButton();
this.hoopStack = new javax.swing.JButton();
this.disparityBarGraph = new javax.swing.JButton();
this.disparityChords = new javax.swing.JButton();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setResizable(false);

jLabel1.setText("Select Visual Style");
barGraph.setText("Bar Graph");
barGraph.addActionListener(new java.awt.event.ActionListener() {
@Override
Expand Down Expand Up @@ -200,16 +200,16 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
hoopStackActionPerformed(evt);
}
});
disparityBarGraph.setText("Disparity Bar Graph");
disparityBarGraph.setText("Disparity Bar Graph");
disparityBarGraph.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent evt) {
disparityBarGraphActionPerformed(evt);
}
});
disparityChords.setText("Disparity Chords");
disparityChords.setText("Disparity Chords");
disparityChords.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent evt) {
Expand Down Expand Up @@ -290,7 +290,7 @@ private void setAllFieldsFalse(){
ArrayVisualizer.toggleSpiral(false);
ArrayVisualizer.toggleWave(false);
}
private void barGraphActionPerformed(java.awt.event.ActionEvent evt) {
setAllFieldsFalse();
ArrayVisualizer.setVisual(VisualStyles.BARS);
Expand Down Expand Up @@ -401,8 +401,8 @@ private void disparityChordsActionPerformed(java.awt.event.ActionEvent evt) {
private javax.swing.JButton customImage;
private javax.swing.JButton sineWave;
private javax.swing.JButton waveDots;
private javax.swing.JButton hoopStack;
private javax.swing.JButton hoopStack;
private javax.swing.JButton disparityBarGraph;
private javax.swing.JButton disparityChords;
private javax.swing.JButton disparityChords;
private javax.swing.JLabel jLabel1;
}
Loading

0 comments on commit 318d784

Please sign in to comment.