Region
- class Region
Region
describes the set of pixels used to clipCanvas
.Region
is compact, efficiently storing a single integer rectangle, or a run length encoded array of rectangles.Region
may reduce the currentCanvas
clip, or may be drawn as one or more integer rectangles.Region
iterator returns the scan lines or rectangles contained by it, optionally intersecting a bounding rectangle.Region
supports 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
Region
intersected 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
Region
that intersect a horizontal line.Methods
Overloaded function.
Creates
Cliperator
to return elements ofIRect
array inRegion
within clip.Returns a value that increases with the number of elements in
Region
.Overloaded function.
Appends outline of
Region
to path.Returns minimum and maximum axes values of
IRect
array.Overloaded function.
Returns true if
Region
is described by more than one rectangle.Returns true if
Region
is empty.Returns true if
Region
is oneIRect
with positive dimensions.Creates
Iterator
to return elements ofIRect
array in region.Overloaded function.
Returns true if
Region
is a single rectangle and contains r.Overloaded function.
Constructs
Region
from buffer of size length.Sets
Region
to src, and returns true if src bounds is not empty.Constructs an empty
Region
.Constructs
Region
to match outline of path within clip.Constructs a rectangular
Region
matching the bounds of rect.Constructs a copy of an existing region.
Creates
Region.Spanerator
to return line segments inRegion
on scan line.Offsets
Region
by ivector (dx, dy).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
Rect
array is copied when modified.Creating a
Region
copy is very efficient and never allocates memory.Region
are always copied by value from the interface; the underlying shared pointers are not exposed.- region:
Region
to copy by value
__init__(self: skia.Region, rect: skia.IRect) -> None
- Region.cliperator(self: skia.Region, clip: skia.IRect) skia.Region.Cliperator
Creates
Cliperator
to return elements ofIRect
array inRegion
within 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
Region
is empty. Returns one ifRegion
equalsIRect
; otherwise, returns value greater than one indicating thatRegion
is complex.Call to compare
Region
for 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
Region
to path.Returns true if
Region
is not empty; otherwise, returns false, and leaves path unmodified.
- Region.getBounds(self: skia.Region) skia.IRect
Returns minimum and maximum axes values of
IRect
array.Returns (0, 0, 0, 0) if
Region
is empty.- Returns:
combined bounds of all
IRect
elements
- 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
Region
is described by more than one rectangle.
- Region.isEmpty(self: skia.Region) bool
Returns true if
Region
is empty.Empty
Region
has bounds width or height less than or equal to zero.__init__()
constructs emptyRegion
;setEmpty()
andsetRect()
with dimensionless data makeRegion
empty.- Returns:
true if bounds has no width or height
- Region.isRect(self: skia.Region) bool
Returns true if
Region
is oneIRect
with positive dimensions.
- Region.iterator(self: skia.Region) skia.Region.Iterator
Creates
Iterator
to return elements ofIRect
array 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
Region
is a single rectangle and contains r.May return false even though
Region
contains r.- Parameters:
r (skia.IRect) –
IRect
to 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
Region
from 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
Region
to src, and returns true if src bounds is not empty.This makes
Region
and src identical by value. Internally,Region
and src share pointer values. The underlyingRect
array is copied when modified.Creating a
Region
copy is very efficient and never allocates memory.Region
are always copied by value from the interface; the underlying shared pointers are not exposed.- Parameters:
src (skia.Region) –
Region
to copy- Returns:
copy of src
- Region.setEmpty(self: skia.Region) bool
Constructs an empty
Region
.Region
is 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
Region
to match outline of path within clip.Returns false if constructed
Region
is empty.Constructed
Region
draws the same pixels as path through clip when anti-aliasing is disabled.- Parameters:
clip (skia.Region) –
Region
containing path
- Returns:
true if constructed
Region
is not empty
- Region.setRect(self: skia.Region, rect: skia.IRect) bool
Constructs a rectangular
Region
matching the bounds of rect.If rect is empty, constructs empty and returns false.
- Region.setRects(self: skia.Region, rects: list[skia.IRect]) bool
Constructs
Region
as the union ofIRect
in rects array.If count is zero, constructs empty
Region
. Returns false if constructedRegion
is empty.May be faster than repeated calls to
op()
.- Parameters:
rects (List[skia.IRect]) – array of
IRect
- Returns:
true if constructed
Region
is 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
Rect
array is copied when modified.Creating a
Region
copy is very efficient and never allocates memory.Region
are always copied by value from the interface; the underlying shared pointers are not exposed.- Parameters:
region (skia.Region) –
Region
to copy by value- Returns:
Region
to copy by value
- Region.spanerator(self: skia.Region, y: int, left: int, right: int) skia.Region.Spanerator
Creates
Region.Spanerator
to return line segments inRegion
on 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
IRect
array ofRegion
and other.swap() internally exchanges pointers, so it is lightweight and does not allocate memory.
Path
do 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
Region
by ivector (dx, dy).Has no effect if
Region
is empty. IfRegion
is 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>