Skip to content

Commit

Permalink
#194 Bringing zoom poprties into alignment.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich2 committed Feb 1, 2023
1 parent c5a0231 commit 4e6bf10
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 36 deletions.
4 changes: 2 additions & 2 deletions EGrid/src/egrid/ExpWorldGui.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class ExpWorldGui(val canv: CanvasPlatform, scenIn: EScenBasic, viewIn: HGView,
val eas: RArr[EArea2] = earthAllAreas.flatMap(_.a2Arr)
implicit val gridSys: EGridSys = scen.gridSys

var scale: Length = gridSys.cScale / viewIn.cPScale
var scale: Length = gridSys.cScale / viewIn.pixelsPerC
def gScale: Double = gridSys.cScale / scale
def ifGScale(minScale: Double, elems : => GraphicElems): GraphicElems = ife(gScale >= minScale, elems, RArr[GraphicElem]())
var focus: LatLong = gridSys.hCoordLL(viewIn.hCoord)
Expand Down Expand Up @@ -75,7 +75,7 @@ class ExpWorldGui(val canv: CanvasPlatform, scenIn: EScenBasic, viewIn: HGView,
case _ => RArr()
}

def seas: GraphicElems = ifGlobe{ep => RArr(earth2DEllipse(ep.scale).fill(LightBlue)) }
def seas: GraphicElems = ifGlobe{ep => RArr(earth2DEllipse(ep.metresPerPixel).fill(LightBlue)) }
def irrLines: GraphicElems = ifGlobe{ ep => ep.irrLines2 }
def irrNames: GraphicElems = ifGlobe{ ep => ep.irrNames2 }

Expand Down
4 changes: 2 additions & 2 deletions EGrid/src/egrid/GridWorldGui.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class GridWorldGui(val canv: CanvasPlatform, scenIn: EScenBasic, viewIn: HGView,
val eas: RArr[EArea2] = earthAllAreas.flatMap(_.a2Arr)
implicit val gridSys: EGridSys = scen.gridSys

var scale: Length = gridSys.cScale / viewIn.cPScale
var scale: Length = gridSys.cScale / viewIn.pixelsPerC
def gScale: Double = gridSys.cScale / scale
def ifGScale(minScale: Double, elems : => GraphicElems): GraphicElems = ife(gScale >= minScale, elems, RArr[GraphicElem]())
var focus: LatLong = gridSys.hCoordLL(viewIn.hCoord)
Expand Down Expand Up @@ -66,7 +66,7 @@ class GridWorldGui(val canv: CanvasPlatform, scenIn: EScenBasic, viewIn: HGView,
case _ => RArr()
}

def seas: GraphicElems = ifGlobe{ep => RArr(earth2DEllipse(ep.scale).fill(LightBlue)) }
def seas: GraphicElems = ifGlobe{ep => RArr(earth2DEllipse(ep.metresPerPixel).fill(LightBlue)) }
def irrLines: GraphicElems = ifGlobe{ ep => ep.irrLines2 }
def irrNames: GraphicElems = ifGlobe{ ep => ep.irrNames2 }

Expand Down
38 changes: 16 additions & 22 deletions EGrid/src/egrid/HSysProjectionEarth.scala
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
/* Copyright 2018-22 Richard Oliver. Licensed under Apache Licence version 2.0. */
/* Copyright 2018-23 Richard Oliver. Licensed under Apache Licence version 2.0. */
package ostrat; package egrid
import geom._, prid._, phex._, pglobe._, pgui._, pEarth._, Colour._

case class HSysProjectionEarth(parent: EGridSys, panel: Panel) extends HSysProjection
{
override type GridT = EGridSys
var focus: LatLong = 0 ll 0
var scale: Length = 4.km
def gScale: Double = parent.cScale / scale
override def pixelsPerTile: Double = gScale * 4
def metresPerPixel: Length = parent.cScale / pixelsPerC// 4.km

def setMetresPerPixel(value: Length): Unit = pixelsPerC = parent.cScale / value

override def pixelsPerTile: Double = pixelsPerC * 4
override def ifTileScale(minScale: Double, elems: => GraphicElems): GraphicElems = ife(pixelsPerTile >= minScale, elems, RArr[GraphicElem]())

override def setView(view: Any): Unit = view match {
case hv: HGView => {
scale = parent.cScale / hv.cPScale
pixelsPerC = hv.pixelsPerC
focus = parent.hCoordLL(hv.hCoord)
}
//case d: Double => cPScale = d
Expand All @@ -25,21 +27,13 @@ case class HSysProjectionEarth(parent: EGridSys, panel: Panel) extends HSysProje
def setGChid: HGridSys = parent

def zoomOut: PolygonCompound = clickButton("-") { _ =>
scale *= 1.1
pixelsPerC *= 1.1
panel.repaint(getFrame())
//setStatusText(tilePScaleStr)
//panel.repaint(frame)
//statusText = tilePScaleStr
//thisTop()
}

def zoomIn: PolygonCompound = clickButton("+") { _ =>
scale /= 1.1
pixelsPerC /= 1.1
panel.repaint(getFrame())
//setStatusText(tilePScaleStr)
//panel.repaint(frame)
//statusText = tilePScaleStr
//thisTop()
}


Expand Down Expand Up @@ -110,26 +104,26 @@ case class HSysProjectionEarth(parent: EGridSys, panel: Panel) extends HSysProje
def transLineSegM3Arr(inp: LineSegM3Arr): LineSegArr =
{ val rotated = inp.fromLatLongFocus(focus)
val visible = rotated.filter(_.zsPos)
visible.map(_.xyLineSeg(scale))
visible.map(_.xyLineSeg(metresPerPixel))
}

override def transOptCoord(hc: HCoord): Option[Pt2] =
{ val m3 = parent.hCoordLL(hc).toMetres3
val rotated = m3.fromLatLongFocus(focus)
val opt = ife(rotated.zPos, Some(rotated.xy), None)
opt.map(_ / scale)
opt.map(_ / metresPerPixel)
}

override def transCoord(hc: HCoord): Pt2 = {
val m3 = parent.hCoordLL(hc).toMetres3
val rotated = m3.fromLatLongFocus(focus)
rotated.xy / scale
rotated.xy / metresPerPixel
}

override def transTile(hc: HCen): Option[Polygon] =
{ val p1 = hc.hVertPolygon.map(parent.hCoordLL(_)).toMetres3.fromLatLongFocus(focus)
val opt = ife(p1.vert(0).zPos, Some(p1.map(_.xy)), None)
opt.map(_.map(_ / scale))
opt.map(_.map(_ / metresPerPixel))
}

override def hCoordOptStr(hc: HCoord): Option[String] = Some(parent.hCoordLL(hc).degStr)
Expand All @@ -144,16 +138,16 @@ case class HSysProjectionEarth(parent: EGridSys, panel: Panel) extends HSysProje
case w: Water => BlueViolet
case _ => Colour.LightPink
}
p.map(_ / scale).fill(col)
p.map(_ / metresPerPixel).fill(col)
}

def irrLines: RArr[PolygonDraw] = irr1.map { a => a._2.map(_ / scale).draw(Violet) }
def irrLines: RArr[PolygonDraw] = irr1.map { a => a._2.map(_ / metresPerPixel).draw(Violet) }

def irrLines2: GraphicElems = ifTileScale(8, irrLines)

def irrNames: RArr[TextGraphic] = irr1.map { pair =>
val (d, _) = pair
val posn = d.cen.toMetres3.fromLatLongFocus(focus).xy / scale
val posn = d.cen.toMetres3.fromLatLongFocus(focus).xy / metresPerPixel
TextGraphic(d.name, 12, posn, d.colour.contrastBW)
}

Expand Down
2 changes: 1 addition & 1 deletion Tiling/ExsSrc/gThree/GThreeGui.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ case class GThreeGui(canv: CanvasPlatform, scenStart: ThreeScen, viewIn: HGView)
def terrs: HCenLayer[Terr] = scen.terrs
var history: RArr[ThreeScen] = RArr(scen)
implicit def gridSys: HGridSys = scen.gridSys
cPScale = viewIn.cPScale
cPScale = viewIn.pixelsPerC
focus = viewIn.vec
implicit val proj: HSysProjection = gridSys.projection(mainPanel)
proj.setView(viewIn)
Expand Down
5 changes: 4 additions & 1 deletion Tiling/src/prid/TSysProjection.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright 2018-22 Richard Oliver. Licensed under Apache Licence version 2.0. */
/* Copyright 2018-23 Richard Oliver. Licensed under Apache Licence version 2.0. */
package ostrat; package prid
import geom._, pgui._

Expand All @@ -13,6 +13,8 @@ trait TSysProjection
/** The panel this projection outputs to. */
def panel: Panel

var pixelsPerC: Double = 80

/** The number of pixels per tile from side to opposite side. */
def pixelsPerTile: Double

Expand All @@ -23,6 +25,7 @@ trait TSysProjection
def ifTileScale(minScale: Double, elems: => GraphicElems): GraphicElems

var setStatusText: String => Unit = s => {}

val buttons: RArr[PolygonCompound]

/** Projected [[Polygon]]s of the tiles. */
Expand Down
8 changes: 4 additions & 4 deletions Tiling/src/prid/phex/HGView.scala
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
/* Copyright 2018-22 Richard Oliver. Licensed under Apache Licence version 2.0. */
/* Copyright 2018-23 Richard Oliver. Licensed under Apache Licence version 2.0. */
package ostrat; package prid; package phex
import geom._

/** A view of a hex grid, currently representing the [[HCoord]] focus and the pixels/dx scale. */
class HGView(val r: Int, val c: Int, val cPScale: Double) extends Show2[HCoord, Double]
/** A view of a hex grid, currently representing the [[HCoord]] focus and the pixels per delta Cs scale. */
class HGView(val r: Int, val c: Int, val pixelsPerC: Double) extends Show2[HCoord, Double]
{ def hCoord: HCoord = HCoord(r, c)
def vec: Vec2 = hCoord.toVecReg
def pt2: Pt2 = hCoord.toPt2Reg
override def typeStr: String = "HGView"
override def name1: String = "hCoord"
inline override def show1: HCoord = hCoord
override def name2: String = "cPScale"
inline override def show2: Double = cPScale
inline override def show2: Double = pixelsPerC
override implicit def showT1: ShowT[HCoord] = HCoord.persistImplicit
override implicit def showT2: ShowT[Double] = ShowT.doublePersistEv
override def syntaxDepth: Int = 3
Expand Down
4 changes: 2 additions & 2 deletions Tiling/src/prid/phex/HSysProjectionFlat.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import geom._, pgui._, collection.mutable.ArrayBuffer
/** Projects [[HGridSys]] on to a flat surface for 2D graphics. Like all projections attempts to remove tiles that can't be seen. */
final case class HSysProjectionFlat(parent: HGridSys, panel: Panel) extends HSysProjection with TSysProjectionFlat
{ type GridT = HGridSys
var pixelsPerC: Double = parent.fullDisplayScale(panel.width, panel.height)
pixelsPerC = parent.fullDisplayScale(panel.width, panel.height)
override def pixelsPerR: Double = pixelsPerC * Sqrt3
override def pixelsPerTile: Double = pixelsPerC * 4

Expand All @@ -15,7 +15,7 @@ final case class HSysProjectionFlat(parent: HGridSys, panel: Panel) extends HSys
override def setView(view: Any): Unit = view match
{
case hv: HGView =>
{ pixelsPerC = hv.cPScale
{ pixelsPerC = hv.pixelsPerC
focus = hv.vec
gChild = getGChild
}
Expand Down
4 changes: 2 additions & 2 deletions Tiling/src/prid/psq/SqSysProjection.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright 2018-22 Richard Oliver. Licensed under Apache Licence version 2.0. */
/* Copyright 2018-23 Richard Oliver. Licensed under Apache Licence version 2.0. */
package ostrat; package prid; package psq
import geom._, pgui._

Expand All @@ -24,7 +24,7 @@ trait SqSysProjection extends TSysProjection
case class SqSysProjectionFlat(parent: SqGridSys, panel: Panel) extends SqSysProjection with TSysProjectionFlat
{
type GridT = SqGridSys
var pixelsPerC: Double = parent.fullDisplayScale(panel.width, panel.height)
pixelsPerC = parent.fullDisplayScale(panel.width, panel.height)
override def pixelsPerTile: Double = pixelsPerC * 2
override def pixelsPerR: Double = pixelsPerC
var focus: Vec2 = parent.defaultView(pixelsPerC).vec
Expand Down

0 comments on commit 4e6bf10

Please sign in to comment.