common

package
v0.0.0-...-4c2d33b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 12, 2025 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// GPSPrecision0 is the precision for country or large region
	GPSPrecision0 = 0
	// GPSPrecision1 is the precision for large city or district
	GPSPrecision1 = 1
	// GPSPrecision2 is the precision for town or village
	GPSPrecision2 = 2
	// GPSPrecision3 is the precision for neighborhood, street
	GPSPrecision3 = 3
	// GPSPrecision4 is the precision for individual street, large buildings
	GPSPrecision4 = 4
	// GPSPrecision5 is the precision for individual trees, houses
	GPSPrecision5 = 5
	// GPSPrecision6 is the precision for individual cats
	GPSPrecision6 = 6
	// GPSPrecision7 is the precision for practical limit of commercial surveying
	GPSPrecision7 = 7
	// GPSPrecision8 is the precision for specialized surveying
	GPSPrecision8 = 8
)
View Source
const ElevationCommercialFlightCruising = 10668.0
View Source
const ElevationOfDeadSea = -430.0
View Source
const ElevationOfEverest = 8848.0
View Source
const ElevationOfTroposphere = 11000.0
View Source
const SpeedOfCommercialFlight = 250.0 // or 900 km/h
View Source
const SpeedOfCyclingMax = 11.76 // or 42 km/h or 26 mph
View Source
const SpeedOfCyclingMin = SpeedOfRunningMin
View Source
const SpeedOfDrivingAutobahn = 67.06 // or 241 km/h or 150 mph
View Source
const SpeedOfDrivingCityUSMean = 13.9 // or 50 km/h or 31 mph
View Source
const SpeedOfDrivingFreeway = 33.33 // or 120 km/h or 75 mph
View Source
const SpeedOfDrivingHighway = 25.29 // or 91 km/h or 56 mph
View Source
const SpeedOfDrivingHighwayMin = 20.11 // or 72 km/h or 45 mph
View Source
const SpeedOfDrivingMin = 4.47 // or 16 km/h or 10 mph
View Source
const SpeedOfDrivingPrettyDamnFast = 44.7 // or 161 km/h or 100 mph
View Source
const SpeedOfFlyingSlow = 55.56 // or 200 km/h or 124 mph
View Source
const SpeedOfRunningMax = 5.56 // or 20 km/h or 12 mph
View Source
const SpeedOfRunningMin = 2.23 // or 8 km/h or 5 mph
View Source
const SpeedOfSound = 343.0
View Source
const SpeedOfWalkingMax = 1.78 // or 6.4 km/h or 4 mph
View Source
const SpeedOfWalkingMean = 1.2 // or 4.3 km/h or 2.7 mph
View Source
const SpeedOfWalkingMin = 0.23 // or 0.8 km/h or 0.5 mph
View Source
const SpeedOfWalkingSlow = 0.5 // or 1.8 km/h or 1.1 mph

Variables

View Source
var ArgNone = &argNone
View Source
var SpeedOfCyclingMean = 5.36 // or 19.3 km/h or 12 mph
View Source
var SpeedOfRunningMean = 3.35 // or 12 km/h or 7.5 mph or 8min/mile

Functions

func DecimalToFixed

func DecimalToFixed(num float64, precision int) float64

func DecodeB64ToJPGBytes

func DecodeB64ToJPGBytes(b64 string) ([]byte, error)

func DialRPC

func DialRPC(network, address string) (*rpc.Client, error)

func Interrupted

func Interrupted() <-chan os.Signal

func ReflectFunctionName

func ReflectFunctionName(i interface{}) string

ReflectFunctionName returns the fully-qualifed name of a function. eg. "github.com/rotblauer/geom.(*Polygon).Area" eg. "github.com/rotblauer/geom.(*Polygon).Length" eg. "github.com/sams96/rgeo.Countries110

func SegmentsIntersect

func SegmentsIntersect(segA, segB orb.LineString) (intersect bool, x, y *float64)

SegmentsIntersect returns true if the two line segments intersect and the intersection point, otherwise false and nils. The intersection point is considered exclusive of the endpoints of the segments; continuous segments are not considered to intersect.

https://stackoverflow.com/a/1968345

// Returns 1 if the lines intersect, otherwise 0. In addition, if the lines
// intersect the intersection point may be stored in the floats i_x and i_y.
char get_line_intersection(float p0_x, float p0_y, float p1_x, float p1_y,
    float p2_x, float p2_y, float p3_x, float p3_y, float *i_x, float *i_y)
{
    float s1_x, s1_y, s2_x, s2_y;
    s1_x = p1_x - p0_x;     s1_y = p1_y - p0_y;
    s2_x = p3_x - p2_x;     s2_y = p3_y - p2_y;

    float s, t;
    s = (-s1_y * (p0_x - p2_x) + s1_x * (p0_y - p2_y)) / (-s2_x * s1_y + s1_x * s2_y);
    t = ( s2_x * (p0_y - p2_y) - s2_y * (p0_x - p2_x)) / (-s2_x * s1_y + s1_x * s2_y);

    if (s >= 0 && s <= 1 && t >= 0 && t <= 1)
    {
        // Collision detected
        if (i_x != NULL)
            *i_x = p0_x + (t * s1_x);
        if (i_y != NULL)
            *i_y = p0_y + (t * s1_y);
        return 1;
    }

    return 0; // No collision
}

func SlogResetLevel

func SlogResetLevel(level slog.Level) (reset func())

SlogTempLevel returns a function that resets the slog level to the previous level, pairs well with defer. Use like:

