Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions src/Geometry-Tests/GEllipseTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,36 @@ GEllipseTest >> testEquals [
assert: (GEllipse center: 10 @ 10 a: 5 b: 10) hash
equals: (GEllipse center: 10 @ 10 a: 5 b: 10) hash
]

{ #category : #tests }
GEllipseTest >> testHash [

self
assert: (GEllipse center: 10 @ 10 a: 5 b: 10) hash
equals: 17696867
]

{ #category : #tests }
GEllipseTest >> testIntersectLineSegment [

self
assert: ((GEllipse center: 0 @ 0 a: 3 b: 2) intersectLineSegment:
(GLineSegment from: 0 @ 0 to: 0 @ 3))
equals: {
(0 @ -2).
(0 @ 2) } asOrderedCollection
]

{ #category : #tests }
GEllipseTest >> testNotEquals [

self
deny: (GCircle center: 2 @ 2 radius: 3)
equals: (GEllipse center: 5 @ 5 a: 2 b: 3).
self
deny: (GEllipse center: 10 @ 10 a: 5 b: 10)
equals: (GEllipse center: 5 @ 5 a: 2 b: 3).
self
deny: (GEllipse center: 10 @ 10 a: 5 b: 10) hash
equals: (GEllipse center: 5 @ 5 a: 2 b: 3) hash
]
211 changes: 201 additions & 10 deletions src/Geometry-Tests/GLineTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,35 @@ GLineTest >> testCutWith [
equals: nil.
]

{ #category : #tests }
GLineTest >> testCutWith2 [

self
assert: ((GLine a: 0 b: 1 c: -3) cutWith: (GPolygon newVertices: {
(1 @ 5).
(1 @ 2).
(1 @ 4).
(1 @ 1).
(3 @ 1).
(3 @ 5) })) v2
equals: 3 @ 3
]

{ #category : #tests }
GLineTest >> testDist [
self
assert: ((GLine a:1 b:0 c: -7)dist: 7 @ 0)
equals: 0.
self
assert: ((GLine a:1 b:0 c: -7)dist: 7 @ 7)
equals: 0.
self
assert: ((GLine a:1 b:0 c: -7)dist: 0 @ 0)
equals: 7.


self
assert: ((GLine a: 1 b: 0 c: -7) dist: 7 @ 0)
equals: 0.
self
assert: ((GLine a: 1 b: 0 c: -7) dist: 7 @ 7)
equals: 0.
self
assert: ((GLine a: 1 b: 0 c: -7) dist: 0 @ 0)
equals: 7.
self
assert: ((GLine a: -4 b: 2 c: -3) dist: 2 @ 2)
equals: 1.5652475842498528
]

{ #category : #tests }
Expand Down Expand Up @@ -109,6 +125,71 @@ self

]

{ #category : #tests }
GLineTest >> testEquel5 [

self
assert: (GLine a: 6000000 b: 6000000 c: 2000000)
= (GLine a: 0.000006 b: 0.000006 c: 0.000002)
equals: true.
self
assert: (GLine a: 2 b: 5 c: 3) = (GLine a: 2 b: 5 c: 2)
equals: false.
self
assert: (GLine a: 2 b: 5 c: 3) = (GLine a: 1 b: 5 c: 3)
equals: false.
self
assert: (GLine a: 2 b: 5 c: 3) = (GLine a: 2 b: 4 c: 3)
equals: false.
self
assert: (GLine a: 1 b: 0 c: 0) = (GLine a: 6 b: 0 c: 0)
equals: true.
self
assert: (GLine a: 0 b: 0 c: 1) = (GLine a: 0 b: 0 c: 6)
equals: true.
self
assert: (GLine a: 5 b: 4 c: 4) = (GLine a: 0 b: 2 c: 2)
equals: false.
self
assert: (GLine a: 5 b: 4 c: 4) = (GLine a: 2 b: 2 c: 0)
equals: false.
self
assert: (GLine a: 4 b: 0 c: 4) = (GLine a: 2 b: 2 c: 2)
equals: false
]

{ #category : #tests }
GLineTest >> testEquel6 [

self
assert: (GLine a: 1 b: 0 c: 0) = (GLine a: 0 b: 1 c: 0)
equals: false.
self
assert: (GLine a: 1 b: 0 c: 0) = (GLine a: 0 b: 0 c: 1)
equals: false.
self
assert: (GLine a: 0 b: 1 c: 0) = (GLine a: 1 b: 0 c: 0)
equals: false.
self
assert: (GLine a: 0 b: 1 c: 0) = (GLine a: 0 b: 0 c: 1)
equals: false.
self
assert: (GLine a: 0 b: 0 c: 1) = (GLine a: 1 b: 0 c: 0)
equals: false.
self
assert: (GLine a: 0 b: 0 c: 1) = (GLine a: 0 b: 1 c: 0)
equals: false.
self
assert: (GLine a: 0 b: 1 c: 1) = (GLine a: 1 b: 0 c: 0)
equals: false.
self
assert: (GLine a: 1 b: 0 c: 1) = (GLine a: 0 b: 1 c: 0)
equals: false.
self
assert: (GLine a: 1 b: 1 c: 0) = (GLine a: 0 b: 0 c: 1)
equals: false
]

{ #category : #tests }
GLineTest >> testHasPoint [
"self
Expand All @@ -132,6 +213,18 @@ self
assert: ((GSegment with: ((17674/229)@(14582/229)) with:([email protected]))
asLine hasPoint: ((9244/147)@(1090/21)) withApproximation: 0.525738602984892 )
equals: true."
self
assert: ((GLine a: -2 b: 1 c: -1) hasPoint: 1@3 withApproximation: 0)
equals: true
]

{ #category : #tests }
GLineTest >> testHash [

self assert: (GLine a: 1 b: 3 c: -2) hash equals: 242268498.
self
deny: (GLine a: 1 b: 3 c: -2) hash
equals: (GLine a: 1 b: 3 c: 2) hash
]

{ #category : #tests }
Expand Down Expand Up @@ -162,6 +255,88 @@ self
self
assert: ((GLine a: 0 b: 2 c: 0.5) parallelTo: (GLine a: 0 b: 2 c: 0.5))
equals: true.
self
assert: ((GLine a: 1 b: 0 c: 0.5) parallelTo: (GLine a: 2 b: 0 c: 4))
equals: true
.
self
assert: ((GLine a: 0 b: 0 c: 0) parallelTo: (GLine a: 0 b: 0 c: 0))
equals: true
]

{ #category : #tests }
GLineTest >> testPointsWithDist1To [

self
assert: ((GLine a: -1 b: 1 c: 0) pointsWithDist: 2 to: 1 @ 1)
equals: {
(2.414213562373095 @ 2.414213562373095).
(-0.4142135623730949 @ -0.4142135623730949) }.
self
assert: ((GLine a: -2 b: 3 c: 0) pointsWithDist: 2 to: 3 @ 2)
equals: {
(4.664100588675687 @ 3.1094003924504583).
(1.3358994113243126 @ 0.8905996075495417) }.
self
assert: ((GLine a: 1 b: 0 c: -2) pointsWithDist: 2 to: 2 @ 1)
equals: {
(2 @ 3).
(2 @ -1) }
]

{ #category : #tests }
GLineTest >> testPointsWithDistTo [

self
assert: ((GLine a: -1 b: 1 c: 0) pointsWithDist1: 2 to: 1 @ 1)
equals: {
(2.414213562373095 @ 2.414213562373095).
(-0.4142135623730949 @ -0.4142135623730949) }.
self
assert: ((GLine a: -2 b: 3 c: 0) pointsWithDist1: 2 to: 3 @ 2)
equals: {
(4.664100588675687 @ 3.1094003924504583).
(1.3358994113243126 @ 0.8905996075495417) }.
self
assert: ((GLine a: 1 b: 0 c: -2) pointsWithDist1: 2 to: 2 @ 1)
equals: {
(2 @ 3).
(2 @ -1) }
]

{ #category : #tests }
GLineTest >> testPointsWithDistToRaiseError [

self
should: [ (GLine a: -2 b: 1 c: 0) pointsWithDist: 2 to: 1 @ 1 ]
raise: Error
]

{ #category : #tests }
GLineTest >> testPrintOn [

self
assert:
(String streamContents: [ :s | (GLine a: 1 b: 2 c: 3) printOn: s ])
equals: '1x +2y +3 = 0'.
self
assert:
(String streamContents: [ :s | (GLine a: 1 b: 0 c: 0) printOn: s ])
equals: '1x +0y +0 = 0'.
self
assert:
(String streamContents: [ :s | (GLine a: 1 b: -2 c: -3) printOn: s ])
equals: '1x -2y -3 = 0'
]

{ #category : #tests }
GLineTest >> testThroughAnd [

| l1 l2 |
l1 := GLine through: 2 @ 3 and: 3 @ 3.
l2 := GLine through: 2 @ 2 and: 2 @ 3.
self assert: l1 equals: (GLine a: 0 b: 1 c: -3).
self assert: l2 equals: (GLine a: 1 b: 0 c: -2)
]

{ #category : #tests }
Expand All @@ -176,3 +351,19 @@ self
assert: ((GLine through: 1@1 and: 2@2)through: 1@1 and: 2@2 hasPoint: 2@1 )
equals: false.
]

{ #category : #tests }
GLineTest >> testXFor [

self assert: ((GLine a: -3 b: 1 c: 0) xFor: 3) equals: 1.
self assert: ((GLine a: -3 b: 2 c: 0) xFor: 3) equals: 2.
self assert: ((GLine a: -3 b: 1 c: 2) xFor: 1) equals: 1
]

{ #category : #tests }
GLineTest >> testYFor [

self assert: ((GLine a: -3 b: 1 c: 0) yFor: 1) equals: 3.
self assert: ((GLine a: -3 b: 2 c: 0) yFor: 2) equals: 3.
self assert: ((GLine a: -3 b: 1 c: 2) yFor: 1) equals: 1
]
12 changes: 12 additions & 0 deletions src/Geometry-Tests/GRectangleTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,18 @@ GRectangleTest >> testHasPoint [
equals: false.
]

{ #category : #tests }
GRectangleTest >> testIntersectLineSegment [

self
assert:
((GRectangle origin: 1 @ 3 corner: 3 @ 0) intersectLineSegment:
(GLineSegment from: 0 @ 2 to: 4 @ 2))
equals: {
(1 @ 2).
(3 @ 2) } asSet
]

{ #category : #tests }
GRectangleTest >> testIntersectionPointWithRay [
self assert:((Rectangle origin: 1 @ 3 corner: 3 @ 0) intersectionPointWithRay: ((GRay origin: 2@1 direction: 4@1 )))
Expand Down
81 changes: 81 additions & 0 deletions src/Geometry-Tests/GRoundedRectangleTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ Class {
#category : #'Geometry-Tests'
}

{ #category : #tests }
GRoundedRectangleTest >> testCenter [

self
assert: (GRoundedRectangle
rectangle: (GRectangle origin: -2 @ -1 corner: 2 @ 1)
borderRadius: 0.5) center
equals: 0 @ 0
]

{ #category : #tests }
GRoundedRectangleTest >> testCorners [
| rect |
Expand Down Expand Up @@ -39,3 +49,74 @@ GRoundedRectangleTest >> testCorners [
startAngle: Float threePi / 2
endAngle: Float twoPi))
]

{ #category : #tests }
GRoundedRectangleTest >> testEncompassingRectangle [

| rect |
rect := GRoundedRectangle
rectangle: (GRectangle origin: -40 @ -20 corner: 40 @ 20)
borderRadius: 10.
self
assert: (GRoundedRectangle
rectangle: (GRectangle origin: -40 @ -20 corner: 40 @ 20)
borderRadius: 10) encompassingRectangle
equals: (GRectangle origin: -40 @ -20 corner: 40 @ 20)
]

{ #category : #tests }
GRoundedRectangleTest >> testEqual [

self
assert: (GRoundedRectangle
rectangle: (GRectangle origin: -2 @ -1 corner: 2 @ 1)
borderRadius: 0.5)
equals: (GRoundedRectangle
rectangle: (GRectangle origin: -2 @ -1 corner: 2 @ 1)
borderRadius: 0.5).
self
deny: (GRoundedRectangle
rectangle: (GRectangle origin: -2 @ -1 corner: 2 @ 1)
borderRadius: 0.5)
equals: (GRoundedRectangle
rectangle: (GRectangle origin: -2 @ -1 corner: 2 @ 1)
borderRadius: 1).
self
deny: (GRoundedRectangle
rectangle: (GRectangle origin: -2 @ -1 corner: 2 @ 1)
borderRadius: 0.5)
equals: (GRoundedRectangle
rectangle: (GRectangle origin: -2 @ -1 corner: 2 @ 2)
borderRadius: 0.5).
self
deny: (GRoundedRectangle
rectangle: (GRectangle origin: -2 @ -1 corner: 2 @ 1)
borderRadius: 0.5)
equals: (GRoundedRectangle
rectangle: (GRectangle origin: -2 @ -1 corner: 2 @ 2)
borderRadius: 1).
self deny: (GRoundedRectangle
rectangle: (GRectangle origin: -2 @ -1 corner: 2 @ 1)
borderRadius: 0.5) = (Rectangle origin: -2 @ -1 corner: 2 @ 1)
]

{ #category : #tests }
GRoundedRectangleTest >> testIntersectLineSegment [

| rect |
rect := GRoundedRectangle
rectangle: (GRectangle origin: -40 @ -20 corner: 40 @ 20)
borderRadius: 10.
self
assert:
(rect intersectLineSegment: (GLineSegment from: -40 @ 15 to: 40 @ 15))
equals: {
(-38.66025403784438 @ 15.0).
(38.660254037844396 @ 15.0) }.
self
assert:
(rect intersectLineSegment: (GLineSegment from: -40 @ 5 to: 40 @ 5))
equals: {
(-40 @ 5).
(40 @ 5) } asSet
]
Loading