9fans.net/go@v0.0.5/draw/arith.go (about)

     1  package draw
     2  
     3  import "image"
     4  
     5  // A Point is an X, Y coordinate pair, a location in an Image such as the display.
     6  // The coordinate system has X increasing to the right and Y increasing down.
     7  type Point = image.Point
     8  
     9  // A Rectangle is a rectangular area in an image.
    10  // By definition, Min.X ≤ Max.X and Min.Y ≤ Max.Y.
    11  // By convention, the right (Max.X) and bottom (Max.Y)
    12  // edges are excluded from the represented rectangle,
    13  // so abutting rectangles have no points in common.
    14  // Thus, max contains the coordinates of the first point beyond the rectangle.
    15  // If Min.X > Max.X or Min.Y > Max.Y, the rectangle contains no points.
    16  type Rectangle = image.Rectangle
    17  
    18  // Pt is shorthand for Point{X: x, Y: y}.
    19  func Pt(x, y int) Point {
    20  	return Point{X: x, Y: y}
    21  }
    22  
    23  // Rect is shorthand for Rectangle{Min: Pt(x0, y0), Max: Pt(x1, y1)}.
    24  // Unlike image.Rect, Rect does not swap x1 ↔ x2 or y1 ↔ y2
    25  // to put them in canonical order.
    26  // In this package, a Rectangle with x1 > x2 or y1 > y2
    27  // is an empty rectangle.
    28  func Rect(x1, y1, x2, y2 int) Rectangle {
    29  	return Rectangle{Pt(x1, y1), Pt(x2, y2)}
    30  }
    31  
    32  // Rpt is shorthand for Rectangle{min, max}.
    33  func Rpt(min, max Point) Rectangle {
    34  	return Rectangle{Min: min, Max: max}
    35  }
    36  
    37  // ZP is the zero Point.
    38  var ZP Point
    39  
    40  // ZR is the zero Rectangle.
    41  var ZR Rectangle