Skip to content

Commit

Permalink
skew hexagons are hexagons
Browse files Browse the repository at this point in the history
  • Loading branch information
siddhartha-gadgil committed Jun 29, 2021
1 parent 0dc2c5f commit 8a4d930
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
4 changes: 2 additions & 2 deletions superficial/src/main/scala/superficial/PolygonImageGen.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ trait PolygonImageGen{

val sides: Int

val edgePaths: Vector[Picture[Unit]] =
lazy val edgePaths: Vector[Picture[Unit]] =
vertices.zip(vertices.tail :+ vertices.head).toVector.map {
case (init, term) =>
OpenPath(List(moveTo(init), lineTo(term))).path
}

val edgePathsMid: Vector[(Picture[Unit], Point)] =
lazy val edgePathsMid: Vector[(Picture[Unit], Point)] =
vertices.zip(vertices.tail :+ vertices.head).toVector.map {
case (init, term) =>
(
Expand Down
25 changes: 22 additions & 3 deletions superficial/src/main/scala/superficial/SkewPantsSurfaceImage.scala
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,27 @@ case class SkewHexImageGen(
thicknessMap: Map[Edge, Int],
labelMap: Map[Edge, String],
radius: Double = 100
) extends RegularPolygonImageGen(hex.boundary.size, radius) {
val edgeImages: Vector[Picture[Unit]] =
) extends PolygonImageGen {
val sides: Int = hex.boundary.size

val hexVertices: Vector[Point] = (0 until 6)
.map(index => Point.polar(radius, (360.degrees / 6.0) * index.toDouble))
.toVector

val vertices: Vector[Point] =
hex.segments.zipWithIndex.flatMap{
case (edges, j) =>
val totalLength = edges.map(e => hex.sideLength(e)).sum
val init = hexVertices(2 * j)
val term = hexVertices(2 * j + 1)
import PolygonImageGen.convex
(0 to edges.size).map{
i =>
convex(init, term, (edges.take(i).map(hex.sideLength(_)).sum) /totalLength)
}
}

lazy val edgeImages: Vector[Picture[Unit]] =
hex.boundary.zipWithIndex.map {
case (edge, j) =>
val (ep, mid) = edgePathsMid(j)
Expand All @@ -148,7 +167,7 @@ case class SkewHexImageGen(
label.on(path)
}

val polygon = edgeImages.reduce(_ on _)
lazy val polygon = edgeImages.reduce(_ on _)
}

object SkewPantsSurfaceImage {
Expand Down

0 comments on commit 8a4d930

Please sign in to comment.