Skip to content

Commit cdd2475

Browse files
committed
Throw/raise an exception if alpha, beta or gamma are not within ]0;pi[ when changing lattice angles.
Also see vincefn/objcryst@a55f20d Fixes #20 (raises an ObjCrystException rather than a ValueError, but this would be difficult to do)
1 parent 33abd2c commit cdd2475

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

src/extensions/unitcell_ext.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,11 @@ double _getc(UnitCell& u)
9696

9797
void _setalpha(UnitCell& u, double val)
9898
{
99-
u.GetPar("alpha").SetValue(val);
99+
if((val<=0)||(val>=M_PI)) throw ObjCrystException("alpha must be within ]0;pi[");
100+
RefinablePar &p = u.GetPar("alpha");
101+
if(p.IsUsed()) p.SetValue(val);
102+
// Throwing an exception here would be risky - a warning would be more adequate
103+
// else throw ObjCrystException("alpha is fixed and cannot be changed");
100104
}
101105

102106
double _getalpha(UnitCell& u)
@@ -106,7 +110,11 @@ double _getalpha(UnitCell& u)
106110

107111
void _setbeta(UnitCell& u, double val)
108112
{
109-
u.GetPar("beta").SetValue(val);
113+
if((val<=0)||(val>=M_PI)) throw ObjCrystException("beta must be within ]0;pi[");
114+
RefinablePar &p = u.GetPar("beta");
115+
if(p.IsUsed()) p.SetValue(val);
116+
// Throwing an exception here would be risky - a warning would be more adequate
117+
// else throw ObjCrystException("beta is fixed and cannot be changed");
110118
}
111119

112120
double _getbeta(UnitCell& u)
@@ -116,7 +124,11 @@ double _getbeta(UnitCell& u)
116124

117125
void _setgamma(UnitCell& u, double val)
118126
{
119-
u.GetPar("gamma").SetValue(val);
127+
if((val<=0)||(val>=M_PI)) throw ObjCrystException("gamma must be within ]0;pi[");
128+
RefinablePar &p = u.GetPar("gamma");
129+
if(p.IsUsed()) p.SetValue(val);
130+
// Throwing an exception here would be risky - a warning would be more adequate
131+
// else throw ObjCrystException("gamma is fixed and cannot be changed");
120132
}
121133

122134
double _getgamma(UnitCell& u)

0 commit comments

Comments
 (0)