public ReadOnlyCollection <Vector2> GetContourForCellEdge(IHexCell cell, HexDirection edge) { if (cell == null) { throw new ArgumentNullException("cell"); } List <Vector2>[] contourArray; if (!ContourOfEdgeOfCell.TryGetValue(cell, out contourArray)) { contourArray = new List <Vector2> [6]; ContourOfEdgeOfCell[cell] = contourArray; } if (contourArray[(int)edge] == null) { contourArray[(int)edge] = new List <Vector2>() { cell.AbsolutePositionXZ + RenderConfig.GetFirstCornerXZ(edge), cell.AbsolutePositionXZ + RenderConfig.GetSecondCornerXZ(edge) }; } return(contourArray[(int)edge].AsReadOnly()); }
public bool TryGetSextantOfPointInCell(Vector2 xzPoint, IHexCell cell, out HexDirection sextant) { sextant = HexDirection.NE; foreach (var candidate in EnumUtil.GetValues <HexDirection>()) { sextant = candidate; if (Geometry2D.IsPointWithinTriangle( xzPoint, cell.AbsolutePositionXZ, cell.AbsolutePositionXZ + RenderConfig.GetFirstCornerXZ(candidate), cell.AbsolutePositionXZ + RenderConfig.GetSecondCornerXZ(candidate) )) { return(true); } } return(false); }
public void BuildNonRiverContour(IHexCell center, HexDirection direction) { if (RiverCanon.HasRiverAlongEdge(center, direction)) { return; } var contourPoints = new List <Vector2>(); IHexCell left = Grid.GetNeighbor(center, direction.Previous()); IHexCell right = Grid.GetNeighbor(center, direction); IHexCell nextRight = Grid.GetNeighbor(center, direction.Next()); bool hasCenterLeftRiver = RiverCanon.HasRiverAlongEdge(center, direction.Previous()); bool hasCenterNextRightRiver = RiverCanon.HasRiverAlongEdge(center, direction.Next()); bool hasLeftRightRiver = left != null && RiverCanon.HasRiverAlongEdge(left, direction.Next()); bool hasNextRightRightRiver = nextRight != null && RiverCanon.HasRiverAlongEdge(nextRight, direction.Previous()); if (hasCenterLeftRiver) { ICollection <Vector2> centerLeftContour = CellEdgeContourCanon.GetContourForCellEdge(center, direction.Previous()); contourPoints.Add(centerLeftContour.Last()); } else if (hasLeftRightRiver) { ICollection <Vector2> rightLeftContour = CellEdgeContourCanon.GetContourForCellEdge(right, direction.Previous2()); contourPoints.Add(rightLeftContour.First()); } else { contourPoints.Add(center.AbsolutePositionXZ + RenderConfig.GetFirstCornerXZ(direction)); } if (hasCenterNextRightRiver || (hasNextRightRightRiver && RiverCanon.GetFlowOfRiverAtEdge(nextRight, direction.Previous()) == RiverFlow.Clockwise) ) { ICollection <Vector2> centerNextRightContour = CellEdgeContourCanon.GetContourForCellEdge(center, direction.Next()); contourPoints.Add(centerNextRightContour.First()); } else if (hasNextRightRightRiver) { //We need to add two points here in case the edge is up against the //outflow of a river. We've decided to give the outflow over entirely //to one of the cells, but other constructions are possible. ICollection <Vector2> rightNextRightContour = CellEdgeContourCanon.GetContourForCellEdge(right, direction.Next2()); ICollection <Vector2> nextRightRightContour = CellEdgeContourCanon.GetContourForCellEdge(nextRight, direction.Previous()); contourPoints.Add(rightNextRightContour.Last()); contourPoints.Add(nextRightRightContour.First()); } else { contourPoints.Add(center.AbsolutePositionXZ + RenderConfig.GetSecondCornerXZ(direction)); } CellEdgeContourCanon.SetContourForCellEdge(center, direction, contourPoints); }