예제 #1
0
        /// <summary>
        /// Returns the optimal placement for the double bond
        /// </summary>
        /// <returns>BondDirection value indicating how the bond should be placed.</returns>
        private BondDirection?GetPlacement()
        {
            BondDirection dir = BondDirection.None;

            var vec = GetPrettyDoubleBondVector();

            if (vec == null)
            {
                dir = BondDirection.None;
            }
            else
            {
                // Azure DevOps #713
                if (double.IsNaN(vec.Value.X) || double.IsNaN(vec.Value.Y))
                {
                    dir = BondDirection.None;
                }
                else
                {
                    dir = (BondDirection)Math.Sign(Vector.CrossProduct(vec.Value, BondVector));
                }
            }

            return(dir);
        }
예제 #2
0
        private IRenderingElement GenerateStereoElement(IBond bond, RendererModel model)
        {
            BondStereo stereo = bond.Stereo;

            WedgeLineElement.WedgeType type = WedgeLineElement.WedgeType.Wedged;
            BondDirection dir = BondDirection.ToSecond;

            switch (stereo)
            {
            case BondStereo.Down:
            case BondStereo.DownInverted:
                type = WedgeLineElement.WedgeType.Dashed;
                break;

            case BondStereo.UpOrDown:
            case BondStereo.UpOrDownInverted:
                type = WedgeLineElement.WedgeType.Indiff;
                break;
            }
            switch (stereo)
            {
            case BondStereo.DownInverted:
            case BondStereo.UpInverted:
            case BondStereo.UpOrDownInverted:
                dir = BondDirection.ToFirst;
                break;
            }

            IRenderingElement base_ = GenerateBondElement(bond, BondOrder.Single, model);

            return(new WedgeLineElement((LineElement)base_, type, dir, GetColorForBond(bond, model)));
        }
예제 #3
0
        /// <summary>
        /// draws the two parallel lines of a double bond
        /// These bonds can either straddle the atom-atom line or fall to one or other side of it
        /// </summary>
        /// <param name="startPoint"></param>
        /// <param name="endPoint"></param>
        /// <param name="doubleBondPlacement"></param>
        /// <param name="ringCentroid"></param>
        /// <param name="enclosingPoly"></param>
        /// <returns></returns>
        public static System.Windows.Media.Geometry DoubleBondGeometry(Point startPoint, Point endPoint,
                                                                       BondDirection doubleBondPlacement, ref List <Point> enclosingPoly, Point?ringCentroid = null)

        {
            Point point1;
            Point point2;
            Point point3;
            Point point4;

            enclosingPoly = GetDoubleBondPoints(startPoint, endPoint, doubleBondPlacement, ringCentroid, out point1, out point2, out point3, out point4);

            ;

            StreamGeometry sg = new StreamGeometry();

            using (StreamGeometryContext sgc = sg.Open())
            {
                sgc.BeginFigure(point1, false, false);
                sgc.LineTo(point2, true, false);
                sgc.BeginFigure(point3, false, false);
                sgc.LineTo(point4, true, false);
                sgc.Close();
            }
            sg.Freeze();
            return(sg);
        }
예제 #4
0
파일: Bond.cs 프로젝트: alan008/Version3
        /// <summary>
        /// Returns the optimal placement for the double bond
        /// </summary>
        /// <returns>BondDirection value indicating how the bond should be placed.</returns>
        private BondDirection?GetPlacement()
        {
            BondDirection dir = BondDirection.None;

            var vec = GetPrettyDoubleBondVector();

            if (vec == null)
            {
                dir = BondDirection.None;
            }
            else
            {
                dir = (BondDirection)Math.Sign(Vector.CrossProduct(vec.Value, BondVector));
            }

            return(dir);
        }
예제 #5
0
 public PotentialBond(Vector2i coords, BondDirection direction)
 {
     // this is not the real constructor body, it's only here to make the compiler happy
     this.coords = new Vector2i();
 }
