-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from Martomate/develop
Release 1.1
- Loading branch information
Showing
78 changed files
with
2,386 additions
and
1,383 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Use container-based infrastructure | ||
sudo: false | ||
|
||
# These directories are cached to S3 at the end of the build | ||
cache: | ||
directories: | ||
- $HOME/.ivy2/cache | ||
- $HOME/.sbt | ||
|
||
before_cache: | ||
# Cleanup the cached directories to avoid unnecessary cache updates | ||
- find $HOME/.ivy2/cache -name "ivydata-*.properties" -print -delete | ||
- find $HOME/.sbt -name "*.lock" -print -delete | ||
|
||
language: scala | ||
scala: | ||
- 2.12.6 | ||
script: | ||
- sbt coverage test coverageReport coveralls |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# TriPaint | ||
Like Paint, but for images with triangular pixels | ||
|
||
[](https://travis-ci.org/Martomate/TriPaint) | ||
[](https://coveralls.io/github/Martomate/TriPaint?branch=master) |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.5.1") | ||
addSbtPlugin("org.scoverage" % "sbt-coveralls" % "1.2.2") | ||
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.3.5") |
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
This file was deleted.
Oops, something went wrong.
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
This file was deleted.
Oops, something went wrong.
44 changes: 44 additions & 0 deletions
44
src/main/scala/com/martomate/tripaint/InjectiveHashMap.scala
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.martomate.tripaint | ||
|
||
import scala.collection.mutable | ||
|
||
class InjectiveHashMap[L, R] extends InjectiveMap[L, R] { | ||
private val leftToRight: mutable.Map[L, R] = mutable.Map.empty | ||
private val rightToLeft: mutable.Map[R, L] = mutable.Map.empty | ||
|
||
override def getRight(left: L): Option[R] = leftToRight.get(left) | ||
|
||
override def getLeft(right: R): Option[L] = rightToLeft.get(right) | ||
|
||
override def set(left: L, right: R): Boolean = { | ||
val newMapping = !getRight(left).contains(right) | ||
if (newMapping) { | ||
removeLeft(left) | ||
removeRight(right) | ||
leftToRight.put(left, right) | ||
rightToLeft.put(right, left) | ||
} | ||
newMapping | ||
} | ||
|
||
override def containsLeft(left: L): Boolean = leftToRight.contains(left) | ||
|
||
override def containsRight(right: R): Boolean = rightToLeft.contains(right) | ||
|
||
override def removeRight(right: R): Boolean = { | ||
val l = getLeft(right) | ||
l.foreach(left => removeUnchecked(left, right)) | ||
l.isDefined | ||
} | ||
|
||
override def removeLeft(left: L): Boolean = { | ||
val r = getRight(left) | ||
r.foreach(right => removeUnchecked(left, right)) | ||
r.isDefined | ||
} | ||
|
||
private def removeUnchecked(left: L, right: R): Unit = { | ||
leftToRight.remove(left) | ||
rightToLeft.remove(right) | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.martomate.tripaint | ||
|
||
/** | ||
* An `InjectiveMap` is like a bidirectional Map with both unique keys and unique values. | ||
* This makes the mapping injective.<br /> | ||
* It can be seen as a collection of pairs `(l, r)` where both l and r can be used to find, update and remove the mappings.<br /> | ||
* If you call e.g. `removeLeft(l)`, then the pair `(l, r)` will be removed (which means that r is removed too, and since | ||
* it doesn't exist in any other pair it is no longer present in this map).<br /> | ||
* | ||
* @tparam L The Left type | ||
* @tparam R The Right type | ||
* | ||
*/ | ||
trait InjectiveMap[L, R] { | ||
def getRight(left: L): Option[R] | ||
def getLeft(right: R): Option[L] | ||
|
||
def set(left: L, right: R): Boolean | ||
|
||
def containsLeft(left: L): Boolean | ||
def containsRight(right: R): Boolean | ||
|
||
def removeRight(right: R): Boolean | ||
def removeLeft(left: L): Boolean | ||
} | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.martomate.tripaint | ||
|
||
import scala.collection.mutable.ArrayBuffer | ||
|
||
/** | ||
* Like Observable but with custom listener class | ||
* | ||
* @tparam L the listener trait/interface | ||
*/ | ||
trait Listenable[L] { | ||
private val listeners: ArrayBuffer[L] = ArrayBuffer.empty | ||
final def addListener(listener: L): Unit = listeners += listener | ||
final def removeListener(listener: L): Unit = listeners -= listener | ||
|
||
final protected def notifyListeners(func: L => Unit): Unit = listeners.foreach(func) | ||
} |
Oops, something went wrong.