Skip to content

Commit 8d34587

Browse files
committed
Fix typo
1 parent 9b5c276 commit 8d34587

File tree

1 file changed

+88
-126
lines changed

1 file changed

+88
-126
lines changed

src/js/molpad/MPBond_calc.js

Lines changed: 88 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,18 @@
1616
* along with MolView. If not, see <http://www.gnu.org/licenses/>.
1717
*/
1818

19-
MPBond.prototype.validate = function()
20-
{
21-
if(this.valid) return;
19+
MPBond.prototype.validate = function () {
20+
if (this.valid) return;
2221
this.valid = true;
2322

24-
if(this.mp.mol.atoms[this.from].center.distanceTo(
25-
this.mp.mol.atoms[this.to].center) <=
26-
((this.mp.mol.atoms[this.from].isVisible() ? 1 : 0) +
23+
if (this.mp.mol.atoms[this.from].center.distanceTo(
24+
this.mp.mol.atoms[this.to].center) <=
25+
((this.mp.mol.atoms[this.from].isVisible() ? 1 : 0) +
2726
(this.mp.mol.atoms[this.to].isVisible() ? 1 : 0)) *
28-
this.mp.s.atom.radius)
29-
{
27+
this.mp.s.atom.radius) {
3028
this.hidden = true;
3129
}
32-
else
33-
{
30+
else {
3431
this.hidden = false;
3532

3633
var scale = this.mp.s.bond.scale;
@@ -45,21 +42,17 @@ MPBond.prototype.validate = function()
4542
y: (this.line.from.y + this.line.to.y) / 2
4643
});
4744

48-
if(this.mp.s.bond.colored)
49-
{
45+
if (this.mp.s.bond.colored) {
5046
var f = this.mp.mol.atoms[this.from];
5147
var t = this.mp.mol.atoms[this.to];
5248

53-
if(this.stereo === MP_STEREO_UP)
54-
{
49+
if (this.stereo === MP_STEREO_UP) {
5550
this.cache.bondColor = JmolAtomColorsHashHex["C"];
5651
}
57-
else if(f.element === t.element)
58-
{
52+
else if (f.element === t.element) {
5953
this.cache.bondColor = JmolAtomColorsHashHex[f.element] || JmolAtomColorsHashHex["C"];
6054
}
61-
else
62-
{
55+
else {
6356
this.cache.bondColor = this.mp.ctx.createLinearGradient(f.getX(), f.getY(), t.getX(), t.getY());
6457
this.cache.bondColor.addColorStop(this.mp.s.bond.gradient.from, JmolAtomColorsHashHex[f.element] || JmolAtomColorsHashHex["C"]);
6558
this.cache.bondColor.addColorStop(this.mp.s.bond.gradient.to, JmolAtomColorsHashHex[t.element] || JmolAtomColorsHashHex["C"]);
@@ -70,65 +63,57 @@ MPBond.prototype.validate = function()
7063
this.cache.bondColor = this.mp.s.bond.color;
7164
}
7265

73-
if(this.mp.getScale() >= this.mp.s.bond.singleOnlyScale)
74-
{
75-
if(this.stereo === MP_STEREO_CIS_TRANS && this.type === MP_BOND_DOUBLE)
76-
{
66+
if (this.mp.getScale() >= this.mp.s.bond.singleOnlyScale) {
67+
if (this.stereo === MP_STEREO_CIS_TRANS && this.type === MP_BOND_DOUBLE) {
7768
var ends = transformArrayMult(this.mp.s.bond.delta[MP_BOND_CIS],
78-
-this.mp.s.bond.deltaScale);//flip ends because of flipped y-axis
69+
-this.mp.s.bond.deltaScale);//flip ends because of flipped y-axis
7970
this.cache.ctd = {
8071
from: this.mp.mol.atoms[this.from].calculateBondVertices(this.to, ends),
8172
to: this.mp.mol.atoms[this.to].calculateBondVertices(this.from, ends)
8273
};
8374
}
84-
else if(this.stereo === MP_STEREO_UP)//wedge bond
75+
else if (this.stereo === MP_STEREO_UP)//wedge bond
8576
{
8677
this.cache.wedge = {
8778
far: this.mp.mol.atoms[this.from].calculateBondVertices(this.to, [0]),
8879
near: this.mp.mol.atoms[this.to].calculateBondVertices(this.from,
89-
transformArrayMult(this.mp.s.bond.delta[MP_BOND_WEDGEHASH],
90-
-this.mp.s.bond.deltaScale))//flip ends because of flipped y-axis
80+
transformArrayMult(this.mp.s.bond.delta[MP_BOND_WEDGEHASH],
81+
-this.mp.s.bond.deltaScale))//flip ends because of flipped y-axis
9182
};
9283

93-
if(!this.mp.mol.atoms[this.to].isVisible())
94-
{
84+
if (!this.mp.mol.atoms[this.to].isVisible()) {
9585
var bonds = this.mp.mol.atoms[this.to].calculateClosestBonds(this.index);
9686

97-
if(!bonds.none)
98-
{
99-
if(this.mp.mol.bonds[bonds.lower].type == MP_BOND_SINGLE)
100-
{
87+
if (!bonds.none) {
88+
if (this.mp.mol.bonds[bonds.lower].type == MP_BOND_SINGLE) {
10189
var i1 = this.mp.mol.bonds[bonds.lower].getLine().intersection(
10290
new MPLine({
10391
from: this.cache.wedge.far[0],
10492
to: this.cache.wedge.near[0]
105-
}));
106-
if(i1.p !== undefined && this.line.to.distanceTo(i1.p) < this.mp.s.bond.wedgeFitMaxD)
107-
{
93+
}));
94+
if (i1.p !== undefined && this.line.to.distanceTo(i1.p) < this.mp.s.bond.wedgeFitMaxD) {
10895
this.cache.wedge.near[0] = i1.p || this.cache.wedge.near[0];
10996
}
11097
}
111-
if(this.mp.mol.bonds[bonds.upper].type == MP_BOND_SINGLE)
112-
{
98+
if (this.mp.mol.bonds[bonds.upper].type == MP_BOND_SINGLE) {
11399
var i2 = this.mp.mol.bonds[bonds.upper].getLine().intersection(
114100
new MPLine({
115101
from: this.cache.wedge.far[0],
116102
to: this.cache.wedge.near[1]
117-
}));
118-
if(i2.p !== undefined && this.line.to.distanceTo(i2.p) < this.mp.s.bond.wedgeFitMaxD)
119-
{
103+
}));
104+
if (i2.p !== undefined && this.line.to.distanceTo(i2.p) < this.mp.s.bond.wedgeFitMaxD) {
120105
this.cache.wedge.near[1] = i2.p || this.cache.wedge.near[1];
121106
}
122107
}
123108
}
124109
}
125110
}
126-
else if(this.stereo === MP_STEREO_DOWN)//hash bond
111+
else if (this.stereo === MP_STEREO_DOWN)//hash bond
127112
{
128113
var far = this.mp.mol.atoms[this.from].calculateBondVertices(this.to, [0]);
129114
var near = this.mp.mol.atoms[this.to].calculateBondVertices(this.from,
130-
transformArrayMult(this.mp.s.bond.delta[MP_BOND_WEDGEHASH],
131-
-this.mp.s.bond.deltaScale));//flip ends because of flipped y-axis
115+
transformArrayMult(this.mp.s.bond.delta[MP_BOND_WEDGEHASH],
116+
-this.mp.s.bond.deltaScale));//flip ends because of flipped y-axis
132117

133118
var dx1 = near[0].x - far[0].x;
134119
var dy1 = near[0].y - far[0].y;
@@ -139,8 +124,7 @@ MPBond.prototype.validate = function()
139124
var s = this.mp.s.bond.hashLineSpace * scale;
140125

141126
this.cache.hashLines = [];
142-
while(d1 - s - w > 0)
143-
{
127+
while (d1 - s - w > 0) {
144128
var mult = (d1 - s - w) / d1;
145129
d1 *= mult;
146130
dx1 *= mult; dy1 *= mult;
@@ -152,8 +136,7 @@ MPBond.prototype.validate = function()
152136
});
153137
}
154138
}
155-
else if(this.type === MP_BOND_DOUBLE || this.type === MP_BOND_TRIPLE)
156-
{
139+
else if (this.type === MP_BOND_DOUBLE || this.type === MP_BOND_TRIPLE) {
157140
var ends = [];
158141
var doubleSide = 1;
159142
var fromBonds = this.mp.mol.atoms[this.from].calculateClosestBonds(this.index);
@@ -163,19 +146,18 @@ MPBond.prototype.validate = function()
163146

164147
//check if this bond will be displayed using all skeletal display rules
165148
var skeletal = (this.mp.s.skeletalDisplay &&//skeleton display is enabled
166-
(!this.mp.mol.atoms[this.from].isVisible() || !this.mp.mol.atoms[this.to].isVisible()) &&//and at least one atom is visible
167-
//and the bond is not a bond which connects:
168-
!(this.mp.mol.atoms[this.from].bonds.length === 1 &&//an atom with no other bonds
169-
((this.mp.mol.atoms[this.from].isVisible() &&//which is visible
149+
(!this.mp.mol.atoms[this.from].isVisible() || !this.mp.mol.atoms[this.to].isVisible()) &&//and at least one atom is visible
150+
//and the bond is not a bond which connects:
151+
!(this.mp.mol.atoms[this.from].bonds.length === 1 &&//an atom with no other bonds
152+
((this.mp.mol.atoms[this.from].isVisible() &&//which is visible
170153
this.mp.mol.atoms[this.to].bonds.length > 2) ||//to any atom that is connected to 2+ other atoms
171154
this.mp.mol.atoms[this.to].bonds.length === 1)) &&//or to another atom with no other bonds
172-
!(this.mp.mol.atoms[this.to].bonds.length === 1 &&
173-
((this.mp.mol.atoms[this.to].isVisible() &&
155+
!(this.mp.mol.atoms[this.to].bonds.length === 1 &&
156+
((this.mp.mol.atoms[this.to].isVisible() &&
174157
this.mp.mol.atoms[this.from].bonds.length > 2) ||//to any atom that is connected to 2+ other atoms
175158
this.mp.mol.atoms[this.from].bonds.length === 1)));
176159

177-
if(skeletal)
178-
{
160+
if (skeletal) {
179161
/*
180162
Calculate best doubleSide
181163
=========================
@@ -191,34 +173,30 @@ MPBond.prototype.validate = function()
191173
var length = this.line.from.distanceTo(this.line.to);
192174
var upperLength = length, upperBisectD = 0;
193175

194-
if(fromBonds.upperSectionAngle < Math.PI)
195-
{
196-
if(!this.mp.mol.atoms[this.from].isVisible())
176+
if (fromBonds.upperSectionAngle < Math.PI) {
177+
if (!this.mp.mol.atoms[this.from].isVisible())
197178
upperLength -= 8 / Math.tan(fromBonds.upperSectionAngle / 2);
198179
upperBisectD += Math.abs(this.mp.s.bond.bestBisect - fromBonds.upperSectionAngle / 2);
199180
}
200181
else upperBisectD += Math.abs(this.mp.s.bond.bestBisect - Math.PI / 2);
201182

202-
if(toBonds.lowerSectionAngle < Math.PI)
203-
{
204-
if(!this.mp.mol.atoms[this.to].isVisible())
183+
if (toBonds.lowerSectionAngle < Math.PI) {
184+
if (!this.mp.mol.atoms[this.to].isVisible())
205185
upperLength -= 8 / Math.tan(toBonds.lowerSectionAngle / 2);
206186
upperBisectD += Math.abs(this.mp.s.bond.bestBisect - toBonds.lowerSectionAngle / 2);
207187
}
208188
else upperBisectD += Math.abs(this.mp.s.bond.bestBisect - Math.PI / 2);
209189

210190
var lowerLength = length, lowerBisectD = 0;
211-
if(fromBonds.lowerSectionAngle < Math.PI)
212-
{
213-
if(!this.mp.mol.atoms[this.from].isVisible())
191+
if (fromBonds.lowerSectionAngle < Math.PI) {
192+
if (!this.mp.mol.atoms[this.from].isVisible())
214193
lowerLength -= 8 / Math.tan(fromBonds.lowerSectionAngle / 2);
215194
lowerBisectD += Math.abs(this.mp.s.bond.bestBisect - fromBonds.lowerSectionAngle / 2);
216195
}
217196
else lowerBisectD += Math.abs(this.mp.s.bond.bestBisect - Math.PI / 2);
218197

219-
if(toBonds.upperSectionAngle < Math.PI)
220-
{
221-
if(!this.mp.mol.atoms[this.to].isVisible())
198+
if (toBonds.upperSectionAngle < Math.PI) {
199+
if (!this.mp.mol.atoms[this.to].isVisible())
222200
lowerLength -= 8 / Math.tan(toBonds.upperSectionAngle / 2);
223201
lowerBisectD += Math.abs(this.mp.s.bond.bestBisect - toBonds.upperSectionAngle / 2);
224202
}
@@ -227,34 +205,30 @@ MPBond.prototype.validate = function()
227205
//check if the opposite sections are almost the same (like in a chain)
228206
//if so, a fallback rule is applied (in order to prevent from
229207
//inconsistent double bond sides in carbon chains)
230-
if(Math.abs(fromBonds.upperSectionAngle - toBonds.upperSectionAngle) +
231-
Math.abs(fromBonds.lowerSectionAngle - toBonds.lowerSectionAngle) < this.mp.s.bond.angleDev)
232-
{
208+
if (Math.abs(fromBonds.upperSectionAngle - toBonds.upperSectionAngle) +
209+
Math.abs(fromBonds.lowerSectionAngle - toBonds.lowerSectionAngle) < this.mp.s.bond.angleDev) {
233210
//fallback rule: double bond to the visual upper side
234211
var a = this.mp.mol.atoms[this.from].center.angleTo(this.mp.mol.atoms[this.to].center);
235212
doubleSide = a > -Math.PI / 2 + this.mp.s.bond.angleDev
236-
&& a <= Math.PI / 2 + this.mp.s.bond.angleDev ? 1 : -1;
213+
&& a <= Math.PI / 2 + this.mp.s.bond.angleDev ? 1 : -1;
237214
}
238-
else if(lowerBisectD < upperBisectD ||//the lower side has a smaller bestBisect deviation
215+
else if (lowerBisectD < upperBisectD ||//the lower side has a smaller bestBisect deviation
239216
//or the lower side can apply bond refinement while the upper side cannot
240-
(upperLength < this.mp.s.atom.radius && lowerLength > this.mp.s.atom.radius))
241-
{
217+
(upperLength < this.mp.s.atom.radius && lowerLength > this.mp.s.atom.radius)) {
242218
doubleSide = -1;
243219
}
244220

245221
refineUpperSkeletal = (this.type === MP_BOND_TRIPLE || doubleSide === 1)
246-
&& upperLength > this.mp.s.atom.radius;
222+
&& upperLength > this.mp.s.atom.radius;
247223
refineLowerSkeletal = (this.type === MP_BOND_TRIPLE || doubleSide === -1)
248-
&& lowerLength > this.mp.s.atom.radius;
224+
&& lowerLength > this.mp.s.atom.radius;
249225
}
250226

251-
if(this.type === MP_BOND_DOUBLE)
252-
{
227+
if (this.type === MP_BOND_DOUBLE) {
253228
ends = this.mp.s.bond.delta[MP_BOND_DOUBLE];
254-
if(skeletal) ends = transformArrayAdd(ends, -doubleSide * ends[0]);
229+
if (skeletal) ends = transformArrayAdd(ends, -doubleSide * ends[0]);
255230
}
256-
else if(this.type === MP_BOND_TRIPLE)
257-
{
231+
else if (this.type === MP_BOND_TRIPLE) {
258232
ends = this.mp.s.bond.delta[MP_BOND_TRIPLE];
259233
}
260234

@@ -265,46 +239,38 @@ MPBond.prototype.validate = function()
265239
to: this.mp.mol.atoms[this.to].calculateBondVertices(this.from, toEnds)
266240
};
267241

268-
if(!this.mp.mol.atoms[this.from].isVisible())
269-
{
270-
if(!fromBonds.none)
271-
{
272-
if((!skeletal || refineLowerSkeletal)
273-
&& fromBonds.lowerSectionAngle < Math.PI)
274-
{
275-
this.cache.bond.from[0] = this.refineBondVetex(
276-
skeletal, fromBonds.lowerBisectAngle,
277-
this.line.from, this.cache.bond.from[0], this.cache.bond.to[0],
278-
this.mp.mol.bonds[fromBonds.lower].getLine());
242+
if (!this.mp.mol.atoms[this.from].isVisible()) {
243+
if (!fromBonds.none) {
244+
if ((!skeletal || refineLowerSkeletal)
245+
&& fromBonds.lowerSectionAngle < Math.PI) {
246+
this.cache.bond.from[0] = this.refineBondVertex(
247+
skeletal, fromBonds.lowerBisectAngle,
248+
this.line.from, this.cache.bond.from[0], this.cache.bond.to[0],
249+
this.mp.mol.bonds[fromBonds.lower].getLine());
279250
}
280-
if((!skeletal || refineUpperSkeletal)
281-
&& fromBonds.upperSectionAngle < Math.PI)
282-
{
283-
this.cache.bond.from[1] = this.refineBondVetex(
284-
skeletal, fromBonds.upperBisectAngle,
285-
this.line.from, this.cache.bond.from[1], this.cache.bond.to[1],
286-
this.mp.mol.bonds[fromBonds.upper].getLine());
251+
if ((!skeletal || refineUpperSkeletal)
252+
&& fromBonds.upperSectionAngle < Math.PI) {
253+
this.cache.bond.from[1] = this.refineBondVertex(
254+
skeletal, fromBonds.upperBisectAngle,
255+
this.line.from, this.cache.bond.from[1], this.cache.bond.to[1],
256+
this.mp.mol.bonds[fromBonds.upper].getLine());
287257
}
288258
}
289259
}
290260

291-
if(!this.mp.mol.atoms[this.to].isVisible())
292-
{
293-
if(!toBonds.none)
294-
{
295-
if((!skeletal || refineLowerSkeletal)
296-
&& toBonds.upperSectionAngle < Math.PI)
297-
{
298-
this.cache.bond.to[0] = this.refineBondVetex(skeletal, toBonds.upperBisectAngle,
299-
this.line.to, this.cache.bond.to[0], this.cache.bond.from[0],
300-
this.mp.mol.bonds[toBonds.upper].getLine());
261+
if (!this.mp.mol.atoms[this.to].isVisible()) {
262+
if (!toBonds.none) {
263+
if ((!skeletal || refineLowerSkeletal)
264+
&& toBonds.upperSectionAngle < Math.PI) {
265+
this.cache.bond.to[0] = this.refineBondVertex(skeletal, toBonds.upperBisectAngle,
266+
this.line.to, this.cache.bond.to[0], this.cache.bond.from[0],
267+
this.mp.mol.bonds[toBonds.upper].getLine());
301268
}
302-
if((!skeletal || refineUpperSkeletal)
303-
&& toBonds.lowerSectionAngle < Math.PI)
304-
{
305-
this.cache.bond.to[1] = this.refineBondVetex(skeletal, toBonds.lowerBisectAngle,
306-
this.line.to, this.cache.bond.to[1], this.cache.bond.from[1],
307-
this.mp.mol.bonds[toBonds.lower].getLine());
269+
if ((!skeletal || refineUpperSkeletal)
270+
&& toBonds.lowerSectionAngle < Math.PI) {
271+
this.cache.bond.to[1] = this.refineBondVertex(skeletal, toBonds.lowerBisectAngle,
272+
this.line.to, this.cache.bond.to[1], this.cache.bond.from[1],
273+
this.mp.mol.bonds[toBonds.lower].getLine());
308274
}
309275
}
310276
}
@@ -314,11 +280,9 @@ MPBond.prototype.validate = function()
314280
}
315281

316282

317-
MPBond.prototype.refineBondVetex = function(skeletal, bisectAngle, lineFrom, bondFrom, bondTo, closestBondLine)
318-
{
283+
MPBond.prototype.refineBondVertex = function (skeletal, bisectAngle, lineFrom, bondFrom, bondTo, closestBondLine) {
319284
var intersection;
320-
if(skeletal)
321-
{
285+
if (skeletal) {
322286
intersection = new MPLine({
323287
from: lineFrom,
324288
to: MPPFO({
@@ -329,18 +293,16 @@ MPBond.prototype.refineBondVetex = function(skeletal, bisectAngle, lineFrom, bon
329293
new MPLine({
330294
from: bondFrom,
331295
to: bondTo
332-
}));
296+
}));
333297
}
334-
else
335-
{
298+
else {
336299
intersection = closestBondLine.intersection(
337300
new MPLine({
338301
from: bondFrom,
339302
to: bondTo
340-
}));
341-
if(!intersection.onL1 || lineFrom.distanceTo(intersection.p) >
342-
closestBondLine.length() / 2)
343-
{
303+
}));
304+
if (!intersection.onL1 || lineFrom.distanceTo(intersection.p) >
305+
closestBondLine.length() / 2) {
344306
intersection.p = undefined;
345307
}
346308
}

0 commit comments

Comments
 (0)