Skip to content

Commit

Permalink
condense code
Browse files Browse the repository at this point in the history
  • Loading branch information
akevalion committed Oct 27, 2023
1 parent e3c0822 commit 987b92d
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 26 deletions.
4 changes: 2 additions & 2 deletions src/RTree-Tests/RTCollectionTest.class.st
Expand Up @@ -152,7 +152,7 @@ RTCollectionTest >> testOneElement [
RTCollectionTest >> testSortResultArray [

| shapes a b c d tree e |
shapes := {
shapes := {
((a := RTreeBox model: 'a') -> { 1. 1 }).
((b := RTreeBox model: 'b') -> { 1. 2 }).
((c := RTreeBox model: 'c') -> { 3. 1 }).
Expand All @@ -161,7 +161,7 @@ RTCollectionTest >> testSortResultArray [
tree := RTreeCollection new.
tree sortResultList: shapes.

self assert: (shapes collect: #key) equals: {
self assert: (shapes collect: #key) equals: {
c.
e.
d.
Expand Down
3 changes: 1 addition & 2 deletions src/RTree-Tests/RTreeBox.class.st
Expand Up @@ -26,8 +26,7 @@ Class {
RTreeBox class >> model: anObject [
^ self new
model: anObject;
yourself

yourself
]

{ #category : 'adding' }
Expand Down
16 changes: 8 additions & 8 deletions src/RTree-Tests/RTreeTest.class.st
Expand Up @@ -258,7 +258,7 @@ RTreeTest >> testSearchPath3 [
RTreeTest >> testSortResultArray [

| entries a b c d e |
entries := {
entries := {
((a := RTreeBox model: 'a') -> { 1. 1 }).
((b := RTreeBox model: 'b') -> { 1. 2 }).
((c := RTreeBox model: 'c') -> { 3. 1 }).
Expand All @@ -267,7 +267,7 @@ RTreeTest >> testSortResultArray [
tree := RTreeCollection new.
tree sortResultList: entries.

self assert: (entries collect: #key) equals: {
self assert: (entries collect: #key) equals: {
c.
e.
d.
Expand Down Expand Up @@ -314,7 +314,7 @@ RTreeTest >> testThreeElementsContains [

result := tree entriesAtRectangle: (-20@ -20 corner: 40@40).
self assert: result size equals: 3.
self assert: result asArray equals: { b2. b1. b3 }.
self assert: result asArray equals: { b2. b1. b3 }
]

{ #category : 'tests' }
Expand Down Expand Up @@ -352,7 +352,7 @@ RTreeTest >> testTwoElementsContains [
| b1 b2 result |
b1 := RTreeBox new size: 10; entryIndex: 1.
b2 := RTreeBox new size: 30; position: 25@ 25; entryIndex: 2.

tree addAll: { b1. b2 }.
result := tree entriesAtPoint: 0@0.
self assert: result first equals: b1.
Expand Down Expand Up @@ -387,14 +387,14 @@ RTreeTest >> testUpdateExtentShouldUpdateTreeRectangle [
box := RTreeBox new.
box extent: oldExtent.
collection add: box.

self assert: collection root rectangle equals: box encompassingRectangle.

box extent: newExtent.
collection updateEntry: box.

self assert: box encompassingRectangle extent equals: newExtent.
self assert: collection root rectangle equals: box encompassingRectangle.
self assert: collection root rectangle equals: box encompassingRectangle
]

{ #category : 'tests' }
Expand Down
4 changes: 2 additions & 2 deletions src/RTree/RTAbstractCollection.class.st
Expand Up @@ -18,13 +18,13 @@ Class {
{ #category : 'examples' }
RTAbstractCollection class >> exampleList [
"in the inspector add and remove shapes"
^ StInspectorPresenter openOn: RTSequenceableCollection new.
^ StInspectorPresenter openOn: RTSequenceableCollection new
]

{ #category : 'examples' }
RTAbstractCollection class >> exampleRTree [
"this has normal method collections with some new more"
^ StInspectorPresenter openOn: RTreeCollection new.
^ StInspectorPresenter openOn: RTreeCollection new
]

{ #category : 'adding' }
Expand Down
5 changes: 2 additions & 3 deletions src/RTree/RTNode.class.st
Expand Up @@ -66,15 +66,14 @@ RTNode >> balanceZ: z y: y x: x [
^ self llrotationZ: c y: b x: a ].
(y key not and: [ x key ]) ifTrue: [
^ self lrrotationZ: c y: b x: a ].
^ self rlrotationZ: c y: b x: a.
^ self rlrotationZ: c y: b x: a
]

{ #category : 'accessing' }
RTNode >> children [
^ self isLeaf
ifTrue: [ #() ]
ifFalse: [ { left. right } ]

]

{ #category : 'enumerating' }
Expand Down Expand Up @@ -146,7 +145,7 @@ RTNode >> ensureBalancePath: aCollection [
self balanceZ: z y: y x: x.
]
]
].
]
]

{ #category : 'private' }
Expand Down
2 changes: 1 addition & 1 deletion src/RTree/RTSequenceableCollection.class.st
Expand Up @@ -46,7 +46,7 @@ RTSequenceableCollection >> initialize [

{ #category : 'shapes - ordering' }
RTSequenceableCollection >> pushBack: anRTEntry [
entries remove: anRTEntry; addFirst: anRTEntry.
entries remove: anRTEntry; addFirst: anRTEntry
]

{ #category : 'shapes - ordering' }
Expand Down
15 changes: 7 additions & 8 deletions src/RTree/RTreeCollection.class.st
Expand Up @@ -34,7 +34,7 @@ RTreeCollection >> add: anRTEntry [

{ #category : 'private - removing' }
RTreeCollection >> balanceRemovedPath: path [

(1 to: path size -2) reverseDo: [ :index | | tree |
tree := (path at: index) value.
tree height: (tree left height max: tree right height)+1.
Expand All @@ -51,7 +51,7 @@ RTreeCollection >> balanceRemovedPath: path [
in order to keep it balanced
maybe you can move a lot of nodes"
].
].
]
]

{ #category : 'enumerating' }
Expand Down Expand Up @@ -142,7 +142,7 @@ RTreeCollection >> removeLastNodeInPath: path [
parent := path nextToLast value.
isRight := last key.
last := last value.
brother := isRight
brother := isRight
ifTrue: [ parent left ]
ifFalse: [ parent right ].

Expand All @@ -157,8 +157,8 @@ RTreeCollection >> root [
]

{ #category : 'public' }
RTreeCollection >> shouldSwap: anAssociation and: anAssociation2 [
RTreeCollection >> shouldSwap: anAssociation and: anAssociation2 [

| v1 v2 size|
v1 := anAssociation value.
v2 := anAssociation2 value.
Expand All @@ -167,13 +167,12 @@ RTreeCollection >> shouldSwap: anAssociation and: anAssociation2 [
1 to: size do: [ :i| |index1 index2|
index1 := v1 at: i.
index2 := v2 at: i.
index1 = index2 ifFalse: [
index1 = index2 ifFalse: [
^ index1 > index2 ]
].
^ v1 size = v2 size
^ v1 size = v2 size
ifTrue: [ false ]
ifFalse: [ v1 size > v2 size ]

]

{ #category : 'public' }
Expand Down

0 comments on commit 987b92d

Please sign in to comment.