Matrix3_3.st
author Claus Gittinger <cg@exept.de>
Wed, 21 Aug 2019 10:34:29 +0200
changeset 5111 ab3d7db395d2
parent 5087 2d85f44acc3e
child 5136 761208260bf6
permissions -rw-r--r--
#DOCUMENTATION by exept class: Matrix3_3 class comment/format in: #documentation

"{ Encoding: utf8 }"

"{ Package: 'stx:libbasic2' }"

"{ NameSpace: Smalltalk }"

SquareMatrix variableSubclass:#Matrix3_3
	instanceVariableNames:''
	classVariableNames:''
	poolDictionaries:''
	category:'Collections-MultiDimensional'
!

!Matrix3_3 class methodsFor:'documentation'!

documentation
"
    3x3 Matrix (2 dimensions).
    Especially useful with the ArrayIndexing-Parser extension.

    [author:]
        Claus Gittinger (cg@sinir)

    [instance variables:]

    [class variables:]

    [see also:]
        MatrixAccessor
"
! !

!Matrix3_3 class methodsFor:'instance creation'!

new
    ^ self basicNew:3*3
! !

!Matrix3_3 methodsFor:'accessing'!

_at:index1 at:index2
    "this is a synthetic selector, generated by the compiler,
     if a construct of the form expr[idx...] is parsed.
     I.e. 
        foo[n,m]
     generates
        foo _at:n at:m
    "
    |idx|

    (index1 between:1 and:3) ifFalse:[self subscriptBoundsError:index1].
    (index2 between:1 and:3) ifFalse:[self subscriptBoundsError:index2].

    idx := index1 * 3 - 3 + index2.
    ^ self basicAt:idx.
!

_at:index1 at:index2 put:value
    "this is a synthetic selector, generated by the compiler,
     if a construct of the form expr[idx...] := val is parsed.
     I.e. 
        foo[n,m] := val
     generates
        foo _at:n at:m put:val
    "
    |idx|

    (index1 between:1 and:3) ifFalse:[self subscriptBoundsError:index1].
    (index2 between:1 and:3) ifFalse:[self subscriptBoundsError:index2].

    idx := index1 * 3 - 3 + index2.
    ^ self basicAt:idx put:value.
! !

!Matrix3_3 methodsFor:'matrix operations'!

determinantByCofactors
    "Answer the determinant of this matrix."

    ^ ((self _at: 1 at: 1) * (((self _at: 2 at: 2)*(self _at: 3 at: 3)) - ((self _at: 3 at: 2)*(self _at: 2 at: 3)))) -
      ((self _at: 1 at: 2) * (((self _at: 2 at: 1)*(self _at: 3 at: 3)) - ((self _at: 3 at: 1)*(self _at: 2 at: 3)))) +
      ((self _at: 1 at: 3) * (((self _at: 2 at: 1)*(self _at: 3 at: 2)) - ((self _at: 3 at: 1)*(self _at: 2 at: 2)))).
! !

!Matrix3_3 class methodsFor:'documentation'!

version_CVS
    ^ '$Header$'
! !