csgpoly

package
v0.4.0-rc.3 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2026 License: Apache-2.0 Imports: 3 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package csgpoly holds the rules the outline of a CSG polygon must meet. Package pkg/world3d/csg applies them when it builds a polygon and package pkg/sceneformat when it validates a scene before anything is built; sceneformat cannot import csg (csg imports render3d, which imports sceneformat), so both call this one implementation and cannot drift apart.

Index

Constants

View Source
const (
	// MaxPoints is the most points an outline may have.
	MaxPoints = 2048
	// AxisTolerance is how far from the Y axis a spin outline's X may be and still count as on it.
	AxisTolerance = 1e-7
)

Variables

This section is empty.

Functions

func Normalize

func Normalize(in []Point) ([]Point, *Error)

Normalize checks that in is a simple polygon: between 3 and MaxPoints finite points, at least 3 of them distinct, with non-zero area and no edge crossing or touching another. It returns the points with consecutive duplicates (and a closing point equal to the first) dropped, in counter-clockwise order.

Types

type Error

type Error struct {
	// Index is the input index of the point that breaks the rule, or -1 when the rule is about the outline as a whole.
	Index int
	// TooComplex is true when the outline has more than MaxPoints points, a complexity limit rather than invalid input.
	TooComplex bool
	// Reason describes the broken rule, such as "polygon has zero area".
	Reason string
}

Error is a rule an outline breaks.

func CheckSpin

func CheckSpin(in []Point) *Error

CheckSpin checks that an outline revolved around the Y axis stays on one side of it: every point at X >= 0 and at least one at X > 0, within a small tolerance.

func (*Error) Error

func (e *Error) Error() string

Error returns Reason.

type Point

type Point struct{ X, Y float64 }

Point is one outline point in the polygon's XY plane.

Jump to

Keyboard shortcuts

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