Skip to content

Commit

Permalink
Cairo matrix: add copy and newFrom + tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tinchodias committed Dec 8, 2023
1 parent 9a8820b commit fd6d509
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/Alexandrie-Cairo-Tests/AeCairoMatrixTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,26 @@ AeCairoMatrixTest >> testBeMultiplicationOfBy [
closeTo: (AeCairoMatrix newX: 0.2 y: 0.6 sx: 0.6 sy: 1.2 shx: 1.0 shy: 1.8)
]

{ #category : #tests }
AeCairoMatrixTest >> testCopy [

| aCopy |
matrix := AeCairoMatrix newX: 0.1 y: 0.2 sx: 0.3 sy: 0.4 shx: 0.5 shy: 0.6.
aCopy := matrix copy.

"Check independent change"
matrix x: 17.
aCopy x: 23.
self assert: matrix x equals: 17.
self assert: aCopy x equals: 23.

"Other factors match"
self assert: matrix sx equals: 0.3.
self assert: matrix sy equals: 0.4.
self assert: matrix shx equals: 0.5.
self assert: matrix shy equals: 0.6
]

{ #category : #tests }
AeCairoMatrixTest >> testCreation [

Expand Down Expand Up @@ -71,6 +91,26 @@ AeCairoMatrixTest >> testIsIdentity [

]

{ #category : #tests }
AeCairoMatrixTest >> testNewFrom [

| aCopy |
matrix := AeCairoMatrix newX: 0.1 y: 0.2 sx: 0.3 sy: 0.4 shx: 0.5 shy: 0.6.
aCopy := AeCairoMatrix newFrom: matrix.

"Check independent change"
matrix x: 17.
aCopy x: 23.
self assert: matrix x equals: 17.
self assert: aCopy x equals: 23.

"Other factors match"
self assert: matrix sx equals: 0.3.
self assert: matrix sy equals: 0.4.
self assert: matrix shx equals: 0.5.
self assert: matrix shy equals: 0.6
]

{ #category : #test }
AeCairoMatrixTest >> testNewRotationByRadians [

Expand Down
18 changes: 18 additions & 0 deletions src/Alexandrie-Cairo/AeCairoMatrix.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,18 @@ AeCairoMatrix class >> multiply: a by: b into: result [
AeCairoMatrix * b ) )
]

{ #category : #'instance creation' }
AeCairoMatrix class >> newFrom: aSimilarObject [

^ self
newX: aSimilarObject x
y: aSimilarObject y
sx: aSimilarObject sx
sy: aSimilarObject sy
shx: aSimilarObject shx
shy: aSimilarObject shy
]

{ #category : #'instance creation' }
AeCairoMatrix class >> newIdentity [

Expand Down Expand Up @@ -235,6 +247,12 @@ AeCairoMatrix >> closeTo: anotherMatrix precision: num [
and: [ self y closeTo: anotherMatrix y precision: num ] ] ] ] ]
]

{ #category : #copying }
AeCairoMatrix >> copy [

^ self class newFrom: self
]

{ #category : #comparing }
AeCairoMatrix >> hash [

Expand Down

0 comments on commit fd6d509

Please sign in to comment.