X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=code%2Fnetwork-generator%2Fmodel%2Fpython%2Fcube.py;fp=code%2Fnetwork-generator%2Fmodel%2Fpython%2Fcube.py;h=0000000000000000000000000000000000000000;hb=7004840bca352043aec43d36df79436b90bcbd5a;hp=f709bd7170b051a7bca92b6bcda89cd766502d5f;hpb=c8e3bd35883f540afe023fd077ad64cde327e18a;p=oam.git diff --git a/code/network-generator/model/python/cube.py b/code/network-generator/model/python/cube.py deleted file mode 100644 index f709bd7..0000000 --- a/code/network-generator/model/python/cube.py +++ /dev/null @@ -1,73 +0,0 @@ -# Copyright 2023 highstreet technologies GmbH -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# inspired by http://www.redblobgames.com/grids/hexagons/ - -#!/usr/bin/python -from model.python.hexagon import Hex - - -class Cube: - @staticmethod - def direction_vectors() -> list[Hex]: - q, r, s = 1, 0, -1 - return [ - Hex(q, r, s), - Hex(-s, -q, -r), - Hex(r, s, q), - Hex(-q, -r, -s), - Hex(s, q, r), - Hex(-r, -s, -q), - ] - - @staticmethod - def direction(direction: int) -> Hex: - if direction < 0 or direction > 5: - raise ValueError( - "Invalid direction. The direction value must be in the range of [0..5]." - ) - return Cube.direction_vectors()[direction] - - @staticmethod - def add(hex: Hex, vec: Hex) -> Hex: - return Hex(hex.q + vec.q, hex.r + vec.r, hex.s + vec.s) - - @staticmethod - def neighbor(cube: Hex, direction: int) -> Hex: - return Cube.add(cube, Cube.direction(direction)) - - @staticmethod - def scale(hex: Hex, factor: int) -> Hex: - return Hex(hex.q * factor, hex.r * factor, hex.s * factor) - - @staticmethod - def ring(center: Hex, radius: int) -> list[Hex]: - if not (radius > 0): - raise ValueError( - "Invalid radius. The radius around the hex center must be greater than 0 rings." - ) - results: list[Hex] = [] - hex: Hex = Cube.add(center, Cube.scale(Cube.direction(4), radius)) - for i in range(6): - for j in range(radius): - results.append(hex) - hex = Cube.neighbor(hex, i) - return results - - @staticmethod - def spiral(center: Hex, radius: int) -> list[Hex]: - result: list[Hex] = [center] - for k in range(1, radius + 1): - result.extend(Cube.ring(center, k)) - return result