Giter Club home page Giter Club logo

minimum-area-circumscribing-k-gon's Introduction

Fork repository README

Python Microservice wrapping Minimum-Area-Circumscribing-K-Gon IDL code

This repository contains modified IDL code of upstream repository and Python code which starts HTTP microservice. Everything is dockerized, so you can run the microservice in very smooth manner.

To build docker image run ./build_docker.sh. To run it, run ./run_docker.sh. Now, the microservice accepts connections on port 8000.

This is an example how I use it microservice in the client:

import logging

import json_tricks
import numpy as np
import requests

LOGGER: logging.Logger = logging.getLogger()

def snip_points(points, kgon):
    x = points[:, 0]
    y = points[:, 1]

    try:
        response = requests.post(f'http://localhost:8000/test?kgon={kgon}',
                                 json=json_tricks.dumps({"x": x,
                                                         "y": y}),
                                 timeout=15)

        if response.status_code == 500:
            LOGGER.info('Request http code 500')
            return points, 500

        response_json = json_tricks.loads(response.text)

        res = response_json['response']

        res = np.transpose(res)
        res = np.concatenate([res[:, 0], res[:, 1]])
        xs = res[::2]
        ys = res[1::2]
        new_points = np.transpose(np.vstack([xs, ys]))

        return new_points, 200
    except requests.Timeout:
        LOGGER.info('Request timeout')
        return points, 408
    except requests.ConnectionError:
        LOGGER.info('Request connection error')
        return points, 404

Upstream repository README

POLY_KGON

Computes the minimum-area convex k-gon (k-sided polygon) that circumscribes the given convex n-gon. Follows the method of Aggarwal et al, "Minimum area circumscribing Polygons", The Visual Computer (1985) 1:112-117

Example:

IDL> x = [43, 18, 19, 24, 35, 49, 56, 54]*1.
IDL> y = [24, 45, 54, 63, 69, 64, 57, 41]*1.
IDL> result = POLY_KGON(x, y, kgon=4)
IDL> print, result
      15.2727      47.2909
      28.6026      71.2848
      64.4083      58.4970
      43.5917      23.5030

kgon_example

minimum-area-circumscribing-k-gon's People

Contributors

hylandg avatar victoratpl avatar

Stargazers

 avatar

Watchers

 avatar

Forkers

crotielwf

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.