diff --git a/src/Geometry-Tests/GEllipseTest.class.st b/src/Geometry-Tests/GEllipseTest.class.st index f2643b3..9a7654a 100644 --- a/src/Geometry-Tests/GEllipseTest.class.st +++ b/src/Geometry-Tests/GEllipseTest.class.st @@ -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 +] diff --git a/src/Geometry-Tests/GLineTest.class.st b/src/Geometry-Tests/GLineTest.class.st index 99cc40e..a8c4983 100644 --- a/src/Geometry-Tests/GLineTest.class.st +++ b/src/Geometry-Tests/GLineTest.class.st @@ -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 } @@ -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 @@ -132,6 +213,18 @@ self assert: ((GSegment with: ((17674/229)@(14582/229)) with:(76.82622578909061@64.97050543967634)) 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 } @@ -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 } @@ -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 +] diff --git a/src/Geometry-Tests/GRectangleTest.class.st b/src/Geometry-Tests/GRectangleTest.class.st index a8c8019..8749478 100644 --- a/src/Geometry-Tests/GRectangleTest.class.st +++ b/src/Geometry-Tests/GRectangleTest.class.st @@ -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 ))) diff --git a/src/Geometry-Tests/GRoundedRectangleTest.class.st b/src/Geometry-Tests/GRoundedRectangleTest.class.st index c19b155..10d1f40 100644 --- a/src/Geometry-Tests/GRoundedRectangleTest.class.st +++ b/src/Geometry-Tests/GRoundedRectangleTest.class.st @@ -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 | @@ -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 +] diff --git a/src/Geometry-Tests/GSegmentTest.class.st b/src/Geometry-Tests/GSegmentTest.class.st index 4d63272..4566215 100644 --- a/src/Geometry-Tests/GSegmentTest.class.st +++ b/src/Geometry-Tests/GSegmentTest.class.st @@ -80,6 +80,23 @@ self assert:((GSegment with: -2 @ 4 with: -2 @ 0) belowPoint: -4 @ 2 ) equals: false. ] +{ #category : #tests } +GSegmentTest >> testBoundBy [ + + self + assert: ((GSegment with: 0 @ 0 with: 1 @ 1) boundBy: 0 @ 0) + equals: true. + self + assert: ((GSegment with: 0 @ 0 with: 1 @ 1) boundBy: 1 @ 1) + equals: true. + self + assert: ((GSegment with: 0 @ 0 with: 1 @ 1) boundBy: 1 @ 0) + equals: false. + self + assert: ((GSegment with: 0 @ 0 with: 0 @ 0) boundBy: 0 @ 0) + equals: true +] + { #category : #tests } GSegmentTest >> testCutWith [ self @@ -99,6 +116,30 @@ GSegmentTest >> testCutWith [ equals: nil. ] +{ #category : #tests } +GSegmentTest >> testCutWith2 [ + + self + assert: ((GSegment with: 1 @ 2 with: 2 @ 2) cutWith: + (Rectangle origin: 0 @ 2 corner: 3 @ 0)) + equals: (GSegment with: 1 @ 2 with: 2 @ 2). + self + assert: ((GSegment with: 20 @ 30 with: -10 @ 10) cutWith: + (Rectangle origin: -15 @ 0 corner: 15 @ 15)) + equals: (GSegment with: -5 / 2 @ 15 with: -10 @ 10). + self + assert: + ((GSegment with: 1 @ 3 with: 5 @ 3) cutWith: + (GPolygon newVertices: { + (1 @ 5). + (1 @ 2). + (1 @ 4). + (1 @ 1). + (3 @ 1). + (3 @ 5) })) v2 + equals: 3 @ 3 +] + { #category : #tests } GSegmentTest >> testDist1 [ self assert:( ((GSegment with: ((838/41)@(4811/82)) with:((57583/914)@(56095/914))) dist: (57.998905906959145@61.11074842728413)) <=~ (2 * 0.02757564283371476 ) ) @@ -168,6 +209,31 @@ GSegmentTest >> testEqual3 [ equals:true ] +{ #category : #tests } +GSegmentTest >> testEqual4 [ + + self + assert: (GSegment with: 1 @ 1 with: 1 @ 1) + = (GSegment with: 1 @ 1 with: 1 @ 1) + equals: true. + self + assert: (GSegment with: 1 @ 2 with: 3 @ 4) + = (GSegment with: 1 @ 2 with: 3 @ 3) + equals: false. + self + assert: (GSegment with: 1 @ 2 with: 3 @ 3) + = (GSegment with: 1 @ 1 with: 3 @ 3) + equals: false. + self + assert: (GSegment with: 1 @ 2 with: 3 @ 4) + = (GSegment with: 3 @ 3 with: 1 @ 2) + equals: false. + self + assert: (GSegment with: 1 @ 2 with: 3 @ 3) + = (GSegment with: 3 @ 3 with: 1 @ 1) + equals: false +] + { #category : #tests } GSegmentTest >> testExtendSegmVert [ | segm1 segm2 segm3 frame | @@ -211,6 +277,29 @@ self assert:((GSegment with: -2 @ 4 with: 2 @ 4) extendWith: 3 @ 4 and: frame) equals: (GSegment with: 3 @ 4 with: -5 @ 4). ] +{ #category : #tests } +GSegmentTest >> testExtendWithAnd2 [ + + | frame | + frame := Rectangle origin: -5 @ 0 corner: 5 @ 5. + self + assert: + ((GSegment with: -2 @ 4 with: 2 @ 4) extendWith: -3 @ 4 and: frame) + equals: (GSegment with: -3 @ 4 with: 5 @ 4). + self + assert: + ((GSegment with: -2 @ 4 with: 2 @ 4) extendWith: -3 @ 4 and: frame) + equals: (GSegment with: 5 @ 4 with: -3 @ 4). + self + assert: + ((GSegment with: -2 @ 4 with: 2 @ 4) extendWith: 3 @ 3 and: frame) + equals: (GSegment with: -2 @ 4 with: 2 @ 4). + self + assert: + ((GSegment with: -2 @ 4 with: 2 @ 4) extendWith: 6 @ 4 and: frame) + equals: (GSegment with: 6 @ 4 with: -5 @ 4) +] + { #category : #tests } GSegmentTest >> testHas [ @@ -222,6 +311,52 @@ GSegmentTest >> testHas [ equals: true. ] +{ #category : #tests } +GSegmentTest >> testHas2 [ + + self + assert: ((GSegment with: 0 @ 0 with: 2 @ 2) has: 2 @ 1) + equals: false. + self + assert: ((GSegment with: 0 @ 0 with: 2 @ 3) has: 2 @ 3) + equals: true. + self + assert: ((GSegment with: 0 @ 0 with: 2 @ 3) has: 0 @ 0) + equals: true. + self + assert: ((GSegment with: 2 @ 3 with: 0 @ 0) has: 2 @ 3) + equals: true. + self + assert: ((GSegment with: 2 @ 3 with: 0 @ 0) has: 0 @ 0) + equals: true. + self + assert: ((GSegment with: 2 @ 3 with: 0 @ 0) has: 1 @ (3/2)) + equals: true +] + +{ #category : #tests } +GSegmentTest >> testHas3 [ + + self + assert: ((GSegment with: 2 @ 0 with: 2 @ 2) has: 2 @ 3) + equals: false. + self + assert: ((GSegment with: 2 @ 0 with: 2 @ 2) has: 2 @ -1) + equals: false. + self + assert: ((GSegment with: 2 @ 0 with: 2 @ 2) has: 2 @ 1) + equals: true. + self + assert: ((GSegment with: 0 @ 2 with: 2 @ 2) has: 3 @ 2) + equals: false. + self + assert: ((GSegment with: 0 @ 2 with: 2 @ 2) has: -1 @ 2) + equals: false. + self + assert: ((GSegment with: 0 @ 2 with: 2 @ 2) has: 1 @ 2) + equals: true +] + { #category : #tests } GSegmentTest >> testHasPoint [ @@ -233,6 +368,26 @@ GSegmentTest >> testHasPoint [ equals: true. ] +{ #category : #tests } +GSegmentTest >> testHasPoint2 [ + + self + assert: ((GSegment with: 1 @ 1 with: 3 @ 3) hasPoint: 4 @ 4) + equals: false. + self + assert: ((GSegment with: 1 @ 3 with: 3 @ 1) hasPoint: 4 @ 2) + equals: false. + self + assert: ((GSegment with: 3 @ 1 with: 1 @ 3) hasPoint: 2 @ 0) + equals: false +] + +{ #category : #tests } +GSegmentTest >> testHash [ + + self assert: (GSegment with: 0 @ 1 with: 2 @ 3) hash equals: 1571190 +] + { #category : #tests } GSegmentTest >> testIntersect [ self @@ -257,6 +412,21 @@ GSegmentTest >> testIntersect2 [ equals: (0@0) ] +{ #category : #tests } +GSegmentTest >> testIntersectionPointWithLine [ + + self + assert: + ((GSegment with: 2 @ 0 with: 2 @ 3) intersectionPointWithLine: + (GLine through: 0 @ 1 and: 2 @ 1)) + equals: 2 @ 1. + self + assert: + ((GSegment with: 2 @ 2 with: 2 @ 3) intersectionPointWithLine: + (GLine through: 0 @ 1 and: 2 @ 1)) + equals: nil +] + { #category : #tests } GSegmentTest >> testIntersectionPointWithVector [ self @@ -273,6 +443,21 @@ GSegmentTest >> testIntersectionPointWithVector [ equals: 0 @ 0. ] +{ #category : #tests } +GSegmentTest >> testIntersectionPointWithVector2 [ + + self + assert: + ((GSegment with: 0 @ 0 with: 0 @ 3) intersectionPointWithRay: + (GRay origin: 1 @ 2 direction: 2 @ 2)) + equals: nil. + self + assert: + ((GSegment with: 0 @ 0 with: 0 @ 1) intersectionPointWithRay: + (GRay origin: 0 @ 2 direction: 2 @ 2)) + equals: nil +] + { #category : #tests } GSegmentTest >> testIsOnLinePointWithRespectWith [ "self assert: ((GSegment with:((18427/974)@(57187/974)) with:(362.2460738148583@ -421.94450334080176)) hasOnLinePoint: ((838/41)@(4811/82)) withRespectTo: ((18427/974)@(57187/974)) withApprox: 0.8902246907382428) @@ -305,6 +490,20 @@ GSegmentTest >> testLength1 [ equals: 34 sqrt ] +{ #category : #tests } +GSegmentTest >> testLocationOf [ + + self + assert: ((GSegment with: 0 @ 0 with: 2 @ 2) locationOf: 1 @ 1) + equals: 0. + self + assert: ((GSegment with: 10 @ 10 with: 30 @ 20) locationOf: 15 @ 15) + equals: 1. + self + assert: ((GSegment with: 10 @ 10 with: 20 @ 30) locationOf: 15 @ 15) + equals: -1 +] + { #category : #tests } GSegmentTest >> testMidPoint [ self diff --git a/src/Geometry-Tests/GTriangleTest.class.st b/src/Geometry-Tests/GTriangleTest.class.st index 484fbbc..416c53b 100644 --- a/src/Geometry-Tests/GTriangleTest.class.st +++ b/src/Geometry-Tests/GTriangleTest.class.st @@ -51,6 +51,15 @@ GTriangleTest >> testCircumscribedCircle3 [ +] + +{ #category : #tests } +GTriangleTest >> testCircumscribedCircle4 [ + + self + assert: (GTriangle with: 1000 @ 0 with: 50 @ 0 with: 0 @ 0) + circumscribedCircle + equals: nil ] { #category : #tests } @@ -97,6 +106,19 @@ self ] +{ #category : #tests } +GTriangleTest >> testIsDegenerate5 [ + + self assert: + (GTriangle with: 0 @ 0 with: 0 @ 3 with: 0 @ 1) isDegenerate. + self assert: + (GTriangle with: 0 @ 0 with: 0 @ 0 with: 0 @ 1) isDegenerate. + self assert: + (GTriangle with: 0 @ 0 with: 0 @ 3 with: 0 @ 3) isDegenerate. + self assert: + (GTriangle with: 0 @ 0 with: 0 @ 0 with: 0 @ 0) isDegenerate +] + { #category : #tests } GTriangleTest >> testPerimeter [ self diff --git a/src/Geometry/GLine.class.st b/src/Geometry/GLine.class.st index d88f734..3d3fa7a 100644 --- a/src/Geometry/GLine.class.st +++ b/src/Geometry/GLine.class.st @@ -12,7 +12,7 @@ Class { 'b', 'c' ], - #category : 'Geometry' + #category : #Geometry } { #category : #'as yet unclassified' } @@ -49,7 +49,12 @@ or: ifTrue:[ ( self b / line b ) asFloat =~ ( self c / line c ) asFloat ] ifFalse:[ ( line a ~=~ 0 and:[ line b ~=~ 0] ) ifTrue:[ ( self a / line a ) asFloat =~ ( self b / line b ) asFloat ] - ifFalse:[ ( line a =~ 0 and: [ line c =~ 0 ] ) or: [ ( line b =~ 0 and: [ line c =~ 0 ] ) ] + ifFalse:[ line a ~=~ 0 + ifTrue: [ self b =~ 0 and: [ self c =~ 0 ] ] + ifFalse: [ line b ~=~0 + ifTrue: [ self a =~ 0 and: [ self c =~ 0 ] ] + ifFalse: [ self a =~ 0 and: [ self b =~ 0 ] ] + ] ] ] ]]] @@ -112,7 +117,7 @@ GLine >> hasPoint: aPoint [ { #category : #properties } GLine >> hasPoint: aPoint withApproximation: approx [ - (self a * aPoint x) + (self b * aPoint y) + self c - (((self a * approx) + (self b * approx))abs + self c) <=~ 0. + "(self a * aPoint x) + (self b * aPoint y) + self c - (((self a * approx) + (self b * approx))abs + self c) <=~ 0." ^ "(self a * aPoint x) + (self b * aPoint y) + self c <=~ (2 * approx)" (self dist: aPoint) <=~ (2 * approx) diff --git a/src/Geometry/GRoundedRectangle.class.st b/src/Geometry/GRoundedRectangle.class.st index a3505b4..084fdd7 100644 --- a/src/Geometry/GRoundedRectangle.class.st +++ b/src/Geometry/GRoundedRectangle.class.st @@ -8,7 +8,7 @@ Class { 'rectangle', 'borderRadius' ], - #category : 'Geometry' + #category : #Geometry } { #category : #'instance creation' } @@ -73,9 +73,13 @@ GRoundedRectangle >> encompassingRectangle [ { #category : #comparing } GRoundedRectangle >> intersectLine: aLine [ - (self corners flatCollect: [ :each | aLine intersectCircleArc: each ]) + "same as intersectLineSegment:" + + "(self corners flatCollect: [ :each | aLine intersectCircleArc: each ]) ifNotEmpty: [ :col | ^ col ]. - ^ aLine intersectRectangle: self rectangle + ^ aLine intersectRectangle: self rectangle" + + ] { #category : #comparing } diff --git a/src/Geometry/GSegment.class.st b/src/Geometry/GSegment.class.st index 5f9f1fa..1c4ac16 100644 --- a/src/Geometry/GSegment.class.st +++ b/src/Geometry/GSegment.class.st @@ -9,7 +9,7 @@ Class { 'v2', 'epsilon' ], - #category : 'Geometry' + #category : #Geometry } { #category : #'as yet unclassified' } diff --git a/src/Geometry/Point.extension.st b/src/Geometry/Point.extension.st index fd58a83..b31dad5 100644 --- a/src/Geometry/Point.extension.st +++ b/src/Geometry/Point.extension.st @@ -6,6 +6,12 @@ Point >> =~ aPoint [ ] +{ #category : #'*Geometry' } +Point >> dist: aPoint [ + + ^ self distanceTo: aPoint +] + { #category : #'*Geometry' } Point >> has: aPoint onTheSameSideAs: p [ (self x <= p x)