• 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

87.72
/src/main/scala/tripaint/model/image/RegularImage.scala
1
package tripaint.model.image
2

3
import tripaint.model.Color
4
import tripaint.model.coords.StorageCoords
5

6
import java.awt.image.BufferedImage
7
import java.util
8

9
class RegularImage private (val width: Int, val height: Int, private val pixels: Array[Int]) {
10
  def getColor(x: Int, y: Int): Color =
1✔
11
    require(x >= 0)
1✔
12
    require(y >= 0)
1✔
13
    require(x < width)
1✔
14
    require(y < height)
1✔
15

16
    Color.fromInt(pixels(x + y * width))
1✔
17

18
  def setColor(x: Int, y: Int, color: Color): Unit =
1✔
19
    require(x >= 0)
1✔
20
    require(y >= 0)
1✔
21
    require(x < width)
1✔
22
    require(y < height)
1✔
23

24
    pixels(x + y * width) = color.toInt
1✔
25

26
  def pasteImage(offset: StorageCoords, image: RegularImage): Unit =
1✔
27
    require(offset.x + image.width <= width)
1✔
28
    require(offset.y + image.height <= height)
1✔
29

30
    for
1✔
31
      dy <- 0 until image.height
1✔
32
      dx <- 0 until image.width
1✔
33
    do pixels(offset.x + dx + (offset.y + dy) * width) = image.pixels(dx + dy * image.width)
1✔
34

35
  def toBufferedImage: BufferedImage =
1✔
36
    val image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB)
1✔
37
    image.setRGB(0, 0, width, height, pixels, 0, width)
1✔
38
    image
39

UNCOV
40
  def toIntArray: Array[Int] = pixels.clone()
×
41

42
  override def equals(obj: Any): Boolean = obj match
1✔
43
    case other: RegularImage =>
1✔
44
      if width == other.width && height == other.height
45
      then util.Arrays.equals(pixels, other.pixels)
1✔
46
      else false
1✔
UNCOV
47
    case _ => false
×
48

49
  override def toString: String =
×
50
    pixels
×
51
      .grouped(width)
×
52
      .map(_.map(Integer.toHexString).mkString(", "))
×
UNCOV
53
      .mkString("RegularImage(\n", "\n", "\n)")
×
54
}
55

56
object RegularImage {
57
  def ofSize(width: Int, height: Int): RegularImage =
1✔
58
    new RegularImage(width, height, Array.ofDim(width * height))
1✔
59

60
  def fromBufferedImage(image: BufferedImage): RegularImage =
1✔
61
    val w = image.getWidth()
1✔
62
    val h = image.getHeight()
1✔
63
    new RegularImage(w, h, image.getRGB(0, 0, w, h, null, 0, w))
1✔
64

65
  def fill(width: Int, height: Int, color: Color): RegularImage =
1✔
66
    val image = ofSize(width, height)
1✔
67
    for
1✔
68
      y <- 0 until height
1✔
69
      x <- 0 until width
1✔
70
    do image.setColor(x, y, color)
1✔
71
    image
72

73
  def tabulate(width: Int, height: Int)(fn: (x: Int, y: Int) => Color): RegularImage =
1✔
74
    val image = ofSize(width, height)
1✔
75
    for
1✔
76
      y <- 0 until height
1✔
77
      x <- 0 until width
1✔
78
    do image.setColor(x, y, fn(x, y))
1✔
79
    image
80

81
  def fromBaseAndOverlay(
1✔
82
      baseImage: Option[RegularImage],
83
      overlayImage: RegularImage,
84
      overlayOffset: StorageCoords
85
  ): RegularImage =
86
    val minimumWidth = overlayOffset.x + overlayImage.width
87
    val minimumHeight = overlayOffset.y + overlayImage.height
88

89
    val finalWidth = baseImage.fold(minimumWidth)(_.width.max(minimumWidth))
1✔
90
    val finalHeight = baseImage.fold(minimumHeight)(_.height.max(minimumHeight))
1✔
91

92
    val finalImage = RegularImage.ofSize(finalWidth, finalHeight)
1✔
93
    if baseImage.isDefined then finalImage.pasteImage(StorageCoords(0, 0), baseImage.get)
1✔
94
    finalImage.pasteImage(overlayOffset, overlayImage)
1✔
95
    finalImage
96
}
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