clipping

command
v0.11.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 24, 2025 License: MIT Imports: 3 Imported by: 0

README

Clipping Example

This example demonstrates the clipping API in gogpu/gg.

Features Demonstrated

  1. Circular Clip - Using Clip() to set a circular clipping region
  2. ClipRect - Fast rectangular clipping with ClipRect()
  3. ClipPreserve - Using ClipPreserve() to clip and then stroke the same path
  4. Nested Clips - Multiple intersecting clips with Push()/Pop()
  5. Complex Path - Clipping with curved Bezier paths

API Methods

  • Clip() - Set current path as clip region, clear path
  • ClipPreserve() - Set current path as clip region, keep path
  • ClipRect(x, y, w, h) - Fast rectangular clip
  • ResetClip() - Remove all clipping regions
  • Push()/Pop() - Save/restore clip state

Running

go run main.go

This will generate output.png showing all clipping examples.

Integration with Push/Pop

Clipping state is saved and restored with Push()/Pop():

dc.Push()
dc.ClipRect(10, 10, 100, 100)
// Drawing is clipped
dc.Pop() // Clip is restored

Performance Notes

  • ClipRect() is faster than creating a rectangular path and calling Clip()
  • Anti-aliased clipping is enabled by default for smooth edges
  • Multiple clips are intersected (AND operation)

Documentation

Overview

Package main demonstrates the clipping API in gogpu/gg. This example shows how to use Clip(), ClipPreserve(), ClipRect(), and ResetClip() to create various clipping effects.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL