ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/util/rmatrix.c
(Generate patch)

Comparing ray/src/util/rmatrix.c (file contents):
Revision 2.68 by greg, Sat Dec 2 16:28:35 2023 UTC vs.
Revision 2.69 by greg, Mon Dec 4 22:02:40 2023 UTC

# Line 31 | Line 31 | rmx_new(int nr, int nc, int n)
31                  return(NULL);
32  
33          dnew = (RMATRIX *)calloc(1, sizeof(RMATRIX));
34 <        if (dnew) {
35 <                dnew->dtype = DTdouble;
36 <                dnew->nrows = nr;
37 <                dnew->ncols = nc;
38 <                dnew->ncomp = n;
39 <                setcolor(dnew->cexp, 1.f, 1.f, 1.f);
40 <                memcpy(dnew->wlpart, WLPART, sizeof(dnew->wlpart));
41 <        }
34 >        if (!dnew)
35 >                return(NULL);
36 >
37 >        dnew->dtype = DTdouble;
38 >        dnew->nrows = nr;
39 >        dnew->ncols = nc;
40 >        dnew->ncomp = n;
41 >        setcolor(dnew->cexp, 1.f, 1.f, 1.f);
42 >        memcpy(dnew->wlpart, WLPART, sizeof(dnew->wlpart));
43 >
44          return(dnew);
45   }
46  
# Line 640 | Line 642 | rmx_identity(const int dim, const int n)
642          return(rid);
643   }
644  
645 < /* Duplicate the given matrix */
645 > /* Duplicate the given matrix (may be unallocated) */
646   RMATRIX *
647   rmx_copy(const RMATRIX *rm)
648   {
649          RMATRIX *dnew;
650  
651 <        if (!rm || !rm->mtx)
651 >        if (!rm)
652                  return(NULL);
653 <        dnew = rmx_alloc(rm->nrows, rm->ncols, rm->ncomp);
653 >        dnew = rmx_new(rm->nrows, rm->ncols, rm->ncomp);
654          if (!dnew)
655                  return(NULL);
656 +        if (rm->mtx) {
657 +                if (!rmx_prepare(dnew)) {
658 +                        rmx_free(dnew);
659 +                        return(NULL);
660 +                }
661 +                memcpy(dnew->mtx, rm->mtx, array_size(dnew));
662 +        }
663          rmx_addinfo(dnew, rm->info);
664          dnew->dtype = rm->dtype;
665          copycolor(dnew->cexp, rm->cexp);
666          memcpy(dnew->wlpart, rm->wlpart, sizeof(dnew->wlpart));
658        memcpy(dnew->mtx, rm->mtx, array_size(dnew));
667          return(dnew);
668   }
669  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines