Coder Social home page Coder Social logo

gomonchickey's Introduction

gomonchickey - go语言实现的工具库

go version: 1.13

example code

package main

import (
    "fmt"
    "time"

    "github.com/zengzhiying/gomonchickey"
)

type Coordinate monchickey.Coordinate

func PolygonContain(pointSet []Coordinate, p Coordinate) (int, error) {
    newPointSet := make([]monchickey.Coordinate, len(pointSet))
    for i, c := range pointSet {
        newPointSet[i] = monchickey.Coordinate(c)
    }
    return monchickey.PolygonContain(newPointSet, monchickey.Coordinate(p))
}

func main() {
    nowTimestamp := time.Now().Unix()
    nowTimeStr := monchickey.TimestampToString(nowTimestamp, "2006-01-02 15:04:05")
    fmt.Println(nowTimeStr)

    numSeq := []uint8{72, 101, 108, 108, 111, 32, 109, 111, 110, 99, 104, 105, 99, 107, 101, 121, 33}
    raw := monchickey.Uint8ToBytes(numSeq)
    fmt.Println(string(raw))
    fmt.Println(monchickey.Base64Encode(raw))

    geoHash, err := monchickey.GeohashEncode(113.56291, 36.9271, 12)
    if err != nil {
        fmt.Println(err)
    } else {
        fmt.Println("(113.56291, 36.9271) geohash Encode:", geoHash)
    }
    longitude, latitude, err := monchickey.GeohashDecode(geoHash)
    if err == nil {
        fmt.Println(geoHash, "Decode:(", longitude, latitude, ")")
    }

    pointSet := []Coordinate{
        Coordinate{1, 1},
        Coordinate{1, 4},
        Coordinate{4, 4},
        Coordinate{4, 1},
    }

    fmt.Println("Polygon: (1,1)-(1,4)-(4,4)-(4,1): ")
    v, _ := PolygonContain(pointSet, Coordinate{1, 1})
    fmt.Println("  (1, 1) in", v)  // 边上
    v, _ = PolygonContain(pointSet, Coordinate{2, 2})
    fmt.Println("  (2, 2) in", v)  // 内部
    v, _ = PolygonContain(pointSet, Coordinate{5, 1})
    fmt.Println("  (5, 1) in", v)  // 外部
}

output:
2020-02-23 15:05:55
Hello monchickey!
SGVsbG8gbW9uY2hpY2tleSE=
(113.56291, 36.9271) geohash Encode: ww8f04mgzw75
ww8f04mgzw75 Decode:( 113.56290997937322 36.92709996365011 )
Polygon: (1,1)-(1,4)-(4,4)-(4,1):
(1, 1) in 0
(2, 2) in 1
(5, 1) in -1

gomonchickey's People

Contributors

zengzhiying avatar

Stargazers

 avatar

Watchers

 avatar

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.