Created
May 4, 2021 21:22
-
-
Save echeipesh/ca9ac3064847c08cd8ffc22d5c670162 to your computer and use it in GitHub Desktop.
Border Class
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
/** | |
* Tracks which border are present | |
*/ | |
class Border(val underlying: Int) extends AnyVal { | |
def remove(other: Border): Border = new Border(~other.underlying & underlying) | |
def add(other: Border): Border = new Border(other.underlying | underlying) | |
def hasTop: Boolean = ((underlying) & 1) == 1 | |
def hasLeft: Boolean = ((underlying >>> 1) & 1) == 1 | |
def hasRight: Boolean = ((underlying >>> 2) & 1) == 1 | |
def hasBottom: Boolean = ((underlying >>> 3) & 1) == 1 | |
override def toString: String = underlying match { | |
case 0 => "Mid" | |
case 15 => "All" | |
case 1 => "Top" | |
case 2 => "Left" | |
case 3 => "Top-Left" | |
case 4 => "Right" | |
case _ => ??? | |
} | |
} | |
object Border { | |
final val TOP = new Border(1) | |
final val LEFT = new Border(2) | |
final val RIGHT = new Border(4) | |
final val BOTTOM = new Border(8) | |
final val ALL = new Border(15) | |
final val NONE = new Border(0) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment