github.com/rajveermalviya/gamen@v0.1.2-0.20220930195403-9be15877c1aa/dpi/logical.go (about)

     1  package dpi
     2  
     3  import "golang.org/x/exp/constraints"
     4  
     5  type LogicalPosition[T constraints.Integer | constraints.Float] struct {
     6  	X, Y T
     7  }
     8  
     9  func (s LogicalPosition[T]) ToLogical(scaleFactor float64) LogicalPosition[T] {
    10  	return s
    11  }
    12  
    13  func (s LogicalPosition[T]) ToPhysical(scaleFactor float64) PhysicalPosition[T] {
    14  	return PhysicalPosition[T]{
    15  		X: T(float64(s.X) * scaleFactor),
    16  		Y: T(float64(s.Y) * scaleFactor),
    17  	}
    18  }
    19  
    20  type LogicalSize[T constraints.Integer | constraints.Float] struct {
    21  	Width, Height T
    22  }
    23  
    24  func (s LogicalSize[T]) ToLogical(scaleFactor float64) LogicalSize[T] {
    25  	return s
    26  }
    27  
    28  func (s LogicalSize[T]) ToPhysical(scaleFactor float64) PhysicalSize[T] {
    29  	return PhysicalSize[T]{
    30  		Width:  T(float64(s.Width) * scaleFactor),
    31  		Height: T(float64(s.Height) * scaleFactor),
    32  	}
    33  }