Last active
September 20, 2015 23:22
-
-
Save ryunp/4ae989a50fdd51fbab2a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
See output after code | |
-------------------------------------------------------------------------------- | |
CODE | |
-------------------------------------------------------------------------------- | |
; Author: ryunp | |
; Date: 09/20/15 | |
; Description: Since internal pixel calculations are be fractional, certain x,y | |
; locations seem inconsistant after rounding. Without much thought positions | |
; may seem rather strange and random. This is my decomposition exploration. | |
; | |
; Note: AHK index notation starts at 1 - Adjusted to 0 when necessary. | |
main() | |
return ; End Auto-Execute section | |
main() { | |
tests := {"random cells": {"width": 12.7, "height": 14.4, "pad": 4, "count": 40, "cols": 8, "rows": 5} | |
, "inventory cells": {"width": 47.4, "height": 47, "pad": 3, "count": 60, "cols": 10, "rows": 6} | |
, "tabs": {"width": 50, "height": 125.8, "pad": 3, "count": 5, "cols": 1, "rows": 5}} | |
results := [] | |
for name, settings in tests | |
results[name] := new Grid(settings) | |
output := "[" A_ScriptName "]`r`n`r`n" | |
for header, data in results | |
output .= "::: " header " :::`r`n" data.getReport() "`r`n`r`n" | |
gui, add, edit,, % output | |
gui, show | |
} | |
; Cause why not | |
class Grid { | |
__New(cells) { | |
this.cells := cells | |
} | |
; Position Calculations | |
calcPos(idx, length) { | |
return (length * idx) + (this.cells.pad * idx) | |
} | |
calcPosPrime(idx, length) { | |
return this.calcPos(idx, length) + length | |
} | |
; Length Calculations | |
adjustedLength(idx, length) { | |
start := this.calcPos(idx, length) | |
end := this.calcPosPrime(idx, length) | |
return round(end) - round(start) | |
} | |
; Single axis schema | |
getAxisWidthSchema(axis) { | |
; Determine axis info | |
axisData := this.getAxisData(axis) | |
; Build | |
loop, % axisData.size | |
{ | |
results .= Format("[{:2d}]" | |
, this.adjustedLength(A_Index - 1, axisData.length)) | |
} | |
; And that's how the news goes | |
return results | |
} | |
; Single axis schema details | |
getAxisWidthSchemaDetails(axis) { | |
seperator := "-" | |
axisData := this.getAxisData(axis) | |
;header := axisData.header | |
; Add header (Seperator line length: minus two newline characters) | |
results := Format("{:-5s} {:-10s} {:-10s} {:s}`r`n", (axisData.header)*) | |
loop, % (strlen(results) - 2) | |
results .= seperator | |
results .= "`r`n" | |
; Add each iteration | |
loop, % axisData.size | |
{ | |
idx := A_Index - 1 | |
results .= Format("{:-5i} {:-10.1f} {:-10.1f} {:d}`r`n" | |
, A_Index | |
, this.calcPos(idx, axisData.length) | |
, this.calcPosPrime(idx, axisData.length) | |
, this.adjustedLength(idx, axisData.length)) | |
} | |
; Just take it already, I was getting bored with it anyways | |
return substr(results, 1, -2) | |
} | |
; Both axis schema | |
getBothAxisSchema() { | |
xAxisData := this.getAxisData("x") | |
yAxisData := this.getAxisData("y") | |
; Add col header indent | |
results := Format("{:-4s}", "") | |
; Add col header content | |
loop, % xAxisData.size | |
results .= Format("{:-9d}" | |
, round(this.adjustedLength(A_Index - 1, xAxisData.length))) | |
results .= "`r`n" | |
; Build row | |
loop, % yAxisData.size | |
{ | |
; Save row number | |
row := A_Index | |
; Add Row header | |
results .= Format("{:-4d}" | |
, this.adjustedLength(A_Index - 1, yAxisData.length)) | |
; Add row content | |
loop, % xAxisData.size | |
{ | |
data := Format("{:d},{:d}" | |
, round(this.calcPos(A_Index - 1, xAxisData.length)) | |
, round(this.calcPos(row - 1, yAxisData.length))) | |
results .= Format("{:-9s}", data) | |
} | |
; Add row newline | |
results .= "`r`n" | |
} | |
; And that's how the news goes | |
return results | |
} | |
getAxisData(axis) { | |
; Determine axis info | |
if (axis = "x") { | |
header := ["Col", "x", "x'", "Width"] | |
length := this.cells.width | |
size := this.cells.cols | |
} else if (axis = "y") { | |
header := ["Row", "y", "y'", "Height"] | |
length := this.cells.height | |
size := this.cells.rows | |
} | |
return {"header": header, "length": length, "size": size} | |
} | |
getReport() { | |
return ("Settings`r`n" | |
. "rows=" this.cells.rows ", cols=" this.cells.cols "`r`n" | |
. "width=" this.cells.width ", height= " this.cells.height "`r`n" | |
. "count=" this.cells.count ", pad=" this.cells.pad "`r`n" | |
. "`r`n" | |
. "Col Schema Details`r`n" | |
. this.getAxisWidthSchemaDetails("x") "`r`n" | |
. "`r`n" | |
. this.getAxisWidthSchema("x") "`r`n" | |
. "`r`n" | |
. "`r`n" | |
. "Row Schema Details`r`n" | |
. this.getAxisWidthSchemaDetails("y") "`r`n" | |
. "`r`n" | |
. this.getAxisWidthSchema("y") "`r`n" | |
. "`r`n" | |
. "Table with rounded Width/Height and X,Y origins`r`n" | |
. this.getBothAxisSchema()) | |
} | |
} | |
-------------------------------------------------------------------------------- | |
OUTPUT | |
-------------------------------------------------------------------------------- | |
[inventory_cell_inconsistency.ahk] | |
::: inventory cells ::: | |
Settings | |
rows=6, cols=10 | |
width=47.4, height= 47 | |
count=60, pad=3 | |
Col Schema Details | |
Col x x' Width | |
--------------------------------- | |
1 0.0 47.4 47 | |
2 50.4 97.8 48 | |
3 100.8 148.2 47 | |
4 151.2 198.6 48 | |
5 201.6 249.0 47 | |
6 252.0 299.4 47 | |
7 302.4 349.8 48 | |
8 352.8 400.2 47 | |
9 403.2 450.6 48 | |
10 453.6 501.0 47 | |
[47][48][47][48][47][47][48][47][48][47] | |
Row Schema Details | |
Row y y' Height | |
---------------------------------- | |
1 0.0 47.0 47 | |
2 50.0 97.0 47 | |
3 100.0 147.0 47 | |
4 150.0 197.0 47 | |
5 200.0 247.0 47 | |
6 250.0 297.0 47 | |
[47][47][47][47][47][47] | |
Table with rounded Width/Height and X,Y origins | |
47 48 47 48 47 47 48 47 48 47 | |
47 0,0 50,0 101,0 151,0 202,0 252,0 302,0 353,0 403,0 454,0 | |
47 0,50 50,50 101,50 151,50 202,50 252,50 302,50 353,50 403,50 454,50 | |
47 0,100 50,100 101,100 151,100 202,100 252,100 302,100 353,100 403,100 454,100 | |
47 0,150 50,150 101,150 151,150 202,150 252,150 302,150 353,150 403,150 454,150 | |
47 0,200 50,200 101,200 151,200 202,200 252,200 302,200 353,200 403,200 454,200 | |
47 0,250 50,250 101,250 151,250 202,250 252,250 302,250 353,250 403,250 454,250 | |
::: random cells ::: | |
Settings | |
rows=5, cols=8 | |
width=12.7, height= 14.4 | |
count=40, pad=4 | |
Col Schema Details | |
Col x x' Width | |
--------------------------------- | |
1 0.0 12.7 13 | |
2 16.7 29.4 12 | |
3 33.4 46.1 13 | |
4 50.1 62.8 13 | |
5 66.8 79.5 13 | |
6 83.5 96.2 12 | |
7 100.2 112.9 13 | |
8 116.9 129.6 13 | |
[13][12][13][13][13][12][13][13] | |
Row Schema Details | |
Row y y' Height | |
---------------------------------- | |
1 0.0 14.4 14 | |
2 18.4 32.8 15 | |
3 36.8 51.2 14 | |
4 55.2 69.6 15 | |
5 73.6 88.0 14 | |
[14][15][14][15][14] | |
Table with rounded Width/Height and X,Y origins | |
13 12 13 13 13 12 13 13 | |
14 0,0 17,0 33,0 50,0 67,0 84,0 100,0 117,0 | |
15 0,18 17,18 33,18 50,18 67,18 84,18 100,18 117,18 | |
14 0,37 17,37 33,37 50,37 67,37 84,37 100,37 117,37 | |
15 0,55 17,55 33,55 50,55 67,55 84,55 100,55 117,55 | |
14 0,74 17,74 33,74 50,74 67,74 84,74 100,74 117,74 | |
::: tabs ::: | |
Settings | |
rows=5, cols=1 | |
width=50, height= 125.8 | |
count=5, pad=3 | |
Col Schema Details | |
Col x x' Width | |
--------------------------------- | |
1 0.0 50.0 50 | |
[50] | |
Row Schema Details | |
Row y y' Height | |
---------------------------------- | |
1 0.0 125.8 126 | |
2 128.8 254.6 126 | |
3 257.6 383.4 125 | |
4 386.4 512.2 126 | |
5 515.2 641.0 126 | |
[126][126][125][126][126] | |
Table with rounded Width/Height and X,Y origins | |
50 | |
126 0,0 | |
126 0,129 | |
125 0,258 | |
126 0,386 | |
126 0,515 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment