public IHexCell GetCellAtPoint(Vector3 point) { if (!Grid.HasCellAtLocation(point)) { return(null); } var gridCell = Grid.GetCellAtLocation(point); foreach (var direction in EnumUtil.GetValues <HexDirection>()) { if (CellContourCanon.IsPointWithinContour(point.ToXZ(), gridCell, direction)) { return(gridCell); } } foreach (var neighbor in Grid.GetNeighbors(gridCell)) { foreach (var direction in EnumUtil.GetValues <HexDirection>()) { if (CellContourCanon.IsPointWithinContour(point.ToXZ(), neighbor, direction.Opposite())) { return(neighbor); } } } return(null); }
private bool ShouldAddQuad( List <IHexCell> farmBlob, Vector2 northVertex, Vector2 eastVertex, Vector2 southVertex, Vector2 westVertex ) { bool northValid = false, eastValid = false, southValid = false, westValid = false; foreach (var cell in farmBlob) { foreach (var direction in EnumUtil.GetValues <HexDirection>()) { if (RiverCanon.HasRiverAlongEdge(cell, direction)) { var contour = CellContourCanon.GetContourForCellEdge(cell, direction); if (CellContourCanon.DoesSegmentCrossContour(northVertex, eastVertex, contour) || CellContourCanon.DoesSegmentCrossContour(northVertex, westVertex, contour) || CellContourCanon.DoesSegmentCrossContour(southVertex, eastVertex, contour) || CellContourCanon.DoesSegmentCrossContour(southVertex, westVertex, contour) ) { return(false); } } northValid |= CellContourCanon.IsPointWithinContour(northVertex, cell, direction); eastValid |= CellContourCanon.IsPointWithinContour(eastVertex, cell, direction); southValid |= CellContourCanon.IsPointWithinContour(southVertex, cell, direction); westValid |= CellContourCanon.IsPointWithinContour(westVertex, cell, direction); } } return(northValid && eastValid && southValid && westValid); }