Skip to content

Commit

Permalink
Fix some failing tests and fail some more
Browse files Browse the repository at this point in the history
  • Loading branch information
IdreesInc committed Feb 9, 2024
1 parent f86a591 commit 59dbcb1
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 13 deletions.
53 changes: 41 additions & 12 deletions src/miracode.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,23 +145,17 @@ def generateEdges(pixels, drawDiagonals = True):
if pixels[row][col] == 1:
# Check if there is a pixel to the right
if col < numOfCols - 1 and pixels[row][col + 1] == 1:
if drawDiagonals and get(pixels, row + 1, col) == 1 and get(pixels, row - 1, col + 2) == 1:
# Disallowed (W)
# 1 0 1
# X 1 0
# 1 0 0
pass
elif drawDiagonals and get(pixels, row - 1, col - 1) == 1 and get(pixels, row + 1, col + 1) == 1:
# Disallowed
# 1 0 1
# 0 X 1
# 0 0 1
if drawDiagonals and ignoreRight(pixels, row, col):
pass
else:
edges.append(((col, row), (col + 1, row)))
# Check if there is a pixel below
if row < numOfRows - 1 and pixels[row + 1][col] == 1:
edges.append(((col, row), (col, row + 1)))
if drawDiagonals and ignoreDown(pixels, row, col):
pass
else:
edges.append(((col, row), (col, row + 1)))
# Check diagonals
if not drawDiagonals:
continue
# Check if there is a pixel to the bottom right
Expand All @@ -174,6 +168,40 @@ def generateEdges(pixels, drawDiagonals = True):
edges.append(((col, row), (col - 1, row + 1)))
return edges

def ignoreRight(pixels, row, col):
if get(pixels, row + 1, col) == 1 and get(pixels, row - 1, col + 2) == 1:
# Disallowed (W)
# 1 0 1
# X 1 0
# 1 0 0
return True
elif get(pixels, row - 1, col - 1) == 1 and get(pixels, row + 1, col + 1) == 1:
# Disallowed
# 1 0 1
# 0 X 1
# 0 0 1
return True
return False

def ignoreDown(pixels, row, col):
if (get(pixels, row, col - 1) == 1 and get(pixels, row + 1, col - 1) == 0 and get(pixels, row + 2, col + 1) == 1) or (get(pixels, row, col + 1) == 1 and get(pixels, row + 1, col + 1) == 0 and get(pixels, row + 2, col - 1) == 1):
# Disallowed (z top)
# 1 X 1
# 0 1 0
# 1 0 0
return True
elif get(pixels, row - 1, col) != 1 and (get(pixels, row - 1, col - 2) != 1 and get(pixels, row - 1, col - 1) == 1 and get(pixels, row, col - 1) == 0 and get(pixels, row + 1, col + 1) == 1) or (get(pixels, row - 1, col + 2) != 1 and get(pixels, row - 1, col + 1) == 1 and get(pixels, row, col + 1) == 0 and get(pixels, row + 1, col - 1) == 1):
# Disallowed (z bottom)
# 0 0 1
# 0 X 0
# 1 1 1
# Allowed (f)
# 0 0 1 1
# 0 X 0 0
# 1 1 1 0
return True
return False

def ignoreDiagonal(pixels, row , col, flipped):
colMod = -1 if flipped else 1
if get(pixels, row + 1, col) == 1 and (get(pixels, row - 1, col - colMod) != 1 or get(pixels, row + 2, col) == 1) and (get(pixels, row + 2, col + 2 * colMod) != 1 or get(pixels, row, col + 2 * colMod) == 1):
Expand Down Expand Up @@ -420,3 +448,4 @@ def drawCharacter(character, glyph, pen, xOffset = 0):
else:
generateFont()
generateExamples(characters, ligatures, charactersByCodepoint)
test()
43 changes: 42 additions & 1 deletion src/tests.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@
},
{
"name": "z",
"comment": "TODO: Likely want to change this in the future",
"input": [
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
Expand Down Expand Up @@ -126,6 +125,48 @@
[2, 0, 0, 0, 2],
[1, 0, 0, 0, 1]
]
},
{
"name": "l",
"input": [
[0, 1, 1, 0, 0],
[0, 0, 1, 0, 0],
[0, 0, 1, 0, 0],
[0, 0, 1, 0, 0],
[0, 0, 1, 0, 0],
[0, 0, 1, 0, 0],
[0, 0, 0, 1, 1]
],
"output": [
[0, 1, 2, 0, 0],
[0, 0, 2, 0, 0],
[0, 0, 2, 0, 0],
[0, 0, 2, 0, 0],
[0, 0, 2, 0, 0],
[0, 0, 2, 0, 0],
[0, 0, 0, 2, 1]
]
},
{
"name": "0",
"input": [
[0, 1, 1, 1, 0],
[1, 0, 0, 0, 1],
[1, 0, 0, 1, 1],
[1, 0, 1, 0, 1],
[1, 1, 0, 0, 1],
[1, 0, 0, 0, 1],
[0, 1, 1, 1, 0]
],
"output": [
[0, 2, 2, 2, 0],
[2, 0, 0, 0, 3],
[2, 0, 0, 2, 2],
[2, 0, 2, 0, 2],
[2, 2, 0, 0, 2],
[3, 0, 0, 0, 2],
[0, 2, 2, 2, 0]
]
}
]
}

0 comments on commit 59dbcb1

Please sign in to comment.