• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Scala-Robotics-Simulator / PPS-22-srs / #115

27 Jul 2025 01:52PM UTC coverage: 63.061% (+14.0%) from 49.091%
#115

Pull #12

github

davidcohenDC
refactor: reorder import statements in LightStateTest
Pull Request #12: feat: control the diffusion of the lights on the enviroment

257 of 395 new or added lines in 22 files covered. (65.06%)

4 existing lines in 2 files now uncovered.

309 of 490 relevant lines covered (63.06%)

9.02 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/main/scala/io/github/srs/controller/ControllerModule.scala
1
package io.github.srs.controller
2

3
import io.github.srs.model.Cell
4
import io.github.srs.model.entity.Orientation
5
import io.github.srs.model.entity.staticentity.StaticEntity.{ Light, Obstacle }
6
import io.github.srs.model.environment.Environment
7
import io.github.srs.model.lighting.{ LightState, ShadowFovDiffuser }
8
import io.github.srs.view.ViewModule
9

10
object ControllerModule:
11

×
12
  /** Public controller interface */
13
  trait Controller:
14
    def start(): Unit
×
15

16
  /** Will be mixed in by the launcher to provide a `controller` */
17
  trait Provider:
18
    val controller: Controller
19

20
  /** The dependencies this module needs: a View and a Model */
21
  type Requirements = ViewModule.Provider & io.github.srs.model.ModelModule.Provider
22

23
  /** The implementation */
24
  trait Component:
25
    context: Requirements =>
×
26

×
27
    object Controller:
28
      def apply(): Controller = new ControllerImpl
×
29

×
30
      private class ControllerImpl extends Controller:
31

×
32
        def start(): Unit =
33
          context.view.init()
×
NEW
34
          showLightMap()
×
NEW
35

×
36
        private def showLightMap(): Unit =
NEW
37
          import io.github.srs.model.environment.view
×
38
          import io.github.srs.model.entity.Point2D.toCell
39

40
          // 1) build & validate environment
41
          val env = Environment(
NEW
42
            width = 10,
×
NEW
43
            height = 10,
×
NEW
44
            entities = Set(
×
NEW
45
              Obstacle((2.0, 1.0), Orientation(0), 1, 1),
×
NEW
46
              Obstacle((2.0, 2.0), Orientation(0), 1, 1),
×
NEW
47
              Obstacle((6.0, 4.0), Orientation(0), 1, 1),
×
NEW
48
              Light((0.0, 0.0), Orientation(0), 8.0, intensity = 1.0, attenuation = 0.2),
×
NEW
49
              Light((9.0, 9.0), Orientation(0), 2.0, intensity = 1.0, attenuation = 0.2),
×
NEW
50
            ),
×
NEW
51
          ).fold(err => sys.error(err.errorMessage), identity)
×
NEW
52

×
53
          val view = env.view
NEW
54
          val diffuser = ShadowFovDiffuser()
×
NEW
55
          val lightInit = LightState.empty(view.width, view.height)
×
NEW
56
          val lightMap = diffuser.step(view)(lightInit)
×
NEW
57

×
58
          val obstacles = env.entities.collect { case Obstacle((x, y), _, w, h) =>
NEW
59
            f"(${x}%.2f, ${y}%.2f)  size=${w}×$h"
×
NEW
60
          }.toVector
×
NEW
61

×
62
          val lights = env.entities.collect { case Light((x, y), _, r, i, k) =>
NEW
63
            f"(${x}%.2f, ${y}%.2f)  r=$r%.1f  I=$i%.1f  k=$k%.2f"
×
NEW
64
          }.toVector
×
NEW
65

×
66
          val header =
67
            s"""|Grid      : ${env.width}×${env.height}
NEW
68
                |
×
69
                |Obstacles : ${obstacles.size}
NEW
70
                |${obstacles.map("  • " + _).mkString("\n")}
×
NEW
71
                |
×
72
                |Lights    : ${lights.size}
NEW
73
                |${lights.map("  • " + _).mkString("\n")}
×
NEW
74
                |
×
75
                |Legend
76
                |  #  obstacle
77
                |  L  light source
78
                |  .░▒▓█  darkest → brightest
79
                |
80
                |""".stripMargin
NEW
81

×
82
          val asciiRaw = lightMap.render(view)
NEW
83
          val numeric = lightMap.render(view, ascii = false)
×
NEW
84

×
85
          val lightCells = view.lights.map(_.position.toCell).toSet
NEW
86
          val ascii = overlayLights(asciiRaw, lightCells)
×
NEW
87

×
88
          context.view.plotData(
NEW
89
            header +
×
NEW
90
              ascii + "\n\n" +
×
NEW
91
              numeric,
×
NEW
92
          )
×
NEW
93

×
94
        end showLightMap
95

96
        /** Replace the shade‐char at each light‐cell with 'L' */
97
        private def overlayLights(ascii: String, lights: Set[Cell]): String =
NEW
98
          ascii.linesIterator.zipWithIndex.map { case (line, y) =>
×
NEW
99
            line.zipWithIndex.map { case (ch, x) =>
×
100
              if lights.contains(Cell(x, y)) then 'L' else ch
101
            }.mkString
102
          }
NEW
103
            .mkString("\n")
×
NEW
104

×
105
      end ControllerImpl
106

107
    end Controller
108

109
  end Component
110

111
  /** Glue the provider + component together */
112
  trait Interface extends Provider with Component:
113
    self: Requirements =>
114
end ControllerModule
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc