mirror of
https://bitbucket.org/s_l_teichmann/mtsatellite
synced 2024-12-23 08:40:18 +01:00
unexport span types
This commit is contained in:
parent
493da71d53
commit
88e9088704
@ -106,8 +106,8 @@ func BlendColor(c1, c2 color.RGBA, a float32) color.RGBA {
|
||||
A: 0xff}
|
||||
}
|
||||
|
||||
func (colors *Colors) BlendColors(span *Span, col color.RGBA, pos int32) color.RGBA {
|
||||
curr := span
|
||||
func (colors *Colors) BlendColors(sp *span, col color.RGBA, pos int32) color.RGBA {
|
||||
curr := sp
|
||||
// Ignore colors below pos.
|
||||
for curr != nil && pos >= curr.To {
|
||||
curr = curr.Next
|
||||
|
@ -9,11 +9,11 @@ import "sync"
|
||||
type zRange struct {
|
||||
y1 int16
|
||||
y2 int16
|
||||
xRange *Span
|
||||
xRange *span
|
||||
}
|
||||
|
||||
type Coverage3D struct {
|
||||
pool *SpanPool
|
||||
pool *spanPool
|
||||
zRanges map[int16]*zRange
|
||||
mu sync.RWMutex
|
||||
}
|
||||
@ -28,7 +28,7 @@ type Range struct {
|
||||
|
||||
func NewCoverage3D() *Coverage3D {
|
||||
return &Coverage3D{
|
||||
pool: NewSpanPool(),
|
||||
pool: newSpanPool(),
|
||||
zRanges: map[int16]*zRange{}}
|
||||
}
|
||||
|
||||
@ -47,7 +47,7 @@ func (c3d *Coverage3D) Insert(c Coord) {
|
||||
xRange: xr}
|
||||
return
|
||||
}
|
||||
zr.xRange = c3d.pool.Insert(zr.xRange, int32(c.X), 0)
|
||||
zr.xRange = c3d.pool.insert(zr.xRange, int32(c.X), 0)
|
||||
if c.Y < zr.y1 {
|
||||
zr.y1 = c.Y
|
||||
}
|
||||
|
@ -21,8 +21,8 @@ type Renderer struct {
|
||||
RejectedBlocks int
|
||||
SolidBlocks int
|
||||
TransparentBlocks int
|
||||
spans *SpanPool
|
||||
tBuffer []*Span
|
||||
spans *spanPool
|
||||
tBuffer []*span
|
||||
}
|
||||
|
||||
func NewRenderer(width, height int, transparent bool) (renderer *Renderer) {
|
||||
@ -32,12 +32,12 @@ func NewRenderer(width, height int, transparent bool) (renderer *Renderer) {
|
||||
cBuffer := make([]int32, pixSize)
|
||||
yMin := make([]int32, dim)
|
||||
|
||||
var tBuffer []*Span
|
||||
var spans *SpanPool
|
||||
var tBuffer []*span
|
||||
var spans *spanPool
|
||||
|
||||
if transparent {
|
||||
tBuffer = make([]*Span, pixSize)
|
||||
spans = NewSpanPool()
|
||||
tBuffer = make([]*span, pixSize)
|
||||
spans = newSpanPool()
|
||||
}
|
||||
|
||||
renderer = &Renderer{
|
||||
@ -94,7 +94,7 @@ func (r *Renderer) Reset() {
|
||||
tb := r.tBuffer
|
||||
for i, t := range tb {
|
||||
if t != nil {
|
||||
r.spans.FreeAll(t)
|
||||
r.spans.freeAll(t)
|
||||
tb[i] = nil
|
||||
}
|
||||
}
|
||||
@ -195,7 +195,7 @@ func (r *Renderer) RenderBlock(block *Block, colors *Colors) (err error) {
|
||||
cY := blockY + int32(y)
|
||||
|
||||
if colors.IsTransparent(c) {
|
||||
r.tBuffer[ofs] = r.spans.Insert(r.tBuffer[ofs], cY, c)
|
||||
r.tBuffer[ofs] = r.spans.insert(r.tBuffer[ofs], cY, c)
|
||||
// We need to continue to go down because we
|
||||
// can see through this node.
|
||||
} else {
|
||||
@ -302,7 +302,7 @@ func (r *Renderer) CreateShadedImage(
|
||||
y := r.yBuffer[ofs]
|
||||
t := r.tBuffer[ofs]
|
||||
|
||||
opaque := t == nil || t.Top() < y
|
||||
opaque := t == nil || t.top() < y
|
||||
|
||||
var y1, y2 int32
|
||||
|
||||
@ -312,7 +312,7 @@ func (r *Renderer) CreateShadedImage(
|
||||
y1 = r.yBuffer[ofs-1]
|
||||
if opaque {
|
||||
if s := r.tBuffer[ofs-1]; s != nil {
|
||||
y1 = max32(y1, s.Top())
|
||||
y1 = max32(y1, s.top())
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -322,7 +322,7 @@ func (r *Renderer) CreateShadedImage(
|
||||
y2 = r.yBuffer[ofs+pw]
|
||||
if opaque {
|
||||
if s := r.tBuffer[ofs+pw]; s != nil {
|
||||
y1 = max32(y1, s.Top())
|
||||
y1 = max32(y1, s.top())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,29 +11,29 @@ import (
|
||||
|
||||
const chunkSize = 1024
|
||||
|
||||
type Span struct {
|
||||
type span struct {
|
||||
Value int32
|
||||
From int32
|
||||
To int32
|
||||
Next *Span
|
||||
Next *span
|
||||
}
|
||||
|
||||
type SpanPool struct {
|
||||
freeList *Span
|
||||
type spanPool struct {
|
||||
freeList *span
|
||||
}
|
||||
|
||||
func NewSpanPool() *SpanPool {
|
||||
return &SpanPool{}
|
||||
func newSpanPool() *spanPool {
|
||||
return &spanPool{}
|
||||
}
|
||||
|
||||
func (sp *SpanPool) Alloc() *Span {
|
||||
func (sp *spanPool) Alloc() *span {
|
||||
if sp.freeList != nil {
|
||||
next := sp.freeList
|
||||
sp.freeList = next.Next
|
||||
return next
|
||||
}
|
||||
|
||||
spans := make([]Span, chunkSize)
|
||||
spans := make([]span, chunkSize)
|
||||
|
||||
for i := chunkSize - 1; i > 0; i-- {
|
||||
spans[i].Next = sp.freeList
|
||||
@ -43,14 +43,14 @@ func (sp *SpanPool) Alloc() *Span {
|
||||
return &spans[0]
|
||||
}
|
||||
|
||||
func (sp *SpanPool) Free(s *Span) {
|
||||
func (sp *spanPool) free(s *span) {
|
||||
if s != nil {
|
||||
s.Next = sp.freeList
|
||||
sp.freeList = s
|
||||
}
|
||||
}
|
||||
|
||||
func (sp *SpanPool) FreeAll(s *Span) {
|
||||
func (sp *spanPool) freeAll(s *span) {
|
||||
if s == nil {
|
||||
return
|
||||
}
|
||||
@ -62,7 +62,7 @@ func (sp *SpanPool) FreeAll(s *Span) {
|
||||
sp.freeList = head
|
||||
}
|
||||
|
||||
func (sp *SpanPool) Insert(s *Span, pos, value int32) *Span {
|
||||
func (sp *spanPool) insert(s *span, pos, value int32) *span {
|
||||
|
||||
// No head -> create.
|
||||
if s == nil {
|
||||
@ -98,7 +98,7 @@ func (sp *SpanPool) Insert(s *Span, pos, value int32) *Span {
|
||||
if next != nil && next.From == s.To+1 && value == next.Value {
|
||||
s.To = next.To
|
||||
s.Next = next.Next
|
||||
sp.Free(next)
|
||||
sp.free(next)
|
||||
}
|
||||
return head
|
||||
}
|
||||
@ -122,13 +122,13 @@ func (sp *SpanPool) Insert(s *Span, pos, value int32) *Span {
|
||||
return head
|
||||
}
|
||||
|
||||
func (s *Span) Visit(v func(*Span)) {
|
||||
func (s *span) visit(v func(*span)) {
|
||||
for ; s != nil; s = s.Next {
|
||||
v(s)
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Span) Len() int {
|
||||
func (s *span) len() int {
|
||||
n := 0
|
||||
for ; s != nil; s = s.Next {
|
||||
n++
|
||||
@ -136,17 +136,17 @@ func (s *Span) Len() int {
|
||||
return n
|
||||
}
|
||||
|
||||
func (s *Span) Top() int32 {
|
||||
func (s *span) top() int32 {
|
||||
for s.Next != nil {
|
||||
s = s.Next
|
||||
}
|
||||
return s.To
|
||||
}
|
||||
|
||||
func (s *Span) String() string {
|
||||
func (s *span) String() string {
|
||||
var buf bytes.Buffer
|
||||
first := true
|
||||
s.Visit(func(s1 *Span) {
|
||||
s.visit(func(s1 *span) {
|
||||
if !first {
|
||||
buf.WriteString(", ")
|
||||
} else {
|
||||
|
@ -13,45 +13,45 @@ const spanItems = 3000
|
||||
|
||||
func TestSpans(t *testing.T) {
|
||||
|
||||
sp := NewSpanPool()
|
||||
var s *Span
|
||||
sp := newSpanPool()
|
||||
var s *span
|
||||
|
||||
for i := 0; i < spanItems; i++ {
|
||||
s = sp.Insert(s, int32(i), 42)
|
||||
s = sp.insert(s, int32(i), 42)
|
||||
}
|
||||
|
||||
if n := s.Len(); n != 1 {
|
||||
if n := s.len(); n != 1 {
|
||||
t.Errorf("inc: Span length %d expected 1\n", n)
|
||||
t.Errorf("spans: %s\n", s)
|
||||
}
|
||||
|
||||
sp.FreeAll(s)
|
||||
sp.freeAll(s)
|
||||
|
||||
s = nil
|
||||
for i := spanItems - 1; i >= 0; i-- {
|
||||
s = sp.Insert(s, int32(i), 42)
|
||||
s = sp.insert(s, int32(i), 42)
|
||||
}
|
||||
|
||||
if n := s.Len(); n != 1 {
|
||||
if n := s.len(); n != 1 {
|
||||
t.Errorf("dec: Span length %d expected 1\n", n)
|
||||
t.Errorf("spans: %s\n", s)
|
||||
}
|
||||
|
||||
sp.FreeAll(s)
|
||||
sp.freeAll(s)
|
||||
|
||||
s = nil
|
||||
for i := 0; i < spanItems/2; i++ {
|
||||
j := spanItems - 1 - i
|
||||
s = sp.Insert(s, int32(i), 42)
|
||||
s = sp.Insert(s, int32(j), 21)
|
||||
s = sp.insert(s, int32(i), 42)
|
||||
s = sp.insert(s, int32(j), 21)
|
||||
}
|
||||
|
||||
if n := s.Len(); n != 2 {
|
||||
if n := s.len(); n != 2 {
|
||||
t.Errorf("two: Span length %d expected 2\n", n)
|
||||
t.Errorf("spans: %s\n", s)
|
||||
}
|
||||
|
||||
sp.FreeAll(s)
|
||||
sp.freeAll(s)
|
||||
|
||||
inp := make([]int32, spanItems)
|
||||
for i := 0; i < spanItems; i++ {
|
||||
@ -66,13 +66,13 @@ func TestSpans(t *testing.T) {
|
||||
|
||||
s = nil
|
||||
for i := 0; i < spanItems; i++ {
|
||||
s = sp.Insert(s, inp[i], 42)
|
||||
s = sp.insert(s, inp[i], 42)
|
||||
}
|
||||
|
||||
if n := s.Len(); n != 1 {
|
||||
if n := s.len(); n != 1 {
|
||||
t.Errorf("rand: Span length %d expected 1\n", n)
|
||||
t.Errorf("spans: %s\n", s)
|
||||
}
|
||||
|
||||
sp.FreeAll(s)
|
||||
sp.freeAll(s)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user