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