Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- lass Point { /* some reference to the DCEL or points in general */ }
- class Face { /* some reference to the DCEL or faces in general */ }
- class ConflictGraph{
- private var setOfArcs = Set[(Point, Face)]()
- /* adds an arc to the set, with two possible options for the parameters */
- def addArc(p: Point, f: Face): Unit = setOfArcs += ((p,f))
- def addArc(a: (Point, Face)): Unit = setOfArcs += a
- /* removes an arc from the set, with two possible options for the parameters */
- def removeArc(p: Point, f: Face): Unit = setOfArcs -= ((p,f))
- def removeArc(a: (Point, Face)): Unit = setOfArcs -= a
- /* returns the list of points/faces visible from that face/point */
- def P_conflict(f: Face): List[Point] = setOfArcs.filter(_._2 == f).toList.map(_._1)
- def F_conflict(p: Point): List[Face] = setOfArcs.filter(_._1 == p).toList.map(_._2)
- /* removes all the arcs with that point */
- def removePoint(p: Point): Unit = setOfArcs --= setOfArcs.filter(_._1 == p)
- /* removes all the arcs with that face */
- def removeFace (f: Face): Unit = setOfArcs --= setOfArcs.filter(_._2 == f)
- /* adds new arcs with that point and each face */
- def addPointWithItsVisibleFaces(p: Point, l: List[Face]): Unit = l.foreach(f => setOfArcs += ((p,f)))
- /* adds new arcs with that face and each point */
- def addFaceWithItsVisiblePoints(f: Face, l: List[Point]): Unit = l.foreach(p => setOfArcs += ((p,f)))
- override def toString: String = setOfArcs.toString
- }
- class Test{
- private var setOfArcs = Set[(Int, String)]()
- def addArc(p: Int, f: String): Unit = setOfArcs += ((p,f))
- def addArc(a: (Int, String)): Unit = setOfArcs += a
- def removeArc(p: Int, f: String): Unit = setOfArcs -= ((p,f))
- def removeArc(a: (Int, String)): Unit = setOfArcs -= a
- def P_conflict(f: String): List[Int] = setOfArcs.filter(_._2 == f).toList.map(_._1)
- def F_conflict(p: Int): List[String] = setOfArcs.filter(_._1 == p).toList.map(_._2)
- def removeInt(p: Int): Unit = setOfArcs --= setOfArcs.filter(_._1 == p)
- def removeString (f: String): Unit = setOfArcs --= setOfArcs.filter(_._2 == f)
- def addIntWithItsVisibleStrings(p: Int, l: List[String]): Unit = l.foreach(f => setOfArcs += ((p,f)))
- def addStringWithItsVisibleInts(f: String, l: List[Int]): Unit = l.foreach(p => setOfArcs += ((p,f)))
- override def toString: String = setOfArcs.toString
- }
- object Main {
- def main(args: Array[String]) {
- val test = new Test
- test.addArc(1, "a")
- test.addArc(1, "a") // added only once
- test.addArc(2, "b")
- test.addArc((2, "c"))
- println(test)
- test.removeArc(999, "zzz") // no problem if I try to remove an inexistent item
- println(test)
- test.removeInt(2)
- println(test)
- test.addIntWithItsVisibleStrings(3, List("d","e"))
- println(test)
- test.addStringWithItsVisibleInts("f", List(4,5))
- println(test)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement