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

Martomate / Hexacraft / 7351367576

28 Dec 2023 06:50PM UTC coverage: 51.185% (-0.1%) from 51.312%
7351367576

push

github

Martomate
Refactor: Made Chunk not know if it has been saved to file

9 of 12 new or added lines in 2 files covered. (75.0%)

110 existing lines in 32 files now uncovered.

2829 of 5527 relevant lines covered (51.19%)

0.51 hits per line

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

38.71
/game/src/main/scala/hexacraft/world/HexBox.scala
1
package hexacraft.world
2

3
import hexacraft.math.MathUtils
4
import hexacraft.math.geometry.{ConvexHull, OrthogonalProjection}
5
import hexacraft.world.coord.{BlockCoords, BlockRelWorld, CoordUtils, CylCoords}
6

7
import org.joml.Vector3dc
8

9
import scala.annotation.tailrec
10

11
/** radius is the big radius of the hexagon */
12
class HexBox(val radius: Float, val bottom: Float, val top: Float) {
13
  val smallRadius: Double = radius * CylinderSize.y60
14

×
15
  def scaledRadially(scale: Float): HexBox = new HexBox(radius * scale, bottom, top)
16

1✔
17
  def baseArea: Double = radius * radius * CylinderSize.y60 * 3
18

×
19
  def volume: Double = baseArea * (top - bottom)
20

×
21
  def projectedAreaInDirection(dir: Vector3dc): Double =
×
22
    val projection = OrthogonalProjection.inDirection(dir)
×
23
    val projectedVertices = vertices.map(v => projection.project(v.toVector3d))
×
24
    val polygon = ConvexHull.calculate(projectedVertices)
×
25
    polygon.area
26

1✔
27
  def vertices: IndexedSeq[CylCoords.Offset] = {
28
    // val ints = Seq(1, 2, 0, 3, 5, 4)
29

1✔
30
    for {
×
UNCOV
31
      s <- 0 to 1
×
32
      i <- 0 until 6
33
    } yield {
34
      val v = i * Math.PI / 3
1✔
35
      val x = Math.cos(v).toFloat
1✔
36
      val z = Math.sin(v).toFloat
1✔
37
      CylCoords.Offset(x * radius, (1 - s) * (top - bottom) + bottom, z * radius)
38
    }
39
  }
40

41
  /** Returns all blocks spaces that would intersect with this HexBox when placed at the given position */
×
42
  def cover(pos: CylCoords)(using CylinderSize): Seq[BlockRelWorld] =
×
43
    val yLo = math.floor((pos.y + this.bottom) * 2).toInt
×
44
    val yHi = math.floor((pos.y + this.top) * 2).toInt
45

46
    // TODO: improve this implementation to be more correct
×
47
    for
×
48
      y <- yLo to yHi
×
49
      dx <- -1 to 1
×
50
      dz <- -1 to 1
51
      if dx * dz != 1 // remove corners
52
    yield
×
53
      val origin = pos.toBlockCoords.offset(dx, 0, dz)
×
54
      CoordUtils.getEnclosingBlock(BlockCoords(origin.x, y, origin.z))._1
55
}
56

57
object HexBox {
58
  @tailrec
1✔
59
  def approximateVolumeOfIntersection(pos1: CylCoords, box1: HexBox, pos2: CylCoords, box2: HexBox): Double =
60
    if box1.radius < box2.radius
×
61
    then approximateVolumeOfIntersection(pos2, box2, pos1, box1)
62
    else
1✔
63
      val r1 = box1.radius
64
      val r2 = box2.radius
1✔
65
      val d = math.hypot(pos1.x - pos2.x, pos1.z - pos2.z)
1✔
66
      val a2 = box2.baseArea
67

1✔
68
      val baseArea = MathUtils.smoothstep(MathUtils.remap(r1 - r2, r1 + r2, 1, 0, d.toFloat)) * a2
69

70
      val t1 = pos1.y + box1.top
71
      val b1 = pos1.y + box1.bottom
72
      val t2 = pos2.y + box2.top
73
      val b2 = pos2.y + box2.bottom
74

1✔
75
      val height = math.max(0, math.min(t1, t2) - math.max(b1, b2))
76

77
      baseArea * height
78
}
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