Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
c7924cd9ff
|
|||
07712aa08c
|
|||
f5243503db
|
|||
21ae9c70d2
|
@@ -30,3 +30,34 @@ func CompareIntArr(arr1 []int, arr2 []int) bool {
|
|||||||
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func CompareArr[T OrderedConstraint](arr1 []T, arr2 []T) bool {
|
||||||
|
|
||||||
|
for i := 0; i < len(arr1) || i < len(arr2); i++ {
|
||||||
|
|
||||||
|
if i < len(arr1) && i < len(arr2) {
|
||||||
|
|
||||||
|
if arr1[i] < arr2[i] {
|
||||||
|
return true
|
||||||
|
} else if arr1[i] > arr2[i] {
|
||||||
|
return false
|
||||||
|
} else {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if i < len(arr1) {
|
||||||
|
|
||||||
|
return true
|
||||||
|
|
||||||
|
} else { // if i < len(arr2)
|
||||||
|
|
||||||
|
return false
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
21
langext/coords.go
Normal file
21
langext/coords.go
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
package langext
|
||||||
|
|
||||||
|
import "math"
|
||||||
|
|
||||||
|
func DegToRad(deg float64) float64 {
|
||||||
|
return deg * (math.Pi / 180.0)
|
||||||
|
}
|
||||||
|
|
||||||
|
func RadToDeg(rad float64) float64 {
|
||||||
|
return rad / (math.Pi * 180.0)
|
||||||
|
}
|
||||||
|
|
||||||
|
func GeoDistance(lon1 float64, lat1 float64, lon2 float64, lat2 float64) float64 {
|
||||||
|
var d1 = DegToRad(lat1)
|
||||||
|
var num1 = DegToRad(lon1)
|
||||||
|
var d2 = DegToRad(lat2)
|
||||||
|
var num2 = DegToRad(lon2) - num1
|
||||||
|
var d3 = math.Pow(math.Sin((d2-d1)/2.0), 2.0) + math.Cos(d1)*math.Cos(d2)*math.Pow(math.Sin(num2/2.0), 2.0)
|
||||||
|
|
||||||
|
return 6376500.0 * (2.0 * math.Atan2(math.Sqrt(d3), math.Sqrt(1.0-d3)))
|
||||||
|
}
|
5
termext/osutil_linux.go
Normal file
5
termext/osutil_linux.go
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
package termext
|
||||||
|
|
||||||
|
func enableColor() bool {
|
||||||
|
return true
|
||||||
|
}
|
@@ -84,7 +84,7 @@ func IsDatePartEqual(a time.Time, b time.Time, tz *time.Location) bool {
|
|||||||
func WithTimePart(base time.Time, hour, minute, second int) time.Time {
|
func WithTimePart(base time.Time, hour, minute, second int) time.Time {
|
||||||
datepart := TimeToDatePart(base, base.Location())
|
datepart := TimeToDatePart(base, base.Location())
|
||||||
|
|
||||||
delta := time.Duration(hour*int(time.Hour) + minute*int(time.Minute) + second*int(time.Second))
|
delta := time.Duration(int64(hour)*int64(time.Hour) + int64(minute)*int64(time.Minute) + int64(second)*int64(time.Second))
|
||||||
|
|
||||||
return datepart.Add(delta)
|
return datepart.Add(delta)
|
||||||
}
|
}
|
||||||
@@ -94,7 +94,7 @@ func WithTimePart(base time.Time, hour, minute, second int) time.Time {
|
|||||||
func CombineDateAndTime(d time.Time, t time.Time) time.Time {
|
func CombineDateAndTime(d time.Time, t time.Time) time.Time {
|
||||||
datepart := TimeToDatePart(d, d.Location())
|
datepart := TimeToDatePart(d, d.Location())
|
||||||
|
|
||||||
delta := time.Duration(t.Hour()*int(time.Hour) + t.Minute()*int(time.Minute) + t.Second()*int(time.Second) + t.Nanosecond()*int(time.Nanosecond))
|
delta := time.Duration(int64(t.Hour())*int64(time.Hour) + int64(t.Minute())*int64(time.Minute) + int64(t.Second())*int64(time.Second) + int64(t.Nanosecond())*int64(time.Nanosecond))
|
||||||
|
|
||||||
return datepart.Add(delta)
|
return datepart.Add(delta)
|
||||||
}
|
}
|
||||||
@@ -108,7 +108,7 @@ func IsSunday(t time.Time, tz *time.Location) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func DurationFromTime(hours int, minutes int, seconds int) time.Duration {
|
func DurationFromTime(hours int, minutes int, seconds int) time.Duration {
|
||||||
return time.Duration(hours*int(time.Hour) + minutes*int(time.Minute) + seconds*int(time.Second))
|
return time.Duration(int64(hours)*int64(time.Hour) + int64(minutes)*int64(time.Minute) + int64(seconds)*int64(time.Second))
|
||||||
}
|
}
|
||||||
|
|
||||||
func Min(a time.Time, b time.Time) time.Time {
|
func Min(a time.Time, b time.Time) time.Time {
|
||||||
|
Reference in New Issue
Block a user