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

Martomate / TriPaint / 9275511596

28 May 2024 07:51PM UTC coverage: 29.682% (+1.8%) from 27.877%
9275511596

push

github

Martomate
Updated to Scala 3.4 and MUnit 1.0

2 of 11 new or added lines in 9 files covered. (18.18%)

430 existing lines in 38 files now uncovered.

401 of 1351 relevant lines covered (29.68%)

0.3 hits per line

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

0.0
/src/main/scala/tripaint/view/image/TriImageCanvas.scala
1
package tripaint.view.image
2

3
import tripaint.model.Color
4
import tripaint.model.coords.TriangleCoords
5
import tripaint.model.image.ImageStorage
6

7
import javafx.scene.image.PixelFormat
8
import scalafx.scene.canvas.Canvas
9

10
class TriImageCanvas(init_width: Double, imageSize: Int)
UNCOV
11
    extends Canvas(init_width, init_width * Math.sqrt(3) / 2) {
×
12

13
  private val coordsToRealConverter =
UNCOV
14
    new TriangleCoordsToReal(imageSize, (xx, yy) => (xx * width(), yy * height()))
×
15

16
  def setCanvasSize(width: Double): Unit = {
×
17
    this.width = width
×
UNCOV
18
    this.height = width * Math.sqrt(3) / 2
×
19
  }
20

UNCOV
21
  def setCanvasLocationUsingCenter(centerX: Double, centerY: Double): Unit = {
×
22
    // adjustment caused by canvas center not being the wanted rotation center (i.e. the centroid)
23
    val adjLen = this.height() / 6
×
24
    val angle = this.rotate() / 180 * math.Pi
×
25
    val dx = -adjLen * math.sin(angle)
×
26
    val dy = -adjLen * math.cos(angle)
×
UNCOV
27
    this.relocate(centerX - this.width() / 2 + dx, centerY - this.height() / 2 + dy)
×
28
  }
29

30
  def clearCanvas(): Unit = {
×
UNCOV
31
    graphicsContext2D.clearRect(-1, -1, width() + 1, height() + 1)
×
32
  }
33

34
  def drawTriangle(coords: TriangleCoords, color: Color, pixels: ImageStorage): Unit = {
×
35
    val gc = graphicsContext2D
×
UNCOV
36
    val indexMap = new IndexMap(imageSize)
×
37

UNCOV
38
    val (xLo, yLo, xHi, yHi) = triangleBoundingRect(coords)
×
39

40
    for y <- yLo.toInt - 1 to yHi.toInt + 1 do {
×
41
      for x <- xLo.toInt - 1 to xHi.toInt + 1 do {
×
42
        val c = indexMap.coordsAt(x / width(), y / height())
×
43
        if c != null then {
×
44
          val col = if c == coords then color else pixels.getColor(c)
×
UNCOV
45
          gc.pixelWriter.setColor(x, y, col.toFXColor)
×
UNCOV
46
        }
×
47
      }
48
    }
49
  }
50

51
  def redraw(pixels: ImageStorage): Unit = {
×
52
    val gc = graphicsContext2D
×
UNCOV
53
    val indexMap = new IndexMap(imageSize)
×
54

55
    val heightInt = height().toInt
×
UNCOV
56
    val widthInt = width().toInt
×
57

UNCOV
58
    val image = new Array[Int](16 * 16)
×
59

60
    for yc <- 0 until heightInt by 16 do {
×
61
      val h = Math.min(heightInt - yc, 16)
×
62
      for xc <- 0 until widthInt by 16 do {
×
UNCOV
63
        val w = Math.min(widthInt - xc, 16)
×
64

UNCOV
65
        for dy <- 0 until h do {
×
66
          val y = yc + dy
UNCOV
67
          for dx <- 0 until w do {
×
68
            val x = xc + dx
69

70
            val coords = indexMap.coordsAt(x.toDouble / widthInt, y.toDouble / heightInt)
×
71
            val col = if coords != null then pixels.getColor(coords).withAlpha(1).toInt else 0
×
UNCOV
72
            image(dx + dy * 16) = col
×
73
          }
74
        }
75

UNCOV
76
        gc.getPixelWriter.setPixels(xc, yc, w, h, PixelFormat.getIntArgbInstance, image, 0, 16)
×
77
      }
78
    }
79
  }
80

81
  private def triangleBoundingRect(coords: TriangleCoords): (Double, Double, Double, Double) = {
×
UNCOV
82
    val (px, py) = coordsToRealConverter.triangleCornerPoints(coords)
×
83

84
    var xLo, yLo = 1.0e9
85
    var xHi, yHi = 0.0
86

87
    for i <- 0 until 3 do {
×
88
      val x = px(i)
×
UNCOV
89
      val y = py(i)
×
90

91
      if x < xLo then xLo = x
×
92
      if y < yLo then yLo = y
×
93
      if x > xHi then xHi = x
×
UNCOV
94
      if y > yHi then yHi = y
×
95
    }
96

97
    (xLo, yLo, xHi, yHi)
98
  }
99
}
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

© 2025 Coveralls, Inc