예제 #6
0
        /// <summary>
        /// Defines the 4 points that characterise a double bond and returns a list of them in polygon order
        /// </summary>
        /// <param name="startPoint"></param>
        /// <param name="endPoint"></param>
        /// <param name="doubleBondPlacement"></param>
        /// <param name="ringCentroid"></param>
        /// <param name="point1"></param>
        /// <param name="point2"></param>
        /// <param name="point3"></param>
        /// <param name="point4"></param>
        /// <returns></returns>
        public static List <Point> GetDoubleBondPoints(Point startPoint, Point endPoint, BondDirection doubleBondPlacement,
                                                       Point?ringCentroid, out Point point1, out Point point2, out Point point3, out Point point4)
        {
            List <Point> enclosingPoly;
            Vector       v      = endPoint - startPoint;
            Vector       normal = v.Perpendicular();

            normal.Normalize();

            Point?point3a, point4a;

            double distance = Globals.Offset;

            if (ringCentroid == null)
            {
                switch (doubleBondPlacement)
                {
                case BondDirection.None:

                    point1 = startPoint + normal * distance;
                    point2 = point1 + v;

                    point3 = startPoint - normal * distance;
                    point4 = point3 + v;

                    break;

                case BondDirection.Clockwise:
                {
                    point1 = startPoint;

                    point2 = endPoint;
                    point3 = startPoint - normal * 2 * distance;
                    point4 = point3 + v;

                    break;
                }

                case BondDirection.Anticlockwise:
                    point1 = startPoint;
                    point2 = endPoint;
                    point3 = startPoint + normal * 2 * distance;
                    point4 = point3 + v;
                    break;

                default:

                    point1 = startPoint + normal * distance;
                    point2 = point1 + v;

                    point3 = startPoint - normal * distance;
                    point4 = point3 + v;
                    break;
                }
            }
            else
            {
                point1 = startPoint;
                point2 = endPoint;

                var bondvector    = endPoint - startPoint;
                var centreVector  = ringCentroid - startPoint;
                var bondPlacement = (BondDirection)Math.Sign(Vector.CrossProduct(centreVector.Value, bondvector));
                if (bondPlacement == BondDirection.Clockwise)
                {
                    point3 = startPoint - normal * 2 * distance;
                    point4 = point3 + v;
                }
                else
                {
                    point3 = startPoint + normal * 2 * distance;
                    point4 = point3 + v;
                }

                point3a = BasicGeometry.LineSegmentsIntersect(startPoint, ringCentroid.Value, point3, point4);

                var tempPoint3 = point3a ?? point3;

                point4a = BasicGeometry.LineSegmentsIntersect(endPoint, ringCentroid.Value, point3, point4);

                var tempPoint4 = point4 = point4a ?? point4;

                point3 = tempPoint3;
                point4 = tempPoint4;
            }
            //capture  the enclosing polygon for hit testing later

            enclosingPoly = new List <Point>()
            {
                point1, point2, point4, point3
            };

            //shorten the supporting bond if it's a ring bond
            if (ringCentroid != null)
            {
            }
            return(enclosingPoly);
        }
예제 #7
0
 /// <summary>
 /// Make a wedge along the given line element.
 /// </summary>
 /// <param name="element">the line element to use as the basic geometry</param>
 /// <param name="type">if the bond is dashed ,wedged, or "up_or_down", i.e., not defined</param>
 /// <param name="direction">the direction of the thickness</param>
 /// <param name="color">the color of the wedge</param>
 public WedgeLineElement(LineElement element, WedgeType type, BondDirection direction, Color color)
     : this(direction == BondDirection.ToFirst ? element.SecondPoint : element.FirstPoint,
            direction == BondDirection.ToFirst ? element.FirstPoint : element.SecondPoint,
            element.Width, type, direction, color)
 {
 }
예제 #8
0
 /// <summary>
 /// Make a wedge between the points (x1, y1) and (x2, y2) with a certain
 /// width, direction, dash, and color.
 /// </summary>
 /// <param name="firstPoint">the coordinate of the first point</param>
 /// <param name="secondPoint">the coordinate of the second point</param>
 /// <param name="width">the width of the wedge</param>
 /// <param name="type">the bond is dashed ,wedged, or "up_or_down", i.e., not defined.</param>
 /// <param name="direction">the direction of the thickness</param>
 /// <param name="color">the color of the wedge</param>
 public WedgeLineElement(Point firstPoint, Point secondPoint, double width, WedgeType type, BondDirection direction, Color color)
     : base(firstPoint, secondPoint, width, color)
 {
     this.BondType  = type;
     this.Direction = direction;
 }