Skip to content

Commit cbfa704

Browse files
committed
more point operations
1 parent 7dc2645 commit cbfa704

File tree

2 files changed

+28
-47
lines changed

2 files changed

+28
-47
lines changed

Code/GraphMol/MolDraw2D/MolDraw2D.cpp

Lines changed: 26 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -578,15 +578,9 @@ namespace RDKit {
578578
// to the atom-atom line.
579579
if( ( bond->getBondType() == Bond::DOUBLE ) &&
580580
( 1 == at1->getDegree() || 1 == at2->getDegree() ) ) {
581-
Point2D perp = calcPerpendicular( at1_cds , at2_cds );
582-
drawLine( Point2D( at1_cds.x + double_bond_offset * perp.x ,
583-
at1_cds.y + double_bond_offset * perp.y ) ,
584-
Point2D( at2_cds.x + double_bond_offset * perp.x ,
585-
at2_cds.y + double_bond_offset * perp.y ) , col1 , col2 );
586-
drawLine( Point2D( at1_cds.x - double_bond_offset * perp.x ,
587-
at1_cds.y - double_bond_offset * perp.y ) ,
588-
Point2D( at2_cds.x - double_bond_offset * perp.x ,
589-
at2_cds.y - double_bond_offset * perp.y ) , col1 , col2 );
581+
Point2D perp = calcPerpendicular( at1_cds , at2_cds ) * double_bond_offset ;
582+
drawLine(at1_cds + perp, at2_cds + perp, col1,col2);
583+
drawLine(at1_cds - perp, at2_cds - perp, col1,col2);
590584
if( bond->getBondType() == Bond::TRIPLE ) {
591585
drawLine( at1_cds , at2_cds , col1 , col2 );
592586
}
@@ -608,21 +602,17 @@ namespace RDKit {
608602
drawLine( at1_cds , at2_cds , col1 , col2 );
609603
if( Bond::TRIPLE == bond->getBondType() ) {
610604
// 2 further lines, a bit shorter and offset on the perpendicular
611-
Point2D perp = calcPerpendicular( at1_cds , at2_cds );
612605
double dbo = 2.0 * double_bond_offset;
606+
Point2D perp = calcPerpendicular( at1_cds , at2_cds );
613607
double end1_trunc = 1 == at1->getDegree() ? 0.0 : 0.1;
614608
double end2_trunc = 1 == at2->getDegree() ? 0.0 : 0.1;
615-
double bv[2] = { at1_cds.x - at2_cds.x , at1_cds.y - at2_cds.y };
616-
double px1 = at1_cds.x - end1_trunc * bv[0] + dbo * perp.x;
617-
double py1 = at1_cds.y - end1_trunc * bv[1] + dbo * perp.y;
618-
double px2 = at2_cds.x + end2_trunc * bv[0] + dbo * perp.x;
619-
double py2 = at2_cds.y + end2_trunc * bv[1] + dbo * perp.y;
620-
drawLine( Point2D( px1 , py1 ) , Point2D( px2 , py2 ) , col1 , col2 );
621-
px1 = at1_cds.x - end1_trunc * bv[0] - dbo * perp.x;
622-
py1 = at1_cds.y - end1_trunc * bv[1] - dbo * perp.y;
623-
px2 = at2_cds.x + end2_trunc * bv[0] - dbo * perp.x;
624-
py2 = at2_cds.y + end2_trunc * bv[1] - dbo * perp.y;
625-
drawLine( Point2D( px1 , py1 ) , Point2D( px2 , py2 ) , col1 , col2 );
609+
Point2D bv=at1_cds - at2_cds;
610+
Point2D p1=at1_cds - (bv*end1_trunc) + perp*dbo;
611+
Point2D p2=at2_cds + (bv*end2_trunc) + perp*dbo;
612+
drawLine( p1 , p2 , col1 , col2 );
613+
p1=at1_cds - (bv*end1_trunc) - perp*dbo;
614+
p2=at2_cds + (bv*end2_trunc) - perp*dbo;
615+
drawLine( p1 , p2 , col1 , col2 );
626616
}
627617
// all we have left now are double bonds in a ring or not in a ring
628618
// and multiply connected
@@ -635,13 +625,11 @@ namespace RDKit {
635625
perp = bondInsideDoubleBond( mol , bond );
636626
}
637627
double dbo = 2.0 * double_bond_offset;
638-
double bv[2] = { at1_cds.x - at2_cds.x , at1_cds.y - at2_cds.y };
639-
double px1 = at1_cds.x - 0.1 * bv[0] + dbo * perp.x;
640-
double py1 = at1_cds.y - 0.1 * bv[1] + dbo * perp.y;
641-
double px2 = at2_cds.x + 0.1 * bv[0] + dbo * perp.x;
642-
double py2 = at2_cds.y + 0.1 * bv[1] + dbo * perp.y;
628+
Point2D bv=at1_cds - at2_cds;
629+
Point2D p1 = at1_cds - bv * 0.1 + perp * dbo;
630+
Point2D p2 = at2_cds + bv * 0.1 + perp * dbo;
643631
if(bond->getBondType()==Bond::AROMATIC) setDash(dashes);
644-
drawLine( Point2D( px1 , py1 ) , Point2D( px2 , py2 ) , col1 , col2 );
632+
drawLine( p1, p2, col1 , col2 );
645633
if(bond->getBondType()==Bond::AROMATIC) setDash(noDash);
646634
}
647635
}
@@ -657,37 +645,30 @@ namespace RDKit {
657645
bool draw_dashed , const DrawColour &col1 ,
658646
const DrawColour &col2) {
659647
Point2D perp = calcPerpendicular( cds1 , cds2 );
660-
Point2D disp( 0.1 * perp.x , 0.1 * perp.y );
661-
Point2D end1 , end2;
662-
end1.x = cds2.x + disp.x;
663-
end1.y = cds2.y + disp.y;
664-
end2.x = cds2.x - disp.x;
665-
end2.y = cds2.y - disp.y;
648+
Point2D disp = perp*0.1;
649+
Point2D end1 = cds2 + disp;
650+
Point2D end2 = cds2 - disp;
666651

667652
setColour( col1 );
668653
if( draw_dashed ) {
669-
Point2D e1( end1.x - cds1.x , end1.y - cds1.y );
670-
Point2D e2( end2.x - cds1.x , end2.y - cds1.y );
654+
Point2D e1=end1-cds1;
655+
Point2D e2=end2-cds1;
671656
for( int i = 1 ; i < 11 ; ++i ) {
672657
if( 6 == i ) {
673658
setColour( col2 );
674659
}
675-
Point2D e11( cds1.x + double( i ) * 0.1 * e1.x ,
676-
cds1.y + double( i ) * 0.1 * e1.y );
677-
Point2D e22( cds1.x + double( i ) * 0.1 * e2.x ,
678-
cds1.y + double( i ) * 0.1 * e2.y );
660+
Point2D e11 = cds1 + e1*0.1*i;
661+
Point2D e22 = cds1 + e2*0.1*i;
679662
drawLine( e11 , e22 );
680663
}
681664
} else {
682665
if( col1 == col2 ) {
683666
drawTriangle( cds1 , end1 , end2 );
684667
} else {
685-
Point2D e1( end1.x - cds1.x , end1.y - cds1.y );
686-
Point2D e2( end2.x - cds1.x , end2.y - cds1.y );
687-
Point2D mid1( cds1.x + 0.5 * e1.x ,
688-
cds1.y + 0.5 * e1.y );
689-
Point2D mid2( cds1.x + 0.5 * e2.x ,
690-
cds1.y + 0.5 * e2.y );
668+
Point2D e1 = end1 - cds1;
669+
Point2D e2 = end2 - cds1;
670+
Point2D mid1 = cds1 + e1*0.5;
671+
Point2D mid2 = cds1 + e2*0.5;
691672
drawTriangle( cds1 , mid1 , mid2 );
692673
setColour( col2 );
693674
drawTriangle( mid1 , end2 , end1 );

Code/GraphMol/MolDraw2D/test1.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ using namespace RDKit;
2929
void test1(){
3030
std::cout << " ----------------- Test 1" << std::endl;
3131
{
32-
std::string smiles="CO[C@@H](O)C1=C(O[C@H](F)Cl)C=C1ONNC[NH3+]";
32+
std::string smiles="CO[C@@H](O)C1=C(O[C@H](F)Cl)C(C#N)=C1ONNC[NH3+]";
3333
ROMol *m = SmilesToMol(smiles);
3434
TEST_ASSERT(m);
3535
RDDepict::compute2DCoords(*m);
@@ -95,7 +95,7 @@ void test1(){
9595
void test2(){
9696
std::cout << " ----------------- Test 2" << std::endl;
9797
{
98-
std::string smiles="CO[C@@H](O)C1=C(O[C@H](F)Cl)C=C1ONNC[NH3+]";
98+
std::string smiles="CO[C@@H](O)C1=C(O[C@H](F)Cl)C(C#N)=C1ONNC[NH3+]";
9999
ROMol *m = SmilesToMol(smiles);
100100
TEST_ASSERT(m);
101101
RDDepict::compute2DCoords(*m);

0 commit comments

Comments
 (0)