Matrix3_3.st
author Claus Gittinger <cg@exept.de>
Sat, 02 May 2020 21:40:13 +0200
changeset 5476 7355a4b11cb6
parent 5389 72cf3b22ba0f
permissions -rw-r--r--
#FEATURE by cg class: Socket class added: #newTCPclientToHost:port:domain:domainOrder:withTimeout: changed: #newTCPclientToHost:port:domain:withTimeout:

"{ Encoding: utf8 }"

"
 COPYRIGHT (c) 2018 by eXept Software AG
              All Rights Reserved

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.
"
"{ Package: 'stx:libbasic2' }"

"{ NameSpace: Smalltalk }"

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

!Matrix3_3 class methodsFor:'documentation'!

copyright
"
 COPYRIGHT (c) 2018 by eXept Software AG
              All Rights Reserved

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.
"
!

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$'
! !