// See cairo_clip_extents().
//
// C API documentation: http://cairographics.org/manual/cairo-cairo-t.html#cairo-clip-extents
358657
func (cr *Context) ClipExtents() (float64, float64, float64, float64) {
	var x1 C.double
	var y1 C.double
	var x2 C.double
	var y2 C.double

	C.cairo_clip_extents(cr.Ptr, &x1, &y1, &x2, &y2)
	if err := cr.status(); err != nil {
		panic(err)
	}
	return float64(x1), float64(y1), float64(x2), float64(y2)
}
482598
func (image *Image) GetOverlap() (overlap uint64, err error) {
	if image.image == nil {
		return 0, RbdErrorImageNotOpen
	}

	ret := C.rbd_get_overlap(image.image, (*C.uint64_t)(&overlap))
	if ret < 0 {
		return overlap, RBDError(int(ret))
	}

	return overlap, nil
}
1220576
func EnclosePoints(points []Point, clip *Rect) (Rect, bool) {
	var result Rect

	if len(points) == 0 {
		return result, false
	}

	var minX, minY, maxX, maxY int32
	if clip != nil {
		added := false
		clipMinX := clip.X
		clipMinY := clip.Y
		clipMaxX := clip.X + clip.W - 1
		clipMaxY := clip.Y + clip.H - 1

		// If the clip has no size, we're done
		if clip.Empty() {
			return result, false
		}

		for _, val := range points {
			// Check if the point is inside the clip rect
			if val.X < clipMinX || val.X > clipMaxX || val.Y < clipMinY || val.Y > clipMaxY {
				continue
			}

			if !added {
				// If it's the first point
				minX = val.X
				maxX = val.X
				minY = val.Y
				maxY = val.Y
				added = true
			}

			// Find mins and maxes
			if val.X < minX {
				minX = val.X
			} else if val.X > maxX {
				maxX = val.X
			}
			if val.Y < minY {
				minY = val.Y
			} else if val.Y > maxY {
				maxY = val.Y
			}
		}
	} else {
		for i, val := range points {
			if i == 0 {
				// Populate the first point
				minX = val.X
				maxX = val.X
				minY = val.Y
				maxY = val.Y
				continue
			}

			// Find mins and maxes
			if val.X < minX {
				minX = val.X
			} else if val.X > maxX {
				maxX = val.X
			}
			if val.Y < minY {
				minY = val.Y
			} else if val.Y > maxY {
				maxY = val.Y
			}
		}
	}

	result.X = minX
	result.Y = minY
	result.W = (maxX - minX) + 1
	result.H = (maxY - minY) + 1

	return result, true
}
921067
func FrameExtentsSet(xu *xgbutil.XUtil, win xproto.Window,
	extents *FrameExtents) error {
	raw := make([]uint, 4)
	raw[0] = uint(extents.Left)
	raw[1] = uint(extents.Right)
	raw[2] = uint(extents.Top)
	raw[3] = uint(extents.Bottom)

	return xprop.ChangeProp32(xu, win, "_NET_FRAME_EXTENTS", "CARDINAL", raw...)
}
1314812
func Extents(font *truetype.Font, fontSize float64, text string) (int, int) {
	c := ftContext(font, fontSize)
	w, h, err := c.MeasureString(text)
	if err != nil {
		return 0, 0
	}
	return int(w / 256), int(h / 256)
}
869868
func (as ArraySpec) Clip2(val Input) Input {
	return as.proc(func(i Input) Input {
		return i.Clip2(val)
	})
}
184474
func (ref *ShapeRef) Docstring() string {
	if ref.Documentation != "" {
		return strings.Trim(ref.Documentation, "\n ")
	}
	return ref.Shape.Docstring()
}
699296
func (cr *Context) ResetClip() {
	C.cairo_reset_clip(cr.Ptr)
	if err := cr.status(); err != nil {
		panic(err)
	}
}
1373960
func (scaledFont *ScaledFont) Extents(extents *FontExtents) {
	C.cairo_scaled_font_extents(scaledFont.Ptr, (*C.cairo_font_extents_t)(unsafe.Pointer(extents)))
	if err := scaledFont.status(); err != nil {
		panic(err)
	}
}
49423
func (surface *RecordingSurface) InkExtents() (float64, float64, float64, float64) {
	var x0 C.double
	var y0 C.double
	var width C.double
	var height C.double

	C.cairo_recording_surface_ink_extents(surface.Ptr, &x0, &y0, &width, &height)
	if err := surface.status(); err != nil {
		panic(err)
	}
	return float64(x0), float64(y0), float64(width), float64(height)
}
462419
func maybeStripExtension(number *builder.Builder) string {
	// If we find a potential extension, and the number preceding this is
	// a viable number, we assume it is an extension.
	numStr := number.String()
	ind := EXTN_PATTERN.FindStringIndex(numStr)
	if len(ind) > 0 && isViablePhoneNumber(numStr[0:ind[0]]) {
		// The numbers are captured into groups in the regular expression.
		for _, extensionGroup := range EXTN_PATTERN.FindAllStringIndex(numStr, -1) {
			if len(extensionGroup) == 0 {
				continue
			}
			// We go through the capturing groups until we find one
			// that captured some digits. If none did, then we will
			// return the empty string.
			extension := numStr[extensionGroup[0]:extensionGroup[1]]
			number.ResetWithString(numStr[0:ind[0]])
			return extension
		}
	}
	return ""
}
1148926
func newClippedShape(id int32, numEdges int) *clippedShape {
	return &clippedShape{
		shapeID: id,
		edges:   make([]int, numEdges),
	}
}
960856
func Extents(font *truetype.Font, size float64) FontExtents {
	bounds := font.Bounds(fixed.Int26_6(font.FUnitsPerEm()))
	scale := size / float64(font.FUnitsPerEm())
	return FontExtents{
		Ascent:  float64(bounds.Max.Y) * scale,
		Descent: float64(bounds.Min.Y) * scale,
		Height:  float64(bounds.Max.Y-bounds.Min.Y) * scale,
	}
}
1089692
func (r Region) Clip(other Region) (ret Region) {
	if other.Covers(r) {
		// this region is a subregion within the other region
		return r
	}
	ret.A, ret.B = r.Begin(), r.End()
	other.A, other.B = other.Begin(), other.End()

	if ret.A >= other.A && ret.A < other.B {
		ret.A = other.B
	}
	if ret.B >= other.A && ret.B <= other.B {
		ret.B = other.A
	}
	if ret.B < ret.A {
		ret.B = ret.A
	}
	return
}
1036066
func (f *File) GetClipping(clip bool) bool {
	return f.genericBoolBoolCmd(C.SFC_GET_CLIPPING, false)
}
933946
func (c Cap) Expanded(distance s1.Angle) Cap {
	if c.IsEmpty() {
		return EmptyCap()
	}
	return CapFromCenterChordAngle(c.center, c.radius.Add(s1.ChordAngleFromAngle(distance)))
}
639490
func (cr *Context) InClip(x, y float64) bool {
	ret := C.cairo_in_clip(cr.Ptr, C.double(x), C.double(y)) != 0
	if err := cr.status(); err != nil {
		panic(err)
	}
	return ret
}