Skip to content

Go's image.Point and image.Rectangle with generics, use any number type you want

License

Notifications You must be signed in to change notification settings

greenthepear/imggg

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Go Reference Go Report Card

imggg - go's image generic geometrics, reimplements image.Point and image.Rectangle to work with any number type you want: int, int8, int16, int32, int64, float32, float64, uint, uint8, uint16, uint32, uint64, uintptr, instead of just int.

Features:

  • All the same methods and functions as image, the code is modified directly from https://go.dev/src/image/geom.go.
  • Cast them back to the standard library equivalent with the Std() method.
  • Get X and Y of a point as two variables quickly with the XY() method.
  • Multiply a point by another point with the MulPt() method.

Library made for the egriden game framework. .

Note

Using points and rectangles with floats changes their logic from the intentions of the image library, read more on The Go Blog about the package.

Warning

Operations on unsigned integers is not tested, just try not to underflow things.

Usage

package main

import (
    "github.com/greenthepear/imggg"
    "image"
)

func main(){
    // Be implicit
    floatPoint1 := imggg.Pt[float64](0.2,0.1)
    // Let the compiler figure it out
    floatPoint2 := imggg.Pt(1.6,2.2)
    // Use the classic methods
    rec := imggg.Rectangle[float64]{
		floatPoint1.Mul(10),
		floatPoint2.Div(0.1),
	} // (2,1)-(16,22)

    // Work with the standard library
    img := image.NewRGNA(
        rec.Std()
    )
    ...
}

License

Do what you want with this, to be fancy I chose the 0BSD license.

Uses Go source code, Copyright 2010 The Go Authors. All rights reserved: LICENSE

About

Go's image.Point and image.Rectangle with generics, use any number type you want

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages