@@ -2,6 +2,7 @@ import { IPoint, IPolyPolygon } from "../grids";
22import { RendererBase } from "../renderers/_base" ;
33import { hexOfTri as hexOfTriGrid } from "../grids" ;
44import { BoardReturn } from "." ;
5+ import { offsetPolygon } from "../common/plotting" ;
56
67export const hexOfTri = ( ctx : RendererBase ) : BoardReturn => {
78 if ( ( ctx . json === undefined ) || ( ctx . rootSvg === undefined ) ) {
@@ -188,61 +189,53 @@ export const hexOfTri = (ctx: RendererBase): BoardReturn => {
188189 const widest = Math . max ( ...grid . map ( row => row . length ) ) ;
189190 const numWidest = grid . findIndex ( row => row . length === widest ) ;
190191 let boardFill : IPolyPolygon ;
191- const dist = cellsize / 1.5 ;
192192 // if numWidest is not the top or the bottom, then we have a full hex
193193 if ( numWidest !== numTop && numWidest !== numBottom ) {
194- const xDist = dist / Math . sqrt ( 3 ) ;
195194 boardFill = {
196195 type : "poly" ,
197- points : [
198- { x : grid [ numTop ] [ 0 ] . x - xDist , y : grid [ numTop ] [ 0 ] . y - dist } ,
199- { x : grid [ numTop ] [ grid [ numTop ] . length - 1 ] . x + xDist , y : grid [ numTop ] [ grid [ numTop ] . length - 1 ] . y - dist } ,
200- { x : grid [ numWidest ] [ grid [ numWidest ] . length - 1 ] . x + ( 2 * xDist ) , y : grid [ numWidest ] [ grid [ numWidest ] . length - 1 ] . y } ,
201- { x : grid [ numBottom ] [ grid [ numBottom ] . length - 1 ] . x + xDist , y : grid [ numBottom ] [ grid [ numBottom ] . length - 1 ] . y + dist } ,
202- { x : grid [ numBottom ] [ 0 ] . x - xDist , y : grid [ numBottom ] [ 0 ] . y + dist } ,
203- { x : grid [ numWidest ] [ 0 ] . x - ( 2 * xDist ) , y : grid [ numWidest ] [ 0 ] . y } ,
204- ] ,
196+ points : offsetPolygon ( [
197+ { x : grid [ numTop ] [ 0 ] . x , y : grid [ numTop ] [ 0 ] . y } ,
198+ { x : grid [ numTop ] [ grid [ numTop ] . length - 1 ] . x , y : grid [ numTop ] [ grid [ numTop ] . length - 1 ] . y } ,
199+ { x : grid [ numWidest ] [ grid [ numWidest ] . length - 1 ] . x , y : grid [ numWidest ] [ grid [ numWidest ] . length - 1 ] . y } ,
200+ { x : grid [ numBottom ] [ grid [ numBottom ] . length - 1 ] . x , y : grid [ numBottom ] [ grid [ numBottom ] . length - 1 ] . y } ,
201+ { x : grid [ numBottom ] [ 0 ] . x , y : grid [ numBottom ] [ 0 ] . y } ,
202+ { x : grid [ numWidest ] [ 0 ] . x , y : grid [ numWidest ] [ 0 ] . y } ,
203+ ] , cellsize / 1.5 ) ,
205204 } ;
206205 }
207206 // otherwise we just have a four-point poly
208207 else {
209- const xDist = dist / Math . sqrt ( 3 ) ;
210208 const ptWideL = {
211- x : grid [ numWidest ] [ 0 ] . x - ( 2 * xDist ) ,
212- y : grid [ numWidest ] [ 0 ] . y + dist * ( half === "top" ? 1 : - 1 ) ,
209+ x : grid [ numWidest ] [ 0 ] . x ,
210+ y : grid [ numWidest ] [ 0 ] . y ,
213211 } ;
214212 const ptWideR = {
215- x : grid [ numWidest ] [ grid [ numWidest ] . length - 1 ] . x + ( 2 * xDist ) ,
216- y : grid [ numWidest ] [ grid [ numWidest ] . length - 1 ] . y + dist * ( half === "top" ? 1 : - 1 ) ,
213+ x : grid [ numWidest ] [ grid [ numWidest ] . length - 1 ] . x ,
214+ y : grid [ numWidest ] [ grid [ numWidest ] . length - 1 ] . y ,
217215 } ;
218216 let ptOtherL : IPoint ; let ptOtherR : IPoint ;
219217 if ( half === "top" ) {
220218 ptOtherL = {
221- x : grid [ numTop ] [ 0 ] . x - xDist ,
222- y : grid [ numTop ] [ 0 ] . y - dist
219+ x : grid [ numTop ] [ 0 ] . x ,
220+ y : grid [ numTop ] [ 0 ] . y
223221 } ;
224222 ptOtherR = {
225- x : grid [ numTop ] [ grid [ numTop ] . length - 1 ] . x + xDist ,
226- y : grid [ numTop ] [ grid [ numTop ] . length - 1 ] . y - dist
223+ x : grid [ numTop ] [ grid [ numTop ] . length - 1 ] . x ,
224+ y : grid [ numTop ] [ grid [ numTop ] . length - 1 ] . y
227225 } ;
228226 } else {
229227 ptOtherL = {
230- x : grid [ numBottom ] [ 0 ] . x - xDist ,
231- y : grid [ numBottom ] [ 0 ] . y + dist
228+ x : grid [ numBottom ] [ 0 ] . x ,
229+ y : grid [ numBottom ] [ 0 ] . y
232230 } ;
233231 ptOtherR = {
234- x : grid [ numBottom ] [ grid [ numBottom ] . length - 1 ] . x + xDist ,
235- y : grid [ numBottom ] [ grid [ numBottom ] . length - 1 ] . y + dist
232+ x : grid [ numBottom ] [ grid [ numBottom ] . length - 1 ] . x ,
233+ y : grid [ numBottom ] [ grid [ numBottom ] . length - 1 ] . y
236234 } ;
237235 }
238236 boardFill = {
239237 type : "poly" ,
240- points : [
241- ptWideL ,
242- ptOtherL ,
243- ptOtherR ,
244- ptWideR ,
245- ] ,
238+ points : offsetPolygon ( [ ptWideL , ptOtherL , ptOtherR , ptWideR ] , cellsize / 1.5 ) ,
246239 } ;
247240 }
248241
0 commit comments