Region
- class Region
Regiondescribes the set of pixels used to clipCanvas.Regionis compact, efficiently storing a single integer rectangle, or a run length encoded array of rectangles.Regionmay reduce the currentCanvasclip, or may be drawn as one or more integer rectangles.Regioniterator returns the scan lines or rectangles contained by it, optionally intersecting a bounding rectangle.Regionsupports a few operators:regionA == regionB # Equality regionA != regionB # Inequality regionA - regionB # Difference regionA & regionB # Intersect regionA | regionB # Union regionA ^ regionB # XOR regionA -= regionB # In-place Difference regionA &= regionB # In-place Intersect regionA |= regionB # In-place Union regionA ^= regionB # In-place XOR
Classes
Returns the sequence of rectangles, sorted along y-axis, then x-axis, that make up
Regionintersected with the specified clip rectangle.Returns sequence of rectangles, sorted along y-axis, then x-axis, that make up
Region.Members:
Returns the line segment ends within
Regionthat intersect a horizontal line.Methods
cliperator(self: skia.Region, clip: skia.IRect) -> skia.Region.Cliperator
computeRegionComplexity(self: skia.Region) -> int
getBoundaryPath(self: skia.Region, path: SkPath) -> bool
getBounds(self: skia.Region) -> skia.IRect
isComplex(self: skia.Region) -> bool
isEmpty(self: skia.Region) -> bool
isRect(self: skia.Region) -> bool
iterator(self: skia.Region) -> skia.Region.Iterator
quickContains(self: skia.Region, r: skia.IRect) -> bool
readFromMemory(self: skia.Region, data: SkData) -> int
set(self: skia.Region, src: skia.Region) -> bool
setEmpty(self: skia.Region) -> bool
setPath(self: skia.Region, path: SkPath, clip: skia.Region) -> bool
setRect(self: skia.Region, rect: skia.IRect) -> bool
setRects(self: skia.Region, rects: list[skia.IRect]) -> bool
setRegion(self: skia.Region, region: skia.Region) -> bool
spanerator(self: skia.Region, y: int, left: int, right: int) -> skia.Region.Spanerator
swap(self: skia.Region, other: skia.Region) -> None
translate(self: skia.Region, dx: int, dy: int) -> skia.Region
writeToMemory(self: skia.Region) -> SkData
Attributes
Methods
- Region.__init__(*args, **kwargs)
Overloaded function.
__init__(self: skia.Region) -> None
__init__(self: skia.Region, region: skia.Region) -> None
Constructs a copy of an existing region.
Copy constructor makes two regions identical by value. Internally, region and the returned result share pointer values. The underlying
Rectarray is copied when modified.Creating a
Regioncopy is very efficient and never allocates memory.Regionare always copied by value from the interface; the underlying shared pointers are not exposed.- region:
Regionto copy by value
__init__(self: skia.Region, rect: skia.IRect) -> None
- Region.cliperator(self: skia.Region, clip: skia.IRect) skia.Region.Cliperator
Creates
Cliperatorto return elements ofIRectarray inRegionwithin clip.Example:
for rect in region.cliperator(skia.IRect(100, 100)): pass
- Parameters:
clip (skia.IRect) – bounds of iteration
- Region.computeRegionComplexity(self: skia.Region) int
Returns a value that increases with the number of elements in
Region.Returns zero if
Regionis empty. Returns one ifRegionequalsIRect; otherwise, returns value greater than one indicating thatRegionis complex.Call to compare
Regionfor relative complexity.- Returns:
relative complexity
- Region.contains(*args, **kwargs)
Overloaded function.
contains(self: skia.Region, x: int, y: int) -> bool
contains(self: skia.Region, other: skia.IRect) -> bool
contains(self: skia.Region, other: skia.Region) -> bool
- Region.getBoundaryPath(self: skia.Region, path: SkPath) bool
Appends outline of
Regionto path.Returns true if
Regionis not empty; otherwise, returns false, and leaves path unmodified.
- Region.getBounds(self: skia.Region) skia.IRect
Returns minimum and maximum axes values of
IRectarray.Returns (0, 0, 0, 0) if
Regionis empty.- Returns:
combined bounds of all
IRectelements
- Region.intersects(*args, **kwargs)
Overloaded function.
intersects(self: skia.Region, rect: skia.IRect) -> bool
intersects(self: skia.Region, other: skia.Region) -> bool
- Region.isComplex(self: skia.Region) bool
Returns true if
Regionis described by more than one rectangle.
- Region.isEmpty(self: skia.Region) bool
Returns true if
Regionis empty.Empty
Regionhas bounds width or height less than or equal to zero.__init__()constructs emptyRegion;setEmpty()andsetRect()with dimensionless data makeRegionempty.- Returns:
true if bounds has no width or height
- Region.isRect(self: skia.Region) bool
Returns true if
Regionis oneIRectwith positive dimensions.
- Region.iterator(self: skia.Region) skia.Region.Iterator
Creates
Iteratorto return elements ofIRectarray in region.Example:
for rect in region.iterator(): pass
- Region.op(*args, **kwargs)
Overloaded function.
op(self: skia.Region, rect: skia.IRect, op: skia.Region.Op) -> bool
op(self: skia.Region, region: skia.Region, op: skia.Region.Op) -> bool
op(self: skia.Region, rect: skia.IRect, region: skia.Region, op: skia.Region.Op) -> bool
op(self: skia.Region, region: skia.Region, rect: skia.IRect, op: skia.Region.Op) -> bool
op(self: skia.Region, regionA: skia.Region, regionB: skia.Region, op: skia.Region.Op) -> bool
- Region.quickContains(self: skia.Region, r: skia.IRect) bool
Returns true if
Regionis a single rectangle and contains r.May return false even though
Regioncontains r.- Parameters:
r (skia.IRect) –
IRectto contain- Returns:
true quickly if r points are equal or inside
- Region.quickReject(*args, **kwargs)
Overloaded function.
quickReject(self: skia.Region, rect: skia.IRect) -> bool
quickReject(self: skia.Region, region: skia.Region) -> bool
- Region.readFromMemory(self: skia.Region, data: SkData) int
Constructs
Regionfrom buffer of size length.Returns bytes read. Returned value will be multiple of four or zero if length was too small.
- Parameters:
data (skia.Data) – binary data
- Returns:
bytes read
- Region.set(self: skia.Region, src: skia.Region) bool
Sets
Regionto src, and returns true if src bounds is not empty.This makes
Regionand src identical by value. Internally,Regionand src share pointer values. The underlyingRectarray is copied when modified.Creating a
Regioncopy is very efficient and never allocates memory.Regionare always copied by value from the interface; the underlying shared pointers are not exposed.- Parameters:
src (skia.Region) –
Regionto copy- Returns:
copy of src
- Region.setEmpty(self: skia.Region) bool
Constructs an empty
Region.Regionis set to empty bounds at (0, 0) with zero width and height. Always returns false.- Returns:
false
- Region.setPath(self: skia.Region, path: SkPath, clip: skia.Region) bool
Constructs
Regionto match outline of path within clip.Returns false if constructed
Regionis empty.Constructed
Regiondraws the same pixels as path through clip when anti-aliasing is disabled.- Parameters:
clip (skia.Region) –
Regioncontaining path
- Returns:
true if constructed
Regionis not empty
- Region.setRect(self: skia.Region, rect: skia.IRect) bool
Constructs a rectangular
Regionmatching the bounds of rect.If rect is empty, constructs empty and returns false.
- Region.setRects(self: skia.Region, rects: list[skia.IRect]) bool
Constructs
Regionas the union ofIRectin rects array.If count is zero, constructs empty
Region. Returns false if constructedRegionis empty.May be faster than repeated calls to
op().- Parameters:
rects (List[skia.IRect]) – array of
IRect- Returns:
true if constructed
Regionis not empty
- Region.setRegion(self: skia.Region, region: skia.Region) bool
Constructs a copy of an existing region.
Makes two regions identical by value. Internally, region and the returned result share pointer values. The underlying
Rectarray is copied when modified.Creating a
Regioncopy is very efficient and never allocates memory.Regionare always copied by value from the interface; the underlying shared pointers are not exposed.- Parameters:
region (skia.Region) –
Regionto copy by value- Returns:
Regionto copy by value
- Region.spanerator(self: skia.Region, y: int, left: int, right: int) skia.Region.Spanerator
Creates
Region.Spaneratorto return line segments inRegionon scan line.Example:
for left, right in region.spanerator(5, 0, 100): pass
- Parameters:
y (int) – horizontal line to intersect
left (int) – bounds of iteration
right (int) – bounds of iteration
- Region.swap(self: skia.Region, other: skia.Region) None
Exchanges
IRectarray ofRegionand other.swap() internally exchanges pointers, so it is lightweight and does not allocate memory.
Pathdo not copy their content on assignment until they are written to, making assignment as efficient as swap().- Parameters:
other (skia.Region) – other region to swap
- Region.translate(self: skia.Region, dx: int, dy: int) skia.Region
Offsets
Regionby ivector (dx, dy).Has no effect if
Regionis empty. IfRegionis empty, returns empty region.- Dx:
x-axis offset
- Dy:
y-axis offset
- Region.writeToMemory(self: skia.Region) SkData
-
- Returns:
Attributes
- Region.kDifference_Op = <Op.kDifference_Op: 0>
- Region.kIntersect_Op = <Op.kIntersect_Op: 1>
- Region.kLastOp = <Op.kReplace_Op: 5>
- Region.kOpCnt = 6
- Region.kReplace_Op = <Op.kReplace_Op: 5>
- Region.kReverseDifference_Op = <Op.kReverseDifference_Op: 4>
- Region.kUnion_Op = <Op.kUnion_Op: 2>
- Region.kXOR_Op = <Op.kXOR_Op: 3>