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

Martomate / TriPaint / 8896742719

30 Apr 2024 02:39PM UTC coverage: 27.877% (+0.3%) from 27.558%
8896742719

push

github

Martomate
Fixed major performance issue

4 of 6 new or added lines in 1 file covered. (66.67%)

40 existing lines in 5 files now uncovered.

373 of 1338 relevant lines covered (27.88%)

0.28 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

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

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

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

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

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

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

×
31
    if xx - xInt.toDouble > 1 - (yy - yInt.toDouble) then {
32
      GlobalPixCoords(xInt * 2 + 1, yInt)
×
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) = {
×
40
    val (xScroll, yScroll) = this.displacement
41

×
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
×
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
×
53
    val h = height().toInt
54

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

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

×
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)
×
71
          case None        => Color(0, 0, 0, 0)
UNCOV
72
        }
×
73
        buffer.setColor(x - startX, y - startY, col)
74
      }
75
    }
UNCOV
76

×
77
    val f = PixelFormat.getIntArgbInstance
×
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