Skip to content

Commit

Permalink
fix conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaogu-space committed Aug 30, 2021
2 parents 8019489 + 5bfd74f commit 9d5ce4b
Show file tree
Hide file tree
Showing 57 changed files with 1,912 additions and 145 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
push:
branches: [ main ]
pull_request:
branches: [ develop ]
branches: [ main ]

jobs:

Expand Down
4 changes: 2 additions & 2 deletions algorithm/buffer/simplify/line_segment_index.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (l *LineSegmentIndex) Query(querySeg *matrix.LineSegment) []*matrix.LineSeg

visitor := &index.LineSegmentVisitor{QuerySeg: querySeg}
l.index.QueryVisitor(env, visitor)
itemsFound := visitor.Items
itemsFound := visitor.Items()

return itemsFound
return itemsFound.([]*matrix.LineSegment)
}
4 changes: 2 additions & 2 deletions algorithm/buffer/simplify/topology_preserving_simplifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ type TopologyPreservingSimplifier struct {
func (t *TopologyPreservingSimplifier) Simplify(geom matrix.Steric, distanceTolerance float64) matrix.Steric {
tss := &TopologyPreservingSimplifier{InputGeom: geom}
tss.lineSimplifier = &TaggedLinesSimplifier{
&LineSegmentIndex{quadtree.DefaultQuadtree()},
&LineSegmentIndex{quadtree.DefaultQuadtree()},
&LineSegmentIndex{quadtree.NewQuadtree()},
&LineSegmentIndex{quadtree.NewQuadtree()},
distanceTolerance,
}
tss.setDistanceTolerance(distanceTolerance)
Expand Down
103 changes: 103 additions & 0 deletions algorithm/calc/bytevalues/byte_values.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
// Package bytevalues ead and write primitive datatypes from/to byte
package bytevalues

import "math"

// Byte order: big endian or little endian
const (
BigEndian = 0
LittleEndian = 1
)

// GetInt32 Returns int32 read primitive datatypes from/to byte
// sequences, allowing the byte order to be specified
func GetInt32(buf []byte, byteOrder int) uint32 {
if byteOrder == BigEndian {
return uint32((buf[0]&0xff))<<24 | uint32((buf[1]&0xff))<<16 | uint32((buf[2]&0xff))<<8 | uint32(buf[3]&0xff)
}
return uint32((buf[3]&0xff))<<24 | uint32((buf[2]&0xff))<<16 | uint32((buf[1]&0xff))<<8 | uint32(buf[0]&0xff)

}

// PutInt32 write primitive datatypes from/to byte
// sequences, allowing the byte order to be specified
func PutInt32(buf []byte, intValue int32, byteOrder int) {
if byteOrder == BigEndian {
buf[0] = byte(intValue >> 24)
buf[1] = byte(intValue >> 16)
buf[2] = byte(intValue >> 8)
buf[3] = byte(intValue)
} else { // LITTLE_ENDIAN
buf[0] = byte(intValue)
buf[1] = byte(intValue >> 8)
buf[2] = byte(intValue >> 16)
buf[3] = byte(intValue >> 24)
}
}

// GetInt64 Returns int64 read primitive datatypes from/to byte
// sequences, allowing the byte order to be specified
func GetInt64(buf []byte, byteOrder int) uint64 {
if byteOrder == BigEndian {
return uint64((buf[0]&0xff))<<56 | uint64(buf[1]&0xff)<<48 |
uint64(buf[2]&0xff)<<40 | uint64(buf[3]&0xff)<<32 |
uint64(buf[4]&0xff)<<24 | uint64(buf[5]&0xff)<<16 |
uint64(buf[6]&0xff)<<8 | uint64(buf[7]&0xff)
}
return uint64(buf[7]&0xff)<<56 | uint64(buf[6]&0xff)<<48 |
uint64(buf[5]&0xff)<<40 | uint64(buf[4]&0xff)<<32 |
uint64(buf[3]&0xff)<<24 | uint64(buf[2]&0xff)<<16 |
uint64(buf[1]&0xff)<<8 | uint64(buf[0]&0xff)
}

// PutInt64 write primitive datatypes from/to byte
// sequences, allowing the byte order to be specified
func PutInt64(buf []byte, intValue int64, byteOrder int) {
if byteOrder == BigEndian {
buf[0] = byte(intValue >> 56)
buf[1] = byte(intValue >> 48)
buf[2] = byte(intValue >> 40)
buf[3] = byte(intValue >> 32)
buf[4] = byte(intValue >> 24)
buf[5] = byte(intValue >> 16)
buf[6] = byte(intValue >> 8)
buf[7] = byte(intValue)
} else { // LITTLE_ENDIAN
buf[0] = byte(intValue)
buf[1] = byte(intValue >> 8)
buf[2] = byte(intValue >> 16)
buf[3] = byte(intValue >> 24)
buf[4] = byte(intValue >> 32)
buf[5] = byte(intValue >> 40)
buf[6] = byte(intValue >> 48)
buf[7] = byte(intValue >> 56)
}
}

// GetFloat32 Returns float32 read primitive datatypes from/to byte
// sequences, allowing the byte order to be specified
func GetFloat32(buf []byte, byteOrder int) float32 {
longVal := GetInt32(buf, byteOrder)
return math.Float32frombits(longVal)
}

// PutFloat32 write primitive datatypes from/to byte
// sequences, allowing the byte order to be specified
func PutFloat32(buf []byte, floatValue float32, byteOrder int) {
longVal := math.Float32bits(floatValue)
PutInt32(buf, int32(longVal), byteOrder)
}

// GetFloat64 Returns float64 read primitive datatypes from/to byte
// sequences, allowing the byte order to be specified
func GetFloat64(buf []byte, byteOrder int) float64 {
longVal := GetInt64(buf, byteOrder)
return math.Float64frombits(longVal)
}

// PutFloat64 write primitive datatypes from/to byte
// sequences, allowing the byte order to be specified
func PutFloat64(buf []byte, floatValue float64, byteOrder int) {
longVal := math.Float64bits(floatValue)
PutInt64(buf, int64(longVal), byteOrder)
}
25 changes: 25 additions & 0 deletions algorithm/calc/bytevalues/byte_values_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Package bytevalues ead and write primitive datatypes from/to byte
package bytevalues

import "testing"

func TestGetInt32(t *testing.T) {
type args struct {
buf []byte
byteOrder int
}
tests := []struct {
name string
args args
want uint32
}{
{"Getint32", args{[]byte{1, 0, 0, 32}, 1}, 1},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := GetInt32(tt.args.buf, tt.args.byteOrder); (got&0xffff)%1000 != tt.want {
t.Errorf("GetInt32() = %v, want %v", got, tt.want)
}
})
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import (
"github.com/spatial-go/geoos/algorithm/matrix"
)

// Chains Computes a list of the {@link MonotoneChain}s for a list of coordinates.
// Chains Computes a list of the MonotoneChains for a list of coordinates.
func Chains(edge matrix.LineMatrix) []*MonotoneChain {
return ChainsContext(edge, nil)
}

// ChainsContext Computes a list of the {@link MonotoneChain}s for a list of coordinates,attaching a context data object to each.
// ChainsContext Computes a list of the MonotoneChains for a list of coordinates,attaching a context data object to each.
func ChainsContext(edge matrix.LineMatrix, context interface{}) []*MonotoneChain {
mcList := []*MonotoneChain{}
chainStart := 0
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion algorithm/overlay/line_merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func MergeMatrix(ml matrix.Collection, i, j int, result matrix.Collection) (matr
return ml, false
}
for _, v := range ml[j].(matrix.LineMatrix).ToLineArray() {
if relate.InLine(m0, v.P0, v.P1) {
if in, _ := relate.InLine(m0, v.P0, v.P1); in {
result = append(result, ml[:i]...)
result = append(result, ml[i+1:]...)
return result, true
Expand Down
4 changes: 2 additions & 2 deletions algorithm/overlay/overlay_line.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (

"github.com/spatial-go/geoos/algorithm"
"github.com/spatial-go/geoos/algorithm/matrix"
"github.com/spatial-go/geoos/algorithm/overlay/chain"
"github.com/spatial-go/geoos/algorithm/relate"
"github.com/spatial-go/geoos/index/chain"
)

// LineOverlay Computes the overlay of two geometries,either or both of which may be nil.
Expand Down Expand Up @@ -119,7 +119,7 @@ func IntersectLine(m, m1 matrix.LineMatrix) []relate.IntersectionResult {
il := relate.IntersectionResult{Ips: relate.IntersectionPointLine{}}
for i, line := range m.ToLineArray() {
for _, ip := range ips {
if relate.InLine(ip.Matrix, line.P0, line.P1) {
if in, _ := relate.InLine(ip.Matrix, line.P0, line.P1); in {
il.Pos = i
il.Line = *line
il.Start = i
Expand Down
59 changes: 59 additions & 0 deletions algorithm/overlay/sweepline/sweep_line_event.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package sweepline

// Sweepline const parameter.
const (
InsertStatus = iota + 1
DeleteStatus
)

// Event ...
type Event struct {
xValue float64
eventType int
InsertEvent *Event // null if this is an INSERT event
DeleteEventIndex int

SweepInt *Interval
}

// NewEvent create a default NewEvent.
func NewEvent(x float64, insertEvent *Event, sweepInt *Interval) *Event {
s := &Event{}
s.xValue = x
s.InsertEvent = insertEvent
s.eventType = InsertStatus
if s.InsertEvent != nil {
s.eventType = DeleteStatus
}
s.SweepInt = sweepInt
return s
}

// IsInsert ...
func (s *Event) IsInsert() bool {
return s.InsertEvent == nil
}

// IsDelete ...
func (s *Event) IsDelete() bool {
return s.InsertEvent != nil
}

// Compare ProjectionEvents are ordered first by their x-value, and then by their eventType.
// It is important that Insert events are sorted before Delete events, so that
// items whose Insert and Delete events occur at the same x-value will be correctly handled.
func (s *Event) Compare(pe *Event) int {
if s.xValue < pe.xValue {
return -1
}
if s.xValue > pe.xValue {
return 1
}
if s.eventType < pe.eventType {
return -1
}
if s.eventType > pe.eventType {
return 1
}
return 0
}
83 changes: 83 additions & 0 deletions algorithm/overlay/sweepline/sweep_line_index.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
//Package sweepline Contains struct which implement a sweepline algorithm for scanning geometric data structures.
package sweepline

import (
"sort"
)

// Index A sweepline implements a sorted index on a set of intervals.
// It is used to compute all overlaps between the interval in the index.
type Index struct {
events LineEvents
indexBuilt bool
nOverlaps int
}

// Add ...
func (s *Index) Add(sweepInt *Interval) {
insertEvent := NewEvent(sweepInt.Min, nil, sweepInt)
s.events = append(s.events, insertEvent)
s.events = append(s.events, NewEvent(sweepInt.Max, insertEvent, sweepInt))
}

// buildIndex Because Delete Events have a link to their corresponding Insert event,
// it is possible to compute exactly the range of events which must be
// compared to a given Insert event object.
func (s *Index) buildIndex() {
if s.indexBuilt {
return
}
sort.Sort(s.events)
for i, ev := range s.events {
if ev.IsDelete() {
ev.InsertEvent.DeleteEventIndex = i
}
}
s.indexBuilt = true
}

// ComputeOverlaps compute overlaps.
func (s *Index) ComputeOverlaps(action OverlapAction) {
s.nOverlaps = 0
s.buildIndex()

for i, ev := range s.events {
if ev.IsInsert() {
s.processOverlaps(i, ev.DeleteEventIndex, ev.SweepInt, action)
}
}
}

func (s *Index) processOverlaps(start, end int, s0 *Interval, action OverlapAction) {
/**
* Since we might need to test for self-intersections,
* include current insert event object in list of event objects to test.
* Last index can be skipped, because it must be a Delete event.
*/
for i := start; i < end; i++ {
ev := s.events[i]
if ev.IsInsert() {
if action.Overlap(s0, ev.SweepInt) {
s.nOverlaps++
}
}
}
}

// LineEvents ...
type LineEvents []*Event

// Len ...
func (it LineEvents) Len() int {
return len(it)
}

// Less ...
func (it LineEvents) Less(i, j int) bool {
return it[i].Compare(it[j]) == -1
}

// Swap ...
func (it LineEvents) Swap(i, j int) {
it[i], it[j] = it[j], it[i]
}
Loading

0 comments on commit 9d5ce4b

Please sign in to comment.