From 93ce06ae7f96c4d167611f4299053ed9cd0cf592 Mon Sep 17 00:00:00 2001 From: Rich2 Date: Wed, 5 Oct 2022 13:56:58 +0100 Subject: [PATCH] #194 Converting projections map methods back to type parametissed methods. --- Tiling/src/prid/phex/HCenOptLayer.scala | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/Tiling/src/prid/phex/HCenOptLayer.scala b/Tiling/src/prid/phex/HCenOptLayer.scala index 82889eaf1..216098d6d 100644 --- a/Tiling/src/prid/phex/HCenOptLayer.scala +++ b/Tiling/src/prid/phex/HCenOptLayer.scala @@ -134,19 +134,23 @@ class HCenOptLayer[A <: AnyRef](val unsafeArr: Array[A]) extends AnyVal with TCe buff.toArr } - /** Uses projection to map the Some data value with the [[HCen]] and the [[Pt2]]. */ - def projSomeHcPtMap(f: (A, HCen, Pt2) => GraphicElem)(implicit proj: HSysProjection): GraphicElems = projSomeHcPtMap(proj)(f) - - def projSomeHcPtMap(proj: HSysProjection)(f: (A, HCen, Pt2) => GraphicElem): GraphicElems = { - val buff = BuffGraphic() + /** Uses projection to map the Some data value with the corresponing [[HCen]] and the projections corresponding [[Pt2]] to an element of type B. In + * most cases B will be a [[GraphicElem]] or a subtype. */ + def projSomeHcPtMap[B, ArrB <: SeqImut[B]](f: (A, HCen, Pt2) => B)(implicit proj: HSysProjection, build: ArrBuilder[B, ArrB]): ArrB = + projSomeHcPtMap(proj)(f) + + /** Uses projection to map the Some data value with the corresponing [[HCen]] and the projections corresponding [[Pt2]] to an element of type B. In + * most cases B will be a [[GraphicElem]] or a subtype. */ + def projSomeHcPtMap[B, ArrB <: SeqImut[B]](proj: HSysProjection)(f: (A, HCen, Pt2) => B)(implicit build: ArrBuilder[B, ArrB]): ArrB = + { val buff = build.newBuff() proj.gChild.foreach { hc => val a: A = unsafeArr(proj.gridSys.arrIndex(hc)) if (a != null) { val res = f(a, hc, proj.transCoord(hc)) - buff.append(res) + build.buffGrow(buff, res) } } - buff.toArr + build.buffToBB(buff) } /** Uses this and a second [[HCenOptLayer]] of type B. Drops all values where either or both [[HCenOptLayer]] have [[None]] values. Maps the