Skip to content

Commit

Permalink
#194 Crrated fromBuff for RPairBuff.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich2 committed Dec 5, 2022
1 parent f737e53 commit b3accd2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
12 changes: 5 additions & 7 deletions Tiling/src/prid/phex/HGrid.scala
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
/* Copyright 2018-22 Richard Oliver. Licensed under Apache Licence version 2.0. */
package ostrat; package prid; package phex
import geom._

import scala.reflect.ClassTag
import geom._, reflect.ClassTag

/** A grid of hexs. The grid may be a regular rectangle of hexs or an irregular grid with variable length rows.
* @groupdesc SidesGroup Trait members that operate on the sides of the Hex Grid.
Expand Down Expand Up @@ -124,7 +122,7 @@ trait HGrid extends Any with TGrid with HGridSys
val endCen = HCen(startCen.r + step.tr, startCen.c + step.tc)
if (hCenExists(endCen)) endCen else excep("Illegal end hex in unsafeStep method.")
}
def ghj: RBuff[AnyRef] = ???

override def findStepEnd(startHC: HCen, step: HDirn): Option[HCen] =
{ val endHC = HCen(startHC.r + step.tr, startHC.c + step.tc)
if (hCenExists(startHC) & hCenExists(endHC)) Some(endHC) else None
Expand All @@ -147,10 +145,10 @@ trait HGrid extends Any with TGrid with HGridSys
}
}

/** Implementation incomplete. */
def rowCombine[A <: AnyRef](r: Int, layer: HCenLayer[A], indexingGSys: HGridSys = this)(implicit ct2: ClassTag[A]): RPairArr[HCenRow, A] =
{
val buff: RPairBuff[HCenRow, A] = RPairBuff[HCenRow, A]()
RPairArr[HCenRow, A]()
{ val buff: RPairBuff[HCenRow, A] = RPairBuff[HCenRow, A]()
RPairArr.fromBuff(buff)
}

override def rowsCombine[A <: AnyRef](layer: HCenLayer[A], indexingGSys: HGridSys = this): RArr[HCenRowPair[A]] =
Expand Down
5 changes: 4 additions & 1 deletion Util/src/Arr/RPairElem.scala
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ object RPairArr
pairs.iForeach { (i, p) => a1s(i) = p.a1; a2s(i) = p.a2 }
new RPairArr[A1, A2](a1s, a2s)
}

def fromBuff[A1, A2](buff: RPairBuff[A1, A2])(implicit ct1: ClassTag[A1], ct2: ClassTag[A2]): RPairArr[A1, A2] =
new RPairArr[A1, A2](buff.b1Buffer.toArray, buff.b2Buffer.toArray)
}

/** R for the first component of the [[PairNoA1ParamElem]] is stored by reference. [[Buff]] for [[RPairElem]]s. Note although they are named as
Expand All @@ -93,7 +96,7 @@ class RPairBuff[B1, B2](val b1Buffer: ArrayBuffer[B1], val b2Buffer: ArrayBuffer
}

object RPairBuff
{
{ /** Factory apply method for [[RPairBuff]] class. Creates an empty [[Buff]] class with a default buffer for expansion of 4 elements. */
def apply[B1, B2](buffLen: Int = 4): RPairBuff[B1, B2] = new RPairBuff[B1, B2](new ArrayBuffer[B1](buffLen), new ArrayBuffer[B2](buffLen))
}

Expand Down

0 comments on commit b3accd2

Please sign in to comment.