func Test123(t *testing.T) {
    defer common.SlogTempLevel(slog.Level(slog.LevelWarn + 1))()

Types

type RPCArgNone

type RPCArgNone *int

type RingBuffer

type RingBuffer[T any] struct {
	// contains filtered or unexported fields
}

RingBuffer from https://medium.com/@nathanbcrocker/a-practical-guide-to-implementing-a-generic-ring-buffer-in-go-866d27ec1a05. Have added a few things. I'm to blame for SortingRingBuffer.

func NewRingBuffer

func NewRingBuffer[T any](size int) *RingBuffer[T]

NewRingBuffer creates a new ring buffer with a fixed size.

func (*RingBuffer[T]) Add

func (rb *RingBuffer[T]) Add(value T)

Add inserts a new element into the buffer, overwriting the oldest if full.

func (*RingBuffer[T]) First

func (rb *RingBuffer[T]) First() T

func (*RingBuffer[T]) Get

func (rb *RingBuffer[T]) Get() []T

Get returns the contents of the buffer in FIFO order.

func (*RingBuffer[T]) Head

func (rb *RingBuffer[T]) Head(n int) []T

Head returns the first (first in) n elements in the buffer.

func (*RingBuffer[T]) Last

func (rb *RingBuffer[T]) Last() T

func (*RingBuffer[T]) Len

func (rb *RingBuffer[T]) Len() int

Len returns the current number of elements in the buffer.

func (*RingBuffer[T]) Scan

func (rb *RingBuffer[T]) Scan(fn func(T) bool)

func (*RingBuffer[T]) Tail

func (rb *RingBuffer[T]) Tail(n int) []T

Tail returns the last (last in) n elements in the buffer.

type SlippyZoomLevelT

type SlippyZoomLevelT int
var (
	// SlippyZoomLevel0 represents, eg. the whole world
	SlippyZoomLevel0 SlippyZoomLevelT = 0
	SlippyZoomLevel1 SlippyZoomLevelT = 1

	// SlippyZoomLevel2 represents, eg. a subcontinental area
	SlippyZoomLevel2 SlippyZoomLevelT = 2

	// SlippyZoomLevel3 represents, eg. the largest country
	SlippyZoomLevel3 SlippyZoomLevelT = 3
	SlippyZoomLevel4 SlippyZoomLevelT = 4

	// SlippyZoomLevel5 represents, eg. a large African country
	SlippyZoomLevel5 SlippyZoomLevelT = 5
	// SlippyZoomLevel6 represents, eg. a large European country
	SlippyZoomLevel6 SlippyZoomLevelT = 6
	// SlippyZoomLevel7 represents, eg. a small country, US state
	SlippyZoomLevel7 SlippyZoomLevelT = 7
	SlippyZoomLevel8 SlippyZoomLevelT = 8
	// SlippyZoomLevel9 represents, eg. a wide area, large metropolitan area
	SlippyZoomLevel9 SlippyZoomLevelT = 9
	// SlippyZoomLevel10 represents, eg. a metropolitan area
	SlippyZoomLevel10 SlippyZoomLevelT = 10
	// SlippyZoomLevel11 represents, eg. a city
	SlippyZoomLevel11 SlippyZoomLevelT = 11
	// SlippyZoomLevel12 represents, eg. a town, or city district
	SlippyZoomLevel12 SlippyZoomLevelT = 12
	// SlippyZoomLevel13 represents, eg. a village, or suburb
	SlippyZoomLevel13 SlippyZoomLevelT = 13
	// SlippyZoomLevel14 is where houses start showing up on default maps
	SlippyZoomLevel14 SlippyZoomLevelT = 14
	// SlippyZoomLevel15 represents, eg. a small road
	SlippyZoomLevel15 SlippyZoomLevelT = 15
	// SlippyZoomLevel16 represents, eg. a street
	SlippyZoomLevel16 SlippyZoomLevelT = 16
	// SlippyZoomLevel17 represents, eg. a block, park, addresses
	SlippyZoomLevel17 SlippyZoomLevelT = 17
	// SlippyZoomLevel18 represents, eg. some buildings, trees
	SlippyZoomLevel18 SlippyZoomLevelT = 18
	// SlippyZoomLevel19 represents, eg. local highway and crossing details
	SlippyZoomLevel19 SlippyZoomLevelT = 19
	// SlippyZoomLevel20 represents, eg. a mid-sized building
	SlippyZoomLevel20 SlippyZoomLevelT = 20
)

type SortingRingBuffer

type SortingRingBuffer[T any] struct {
	*RingBuffer[T]
	// contains filtered or unexported fields
}

func NewSortingRingBuffer

func NewSortingRingBuffer[T any](size int, less func(T, T) bool) *SortingRingBuffer[T]

func (*SortingRingBuffer[T]) Add

func (rb *SortingRingBuffer[T]) Add(value T)

func (*SortingRingBuffer[T]) First

func (rb *SortingRingBuffer[T]) First() T

func (*SortingRingBuffer[T]) Get

func (rb *SortingRingBuffer[T]) Get() []T

func (*SortingRingBuffer[T]) IsSorted

func (rb *SortingRingBuffer[T]) IsSorted() bool

func (*SortingRingBuffer[T]) Last

func (rb *SortingRingBuffer[T]) Last() T

func (*SortingRingBuffer[T]) Len

func (rb *SortingRingBuffer[T]) Len() int

func (*SortingRingBuffer[T]) Scan

func (rb *SortingRingBuffer[T]) Scan(fn func(T) bool)

func (*SortingRingBuffer[T]) Sort

func (rb *SortingRingBuffer[T]) Sort()

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL