• 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/ImageGridCanvas.scala
1
package tripaint.view.image
2

3
import tripaint.model.{Color, ImageGrid}
4
import tripaint.model.coords.{GlobalPixCoords, PixelCoords}
5
import tripaint.model.image.RegularImage
6

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

UNCOV
10
class ImageGridCanvas(images: ImageGrid) extends Canvas {
×
11
  private var scale: Double = 1
12
  private var displacement: (Double, Double) = (0, 0)
13

UNCOV
14
  def setScale(scale: Double): Unit = {
×
15
    this.scale = scale
16
  }
17

UNCOV
18
  def setDisplacement(dx: Double, dy: Double): Unit = {
×
19
    this.displacement = (dx, dy)
20
  }
21

22
  def coordsAt(x: Double, y: Double): GlobalPixCoords = {
×
UNCOV
23
    val (xScroll, yScroll) = this.displacement
×
24

25
    val yy = -(y - yScroll - height() / 2) / this.scale / Math.sqrt(3)
×
UNCOV
26
    val xx = ((x - xScroll - width() / 2) / this.scale - yy) / 2
×
27

28
    val xInt = Math.floor(xx).toInt
×
UNCOV
29
    val yInt = Math.floor(yy).toInt
×
30

UNCOV
31
    if xx - xInt.toDouble > 1 - (yy - yInt.toDouble) then {
×
32
      GlobalPixCoords(xInt * 2 + 1, yInt)
UNCOV
33
    } else {
×
34
      GlobalPixCoords(xInt * 2, yInt)
35
    }
36
  }
37

38
  /** locationOf is the inverse of the coordsAt function */
39
  def locationOf(coords: GlobalPixCoords): (Double, Double) = {
×
UNCOV
40
    val (xScroll, yScroll) = this.displacement
×
41

UNCOV
42
    val (xInt, yInt) = (Math.floorDiv(coords.x, 2), coords.y)
×
43
    val (xx, yy) = (xInt + 0.5, yInt + 0.5)
44

45
    val y = -yy * Math.sqrt(3) * this.scale + height() / 2 + yScroll
×
UNCOV
46
    val x = (xx * 2 + yy) * this.scale + width() / 2 + xScroll
×
47

48
    (x, y)
49
  }
50

51
  def redraw(): Unit = {
×
52
    val w = width().toInt
×
UNCOV
53
    val h = height().toInt
×
54

UNCOV
55
    redraw(0, 0, w, h)
×
56
  }
57

58
  def redraw(startX: Int, startY: Int, w: Int, h: Int): Unit = {
×
UNCOV
59
    if images.imageSize < 0 then {
×
60
      // This "hack" is needed right at the beginning before the user has specified the size
61
      return
UNCOV
62
    }
×
63

UNCOV
64
    val buffer = RegularImage.ofSize(w, h)
×
65

66
    for y <- startY until (startY + h) do {
×
67
      for x <- startX until (startX + w) do {
×
68
        val coords = PixelCoords(this.coordsAt(x, y), images.imageSize)
×
69
        val col = images(coords.image) match {
×
70
          case Some(image) => image.storage.getColor(coords.pix)
×
UNCOV
71
          case None        => Color(0, 0, 0, 0)
×
72
        }
UNCOV
73
        buffer.setColor(x - startX, y - startY, col)
×
74
      }
75
    }
76

77
    val f = PixelFormat.getIntArgbInstance
×
UNCOV
78
    graphicsContext2D.pixelWriter.setPixels(startX, startY, w, h, f, buffer.toIntArray, 0, w)
×
79
  }
80
}
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