{ "info": { "author": "Stephan Houben", "author_email": "stephanh42@gmail.com", "bugtrack_url": null, "classifiers": [], "description": "chexutil\n========\n\nC++ accelerated classes and functions to deal with hexagonal grids.\n\n.. figure:: img/screenshot.png\n :alt: Screenshot of chex\\_example.py\n\n Screenshot of chex\\_example.py\nIntroduction\n------------\n\nThis module provides the following functionality.\n\n1. Manipulation of grid coordinates in a hexagonal grid.\n2. Converting between hexagonal grid coordinates and screen coordinates.\n3. Field-of-view calculation on a hexagonal grid.\n4. A\\* path-finding on a hexagonal grid.\n\nAll this is provided by the module ``hexutil``. The file\n`chex\\_example.py `__ contains example coding using\nthis functionality. The above image is a screenshot from this example.\n\nManipulation of grid coordinates in a hexagonal grid.\n-----------------------------------------------------\n\nThe class ``chexutil.Hex`` represents a particular hexagon in a grid.\nClass ``Hex`` takes two integer arguments, ``x`` and ``y``. These need\nto satisfy the property that their sum is even.\n\nThe following (x,y) coordinate system is used to address hexagons in the\ngrid.\n\n.. figure:: img/hexcoords.png\n :alt: Hexgrid coordinate system\n\n Hexgrid coordinate system\nAt first, it may seem weird that this coordinate system leaves \"holes\"\nin the representation, i.e. there is no hexagon corresponding to, say,\n(0, 1). However, that turns out to be not a real problem in practise.\nThe advantage is that relationship to the actual center points of the\nhexagons becomes very simple, namely, just multiply ``y`` with \u221a3. This\nalso simplifies screen coordinate calculations.\n\nThe only time the \"holes\" are an issue is if you want to pack grid data\ndensely into a 2D (numpy) array or a list-of-lists. In that case, just\nuse ``ar[hexagon.x//2][hexagon.y]`` to index into array ``ar``.\n\nThe constructor of ``Hex`` checks the \"x+y is even\" property. If it is\nnot satisfied, an ``InvalidHex`` exception is thrown.\n\nNote that ``Hex`` is a namedtuple. That means that it can be used\nwherever a 2-tuple (x, y) is required. It also means that is is\nimmutable.\n\nImportant functionality on instances of ``Hex``. \\* The ``hex.x`` and\n``hex.y`` fields for accessing the x- and y-coordinate, respectively. \\*\nArithmetic operations ``hex1 + hex2``, ``hex1 - hex2`` and ``- hex`` are\nsupported. \\* The method ``hex.neighbours()`` returns the 6 direct\nneighbours of a hex. \\* The method ``hex1.distance(hex2)`` returns the\ndistance in terms of steps on the hexagon grid between ``hex1`` and\n``hex2``.\n\nConverting between hexagonal grid coordinates and screen coordinates.\n---------------------------------------------------------------------\n\nThe mapping of a hexagon to screen (pixel) coordinates can be described\nby two parameters ``width`` and ``height``. The following image shows\nhow these relate to the hexagon size.\n\n.. figure:: img/widthheight.png\n :alt: Hexgrid width and height\n\n Hexgrid width and height\nFor a perfectly regular hexagon, the relationship ``height = \u2153\u221a3 width``\nshould hold. In practice, we typically want integral pixel coordinates.\n\nThe class ``HexGrid`` captures such a pair of ``width`` and ``height``\nvalues. It can be initialized as ``HexGrid(width, height)`` or\n``HexGrid(width)``. In the latter case, ``height`` is automatically\ncomputed as ``round(\u2153\u221a3 * width)``.\n\nImportant functionality on instances of ``Hex``. \\* The\n``hexgrid.width`` and ``hexgrid.height`` fields for accessing the width\nand height, respectively. \\* Method ``hexgrid.center(hex)`` returns a\npair (x, y) of screen coordinates of the center of ``hex``. \\* Method\n``hexgrid.corners(hex)`` returns a sequence of 6 pairs (x, y) of screen\ncoordinates of the 6 corners of ``hex``. \\* Method\n``hexgrid.bounding_box(hex)`` returns a ``chexutil.Rectangle`` object\ndescribing the bounding box of ``hex``. \\* Method\n``hexgrid.hex_at_coordinate(x, y)`` returns the ``Hex`` at screen\ncoordinate (x,y). \\* Method ``hexgrid.hexes_in_rectangle(rect)`` returns\na sequence of all ``Hex``-es which overlap with ``Rectangle`` rect.\n\nField-of-view calculation on a hexagonal grid.\n----------------------------------------------\n\nField-of-view calculation is done by the following method on ``Hex``\ninstances.\n\n``hex.field_of_view(self, transparent, max_distance, visible=None)``\n\n- transparent -- from a Hex to a boolean, indicating of the Hex is\n transparent\n- max\\_distance -- maximum distance you can view\n- visible -- if provided, should be a dict which will be filled and\n returned\n\nReturns a dict which has as its keys the hexagons which are visible. The\nvalue is a bitmask which indicates which sides of the hexagon are\nvisible. The bitmask is useful if you want to use this function also to\ncompute light sources.\n\n::\n\n view_set = player_pos.field_of_view(...)\n light_set = light_source.field_of_view(...)\n\n # Is pos visible?\n if view_set.get(pos, 0) & light_set.get(pos, 0):\n # yes it is\n\nA\\* path-finding on a hexagonal grid.\n-------------------------------------\n\nPath-finding (using the `A\\*\nalgorithm `__) is\ndone by the following method on ``Hex`` instances.\n\n``hex.find_path(self, destination, passable, cost=lambda pos: 1)``\n\n- hex -- Starting position (``Hex`` object) for path finding.\n- destination -- Destination position for path finding.\n- passable -- Function of one position, returning True if we can move\n through this hex.\n- cost -- cost function for moving through a hex. Should return a value\n \u2265 1. By default all costs are 1.\n\nThis returns the path (as a sequence of ``Hex``-es, including start\npoint and destination), or ``None`` if no path could be found.\n\n\n", "description_content_type": null, "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/stephanh42/chexutil", "keywords": "", "license": "", "maintainer": "", "maintainer_email": "", "name": "chexutil", "package_url": "https://pypi.org/project/chexutil/", "platform": "", "project_url": "https://pypi.org/project/chexutil/", "project_urls": { "Homepage": "https://github.com/stephanh42/chexutil" }, "release_url": "https://pypi.org/project/chexutil/0.0.4/", "requires_dist": [ "pybind11 (>=2.2)" ], "requires_python": "", "summary": "C++ accelerated classes and functions to deal with hexagonal grids.", "version": "0.0.4" }, "last_serial": 3351545, "releases": { "0.0.1": [ { "comment_text": "", "digests": { "md5": "930a1d071335c7ddbf5ff1ae864c3f04", "sha256": "27b7204af6e85e10614199323fcfd04a85b00eb4589f7ab5f8a879107ac2dd26" }, "downloads": -1, "filename": "chexutil-0.0.1-cp36-cp36m-macosx_10_12_x86_64.whl", "has_sig": false, "md5_digest": "930a1d071335c7ddbf5ff1ae864c3f04", "packagetype": "bdist_wheel", "python_version": "cp36", "requires_python": null, "size": 136762, "upload_time": "2017-11-13T20:05:49", "url": "https://files.pythonhosted.org/packages/26/a0/d2f5af4da19db5ce7ad71d686cb33b1efb132ae7195d683f232b0116a9ed/chexutil-0.0.1-cp36-cp36m-macosx_10_12_x86_64.whl" }, { "comment_text": "", "digests": { "md5": "b7f5407c06329aec71f0832b50ed4335", "sha256": "94f4829ef81ea205861b64365469cbd76ec34b08d67f8b185dbc21bd1f1b3344" }, "downloads": -1, "filename": "chexutil-0.0.1.tar.gz", "has_sig": false, "md5_digest": "b7f5407c06329aec71f0832b50ed4335", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 12809, "upload_time": "2017-11-13T20:05:51", "url": "https://files.pythonhosted.org/packages/85/f5/67df787d5618531ac881912a6924781980bf48261068b9afb490934da207/chexutil-0.0.1.tar.gz" } ], "0.0.2": [ { "comment_text": "", "digests": { "md5": "c36f5d135405b5a2349d6bb2b3430e5f", "sha256": "41d1f7c2fa3bd5c05b2eb37335d891c8244c2c3c07b8a23ca6620e146242098e" }, "downloads": -1, "filename": "chexutil-0.0.2-cp36-cp36m-macosx_10_12_x86_64.whl", "has_sig": false, "md5_digest": "c36f5d135405b5a2349d6bb2b3430e5f", "packagetype": "bdist_wheel", "python_version": "cp36", "requires_python": null, "size": 137077, "upload_time": "2017-11-13T20:23:24", "url": "https://files.pythonhosted.org/packages/59/56/fdf32052690804218502c2c62dbf95003c578d02048b63f73efd6ab13125/chexutil-0.0.2-cp36-cp36m-macosx_10_12_x86_64.whl" }, { "comment_text": "", "digests": { "md5": "fc42e446b3fa1d7055907bb705a12eb5", "sha256": "a171ddec418844cf3f00859c10f05e64bccd6c8c82c21e1eab51a4f801eaad2b" }, "downloads": -1, "filename": "chexutil-0.0.2.tar.gz", "has_sig": false, "md5_digest": "fc42e446b3fa1d7055907bb705a12eb5", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 13581, "upload_time": "2017-11-13T20:23:26", "url": "https://files.pythonhosted.org/packages/40/5b/d97260cef9da9b88b08a180d3c89ac8de830bf7d7d32e5714c58cd817ec0/chexutil-0.0.2.tar.gz" } ], "0.0.3": [ { "comment_text": "", "digests": { "md5": "6e575c73ec2e92534aad8e7ec9198a64", "sha256": "42640b71cbe06844b4557b8caf3bccdf40ff61bdc001b5a58e2fe1d403246ac1" }, "downloads": -1, "filename": "chexutil-0.0.3-cp36-cp36m-macosx_10_12_x86_64.whl", "has_sig": false, "md5_digest": "6e575c73ec2e92534aad8e7ec9198a64", "packagetype": "bdist_wheel", "python_version": "cp36", "requires_python": null, "size": 139613, "upload_time": "2017-11-15T19:42:44", "url": "https://files.pythonhosted.org/packages/f4/43/a315626dc0f867b203da6286a8a3524b7637dc508a46de74b0a1291d2a44/chexutil-0.0.3-cp36-cp36m-macosx_10_12_x86_64.whl" }, { "comment_text": "", "digests": { "md5": "b7d851c9ab1ed1a82fe1526f9e4fa820", "sha256": "f5c7a1dfceb6c46ca707597d0c8b1b192b8b9b8afc3fa723a2147be4626e0201" }, "downloads": -1, "filename": "chexutil-0.0.3.tar.gz", "has_sig": false, "md5_digest": "b7d851c9ab1ed1a82fe1526f9e4fa820", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 14074, "upload_time": "2017-11-15T19:42:46", "url": "https://files.pythonhosted.org/packages/d8/53/ae2997bf2c45590257158c23d32a025bbbd5f1fc302c71645b9087aa25f9/chexutil-0.0.3.tar.gz" } ], "0.0.4": [ { "comment_text": "", "digests": { "md5": "7747f88106d6ad1981655f9b508b13dc", "sha256": "5f641a07df8d56ac97148e1086f319dd2ec47d5877632a9dc2dac2ee78865ed2" }, "downloads": -1, "filename": "chexutil-0.0.4-cp36-cp36m-macosx_10_12_x86_64.whl", "has_sig": false, "md5_digest": "7747f88106d6ad1981655f9b508b13dc", "packagetype": "bdist_wheel", "python_version": "cp36", "requires_python": null, "size": 146736, "upload_time": "2017-11-21T09:40:07", "url": "https://files.pythonhosted.org/packages/b5/d2/1f341a8be0bda971f346f1cfb24ecd9239f46c896d160dbce918586957c8/chexutil-0.0.4-cp36-cp36m-macosx_10_12_x86_64.whl" }, { "comment_text": "", "digests": { "md5": "c4b88f9c3db5ac8fc7f3bd1868907c03", "sha256": "cd117221557f312230c0ab1cdad38b2ed7161dfd9d40218b525ca70712413dff" }, "downloads": -1, "filename": "chexutil-0.0.4.tar.gz", "has_sig": false, "md5_digest": "c4b88f9c3db5ac8fc7f3bd1868907c03", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 89009, "upload_time": "2017-11-21T09:40:10", "url": "https://files.pythonhosted.org/packages/07/39/ceef15354403f008277e8976a9c6467e3de42f9d524cc8af8aa5debb5834/chexutil-0.0.4.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "7747f88106d6ad1981655f9b508b13dc", "sha256": "5f641a07df8d56ac97148e1086f319dd2ec47d5877632a9dc2dac2ee78865ed2" }, "downloads": -1, "filename": "chexutil-0.0.4-cp36-cp36m-macosx_10_12_x86_64.whl", "has_sig": false, "md5_digest": "7747f88106d6ad1981655f9b508b13dc", "packagetype": "bdist_wheel", "python_version": "cp36", "requires_python": null, "size": 146736, "upload_time": "2017-11-21T09:40:07", "url": "https://files.pythonhosted.org/packages/b5/d2/1f341a8be0bda971f346f1cfb24ecd9239f46c896d160dbce918586957c8/chexutil-0.0.4-cp36-cp36m-macosx_10_12_x86_64.whl" }, { "comment_text": "", "digests": { "md5": "c4b88f9c3db5ac8fc7f3bd1868907c03", "sha256": "cd117221557f312230c0ab1cdad38b2ed7161dfd9d40218b525ca70712413dff" }, "downloads": -1, "filename": "chexutil-0.0.4.tar.gz", "has_sig": false, "md5_digest": "c4b88f9c3db5ac8fc7f3bd1868907c03", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 89009, "upload_time": "2017-11-21T09:40:10", "url": "https://files.pythonhosted.org/packages/07/39/ceef15354403f008277e8976a9c6467e3de42f9d524cc8af8aa5debb5834/chexutil-0.0.4.tar.gz" } ] }