Matrix2_2.st
author Claus Gittinger <cg@exept.de>
Sat, 02 May 2020 21:40:13 +0200
changeset 5476 7355a4b11cb6
parent 5379 9f07dbcb8d23
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:#Matrix2_2
	instanceVariableNames:''
	classVariableNames:''
	poolDictionaries:''
	category:'Collections-MultiDimensional'
!

!Matrix2_2 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
"
    2x2 Matrix (2 dimensions).
    Especially useful with the ArrayIndexing-Parser extension.

    [author:]
        Claus Gittinger (cg@sinir)

    [instance variables:]

    [class variables:]

    [see also:]
        MatrixAccessor
"
! !

!Matrix2_2 class methodsFor:'instance creation'!

new
    ^ self basicNew:2*2
! !

!Matrix2_2 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:2) ifFalse:[self subscriptBoundsError:index1].
    (index2 between:1 and:2) ifFalse:[self subscriptBoundsError:index2].

    idx := index1 * 2 - 2 + 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:2) ifFalse:[self subscriptBoundsError:index1].
    (index2 between:1 and:2) ifFalse:[self subscriptBoundsError:index2].

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

!Matrix2_2 methodsFor:'matrix operations'!

determinantByCofactors
    "Answer the determinant of this matrix."

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

!Matrix2_2 class methodsFor:'documentation'!

version_CVS
    ^ '$Header$'
! !