forked from chemhack/jchemhub
-
Notifications
You must be signed in to change notification settings - Fork 9
/
aromaticity_renderer.js
67 lines (57 loc) · 2.38 KB
/
aromaticity_renderer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/**
* Copyright 2010 Mark Rijnbeek (markr@ebi.ac.uk)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
goog.provide('kemia.view.AromaticityRenderer');
goog.require('kemia.view.BondRenderer');
/**
* Class to render ring aromaticity to a graphics representation.
*
* @param {goog.graphics.AbstractGraphics} graphics to draw on.
* @param {Object=} opt_config override default configuration
* @constructor
* @extends {kemia.view.BondRenderer}
*/
kemia.view.AromaticityRenderer = function(graphics, opt_config) {
kemia.view.BondRenderer.call(
this,
graphics,
kemia.view.AromaticityRenderer.defaultConfig,
opt_config);
}
goog.inherits(kemia.view.AromaticityRenderer, kemia.view.BondRenderer);
/**
* Renders ring aromaticity in omelet style.
* @param {kemia.ring.Ring}
* ring
* @param {kemia.graphics.AffineTransform}
* transform
* @param {kemia.graphics.ElementArray=} opt_element_array
* @return {kemia.graphics.ElementArray}
*/
kemia.view.AromaticityRenderer.prototype.render = function(ring, transform, bondPath) {
this.setTransform(transform);
var aromaticCircle = new goog.graphics.Path();
var ringCenter = this.transform.transformCoords([ring.getCenter()])[0];
// Radius of the aromatic circle proportional to the ring size
var circleRadiusProportion = 0.5;
//Assumption: ring is symmetrical, so pick any one of the ring atom coords
var anyAtomCoord = this.transform.transformCoords([ring.atoms[0].coord])[0];
var spokeSize = goog.math.Coordinate.distance(ringCenter, anyAtomCoord)
var omeletRadius = spokeSize * circleRadiusProportion;
aromaticCircle.moveTo(ringCenter.x + (omeletRadius), ringCenter.y);
aromaticCircle.arcTo(omeletRadius, omeletRadius, 0, 180);
aromaticCircle.moveTo(ringCenter.x + (omeletRadius), ringCenter.y);
aromaticCircle.arcTo(omeletRadius, omeletRadius, 0, -180);
}