TwoDimensionalMatrix.st
author Claus Gittinger <cg@exept.de>
Sat, 02 May 2020 21:40:13 +0200
changeset 5476 7355a4b11cb6
parent 5382 eda4b952a1e7
permissions -rw-r--r--
#FEATURE by cg class: Socket class added: #newTCPclientToHost:port:domain:domainOrder:withTimeout: changed: #newTCPclientToHost:port:domain:withTimeout:
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5122
03e353060f85 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5085
diff changeset
     1
"{ Encoding: utf8 }"
03e353060f85 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5085
diff changeset
     2
5382
eda4b952a1e7 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5188
diff changeset
     3
"
eda4b952a1e7 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5188
diff changeset
     4
 COPYRIGHT (c) 2018 by eXept Software AG
eda4b952a1e7 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5188
diff changeset
     5
              All Rights Reserved
eda4b952a1e7 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5188
diff changeset
     6
eda4b952a1e7 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5188
diff changeset
     7
 This software is furnished under a license and may be used
eda4b952a1e7 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5188
diff changeset
     8
 only in accordance with the terms of that license and with the
eda4b952a1e7 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5188
diff changeset
     9
 inclusion of the above copyright notice.   This software may not
eda4b952a1e7 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5188
diff changeset
    10
 be provided or otherwise made available to, or used by, any
eda4b952a1e7 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5188
diff changeset
    11
 other person.  No title to or ownership of the software is
eda4b952a1e7 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5188
diff changeset
    12
 hereby transferred.
eda4b952a1e7 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5188
diff changeset
    13
"
5085
5154d9584859 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    14
"{ Package: 'stx:libbasic2' }"
5154d9584859 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    15
5154d9584859 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    16
"{ NameSpace: Smalltalk }"
5154d9584859 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    17
5154d9584859 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    18
Matrix variableSubclass:#TwoDimensionalMatrix
5154d9584859 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    19
	instanceVariableNames:''
5154d9584859 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    20
	classVariableNames:''
5154d9584859 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    21
	poolDictionaries:''
5154d9584859 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    22
	category:'Collections-MultiDimensional'
5154d9584859 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    23
!
5154d9584859 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    24
5382
eda4b952a1e7 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5188
diff changeset
    25
!TwoDimensionalMatrix class methodsFor:'documentation'!
eda4b952a1e7 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5188
diff changeset
    26
eda4b952a1e7 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5188
diff changeset
    27
copyright
eda4b952a1e7 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5188
diff changeset
    28
"
eda4b952a1e7 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5188
diff changeset
    29
 COPYRIGHT (c) 2018 by eXept Software AG
eda4b952a1e7 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5188
diff changeset
    30
              All Rights Reserved
eda4b952a1e7 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5188
diff changeset
    31
eda4b952a1e7 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5188
diff changeset
    32
 This software is furnished under a license and may be used
eda4b952a1e7 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5188
diff changeset
    33
 only in accordance with the terms of that license and with the
eda4b952a1e7 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5188
diff changeset
    34
 inclusion of the above copyright notice.   This software may not
eda4b952a1e7 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5188
diff changeset
    35
 be provided or otherwise made available to, or used by, any
eda4b952a1e7 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5188
diff changeset
    36
 other person.  No title to or ownership of the software is
eda4b952a1e7 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5188
diff changeset
    37
 hereby transferred.
eda4b952a1e7 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5188
diff changeset
    38
"
eda4b952a1e7 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5188
diff changeset
    39
! !
5085
5154d9584859 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    40
5154d9584859 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    41
!TwoDimensionalMatrix methodsFor:'accessing'!
5154d9584859 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    42
5154d9584859 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    43
subMatrix: aPoint
5122
03e353060f85 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5085
diff changeset
    44
    |nRows "{Class: SmallInteger }"
03e353060f85 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5085
diff changeset
    45
     nCols "{Class: SmallInteger }"
03e353060f85 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5085
diff changeset
    46
     retval retRow retCol |
5085
5154d9584859 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    47
5122
03e353060f85 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5085
diff changeset
    48
    nRows := self rows.
03e353060f85 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5085
diff changeset
    49
    nCols := self columns.
03e353060f85 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5085
diff changeset
    50
    retval := Matrix newForRows:(nRows-1) cols:(nCols-1).
5085
5154d9584859 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    51
5122
03e353060f85 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5085
diff changeset
    52
    retRow := retCol := 1.
03e353060f85 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5085
diff changeset
    53
03e353060f85 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5085
diff changeset
    54
    1 to:nRows do:[:r |
5085
5154d9584859 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    55
        r ~= aPoint x ifTrue: [
5122
03e353060f85 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5085
diff changeset
    56
            1 to:nCols do:[:c |
5085
5154d9584859 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    57
                c ~= aPoint y ifTrue: [
5154d9584859 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    58
                    retval _at: retRow at: retCol put: (self _at: r at: c).
5154d9584859 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    59
                    retCol := retCol + 1 
5154d9584859 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    60
                ] 
5154d9584859 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    61
            ].
5154d9584859 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    62
            retRow := retRow + 1 
5154d9584859 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    63
        ].
5154d9584859 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    64
        retCol := 1 
5154d9584859 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    65
    ].
5154d9584859 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    66
    ^ retval
5122
03e353060f85 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5085
diff changeset
    67
03e353060f85 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5085
diff changeset
    68
    "
5188
3635c923064b #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5122
diff changeset
    69
     (Matrix3_3 withAll:#(11 12 13 
3635c923064b #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5122
diff changeset
    70
                          21 22 23 
3635c923064b #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5122
diff changeset
    71
                          31 32 33))
3635c923064b #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5122
diff changeset
    72
        subMatrix:(1 @ 1)  
5122
03e353060f85 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5085
diff changeset
    73
    "
5085
5154d9584859 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    74
! !
5154d9584859 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    75
5154d9584859 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    76
!TwoDimensionalMatrix methodsFor:'matrix operations'!
5154d9584859 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    77
5154d9584859 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    78
minor: aPoint
5154d9584859 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    79
    ^ (self subMatrix: aPoint) determinantByCofactors
5154d9584859 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    80
! !
5154d9584859 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    81
5154d9584859 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    82
!TwoDimensionalMatrix methodsFor:'queries'!
5154d9584859 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    83
5154d9584859 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    84
cofactor:aPoint
5154d9584859 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    85
    (aPoint x + aPoint y) odd
5154d9584859 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    86
            ifTrue: [ ^ -1 * (self minor: aPoint) ]
5154d9584859 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    87
            ifFalse: [ ^ self minor: aPoint ]
5154d9584859 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    88
! !
5154d9584859 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    89
5154d9584859 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    90
!TwoDimensionalMatrix class methodsFor:'documentation'!
5154d9584859 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    91
5154d9584859 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    92
version_CVS
5154d9584859 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    93
    ^ '$Header$'
5154d9584859 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    94
! !
5154d9584859 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    95