Skip to content

Commit e1ae49c

Browse files
committed
Connection line disappears if the x coordinate of the end point is lower than the x coordinate of the start point #10
A cubic Bezier curve is completely contained by the bounding box of its control points.
1 parent 8885db5 commit e1ae49c

6 files changed

+106
-13
lines changed

Sources/NodeEngineTest/GeometryTest.cpp

+63
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,67 @@ TEST (RectTest)
9494
ASSERT (IsEqual (r1.Expand (Size (5.0, 6.0)), Rect::FromCenterAndSize (r1.GetCenter (), r1.GetSize () + Size (5.0, 6.0))));
9595
}
9696

97+
TEST (BoundingRectTest_FromRects)
98+
{
99+
BoundingRect boundingRect;
100+
ASSERT (!boundingRect.IsValid ());
101+
102+
Rect rect1 = Rect::FromPositionAndSize (Point (0, 0), Size (100, 100));
103+
Rect rect2 = Rect::FromPositionAndSize (Point (10, 10), Size (50, 50));
104+
Rect rect3 = Rect::FromPositionAndSize (Point (-10, -10), Size (20, 20));
105+
106+
boundingRect.AddRect (rect1);
107+
ASSERT (boundingRect.IsValid ());
108+
ASSERT (IsEqual (boundingRect.GetRect (), rect1));
109+
110+
boundingRect.AddRect (rect2);
111+
ASSERT (boundingRect.IsValid ());
112+
ASSERT (IsEqual (boundingRect.GetRect (), rect1));
113+
114+
boundingRect.AddRect (rect3);
115+
ASSERT (boundingRect.IsValid ());
116+
ASSERT (IsEqual (boundingRect.GetRect (), Rect::FromPositionAndSize (Point (-10, -10), Size (110, 110))));
117+
}
118+
119+
TEST (BoundingRectTest_FromPoints)
120+
{
121+
BoundingRect boundingRect;
122+
ASSERT (!boundingRect.IsValid ());
123+
124+
boundingRect.AddPoint (Point (10, 10));
125+
ASSERT (boundingRect.IsValid ());
126+
ASSERT (IsEqual (boundingRect.GetRect (), Rect::FromPositionAndSize (Point (10, 10), Size (0, 0))));
127+
128+
boundingRect.AddPoint (Point (20, 20));
129+
ASSERT (boundingRect.IsValid ());
130+
ASSERT (IsEqual (boundingRect.GetRect (), Rect::FromPositionAndSize (Point (10, 10), Size (10, 10))));
131+
132+
boundingRect.AddPoint (Point (-10, -10));
133+
ASSERT (boundingRect.IsValid ());
134+
ASSERT (IsEqual (boundingRect.GetRect (), Rect::FromPositionAndSize (Point (-10, -10), Size (30, 30))));
135+
}
136+
137+
TEST (BoundingRectTest_FromRectAndPoint)
138+
{
139+
{
140+
BoundingRect boundingRect;
141+
ASSERT (!boundingRect.IsValid ());
142+
143+
boundingRect.AddPoint (Point (-10, -10));
144+
boundingRect.AddRect (Rect::FromPositionAndSize (Point (0, 0), Size (20, 20)));
145+
ASSERT (boundingRect.IsValid ());
146+
ASSERT (IsEqual (boundingRect.GetRect (), Rect::FromPositionAndSize (Point (-10, -10), Size (30, 30))));
147+
}
148+
149+
{
150+
BoundingRect boundingRect;
151+
ASSERT (!boundingRect.IsValid ());
152+
153+
boundingRect.AddRect (Rect::FromPositionAndSize (Point (0, 0), Size (20, 20)));
154+
boundingRect.AddPoint (Point (-10, -10));
155+
ASSERT (boundingRect.IsValid ());
156+
ASSERT (IsEqual (boundingRect.GetRect (), Rect::FromPositionAndSize (Point (-10, -10), Size (30, 30))));
157+
}
158+
}
159+
97160
}

Sources/NodeUIEngine/NUIE_Geometry.cpp

+17-4
Original file line numberDiff line numberDiff line change
@@ -411,13 +411,26 @@ int IntRect::GetHeight () const
411411
return height;
412412
}
413413

414-
BoundingRectCalculator::BoundingRectCalculator () :
414+
BoundingRect::BoundingRect () :
415415
boundingRect (),
416416
isValid (false)
417417
{
418418
}
419419

420-
void BoundingRectCalculator::AddRect (const Rect& rect)
420+
void BoundingRect::AddPoint (const Point& point)
421+
{
422+
if (!isValid) {
423+
boundingRect = Rect::FromPositionAndSize (point, Size (0.0, 0.0));
424+
isValid = true;
425+
} else {
426+
boundingRect = Rect::FromTwoPoints (
427+
Point (std::min (point.GetX (), boundingRect.GetLeft ()), std::min (point.GetY (), boundingRect.GetTop ())),
428+
Point (std::max (point.GetX (), boundingRect.GetRight ()), std::max (point.GetY (), boundingRect.GetBottom ()))
429+
);
430+
}
431+
}
432+
433+
void BoundingRect::AddRect (const Rect& rect)
421434
{
422435
if (!isValid) {
423436
boundingRect = rect;
@@ -430,12 +443,12 @@ void BoundingRectCalculator::AddRect (const Rect& rect)
430443
}
431444
}
432445

433-
bool BoundingRectCalculator::IsValid () const
446+
bool BoundingRect::IsValid () const
434447
{
435448
return isValid;
436449
}
437450

438-
const Rect& BoundingRectCalculator::GetRect () const
451+
const Rect& BoundingRect::GetRect () const
439452
{
440453
DBGASSERT (isValid);
441454
return boundingRect;

Sources/NodeUIEngine/NUIE_Geometry.hpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,12 @@ class IntRect
150150
int height;
151151
};
152152

153-
class BoundingRectCalculator
153+
class BoundingRect
154154
{
155155
public:
156-
BoundingRectCalculator ();
156+
BoundingRect ();
157157

158+
void AddPoint (const Point& point);
158159
void AddRect (const Rect& rect);
159160

160161
bool IsValid () const;

Sources/NodeUIEngine/NUIE_NodeUIManager.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ void NodeUIManager::ResizeContext (NodeUIDrawingEnvironment& drawingEnv, int new
460460

461461
bool NodeUIManager::GetBoundingRect (NodeUIDrawingEnvironment& drawingEnv, Rect& boundingRect) const
462462
{
463-
BoundingRectCalculator boundingRectCalculator;
463+
BoundingRect boundingRectCalculator;
464464
EnumerateNodes ([&] (const UINodeConstPtr& uiNode) {
465465
Rect nodeRect = GetNodeExtendedRect (drawingEnv, uiNode.get ());
466466
boundingRectCalculator.AddRect (nodeRect);

Sources/NodeUIEngine/NUIE_NodeUIManagerDrawer.cpp

+21-5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@
88
namespace NUIE
99
{
1010

11+
static void GetBezierControlPoints (const Point& beg, const Point& end, Point& controlPoint1, Point& controlPoint2)
12+
{
13+
double bezierOffsetVal = std::fabs (beg.GetX () - end.GetX ()) / 2.0;
14+
Point bezierOffset (bezierOffsetVal, 0.0);
15+
controlPoint1 = beg + bezierOffset;
16+
controlPoint2 = end - bezierOffset;
17+
}
18+
1119
NodeIdToNodeMap::NodeIdToNodeMap (const NodeUIManager& uiManager)
1220
{
1321
uiManager.EnumerateNodes ([&] (const UINodeConstPtr& uiNode) {
@@ -172,9 +180,9 @@ void NodeUIManagerDrawer::DrawConnections (NodeUIDrawingEnvironment& drawingEnv,
172180
void NodeUIManagerDrawer::DrawConnection (NodeUIDrawingEnvironment& drawingEnv, const Pen& pen, const Point& beg, const Point& end) const
173181
{
174182
DrawingContext& context = drawingEnv.GetDrawingContext ();
175-
double bezierOffsetVal = std::fabs (beg.GetX () - end.GetX ()) / 2.0;
176-
Point bezierOffset (bezierOffsetVal, 0.0);
177-
context.DrawBezier (beg, beg + bezierOffset, end - bezierOffset, end, pen);
183+
Point controlPoint1, controlPoint2;
184+
GetBezierControlPoints (beg, end, controlPoint1, controlPoint2);
185+
context.DrawBezier (beg, controlPoint1, controlPoint2, end, pen);
178186
}
179187

180188
void NodeUIManagerDrawer::DrawTemporaryConnection (NodeUIDrawingEnvironment& drawingEnv, const Pen& pen, const Point& beg, const Point& end, NodeDrawingModifier::Direction dir) const
@@ -274,8 +282,16 @@ void NodeUIManagerDrawer::InitSortedNodeList () const
274282

275283
bool NodeUIManagerDrawer::IsConnectionVisible (NodeUIDrawingEnvironment& drawingEnv, const Point& beg, const Point& end) const
276284
{
277-
Rect connectionRect = Rect::FromTwoPoints (beg, end);
278-
return IsRectVisible (drawingEnv, connectionRect);
285+
Point controlPoint1, controlPoint2;
286+
GetBezierControlPoints (beg, end, controlPoint1, controlPoint2);
287+
288+
BoundingRect connectionRect;
289+
connectionRect.AddPoint (beg);
290+
connectionRect.AddPoint (controlPoint1);
291+
connectionRect.AddPoint (controlPoint2);
292+
connectionRect.AddPoint (end);
293+
294+
return IsRectVisible (drawingEnv, connectionRect.GetRect ());
279295
}
280296

281297
bool NodeUIManagerDrawer::IsNodeVisible (NodeUIDrawingEnvironment& drawingEnv, const NodeUIScaleIndependentData& scaleIndependentData, const NodeDrawingModifier* drawModifier, const UINode* uiNode) const

Sources/NodeUIEngine/NUIE_UINodeGroup.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ void UINodeGroup::UpdateDrawingImage (NodeUIDrawingEnvironment& env, const NodeR
132132
const SkinParams& skinParams = env.GetSkinParams ();
133133
DrawingContext& drawingContext = env.GetDrawingContext ();
134134

135-
BoundingRectCalculator boundingRectCalculator;
135+
BoundingRect boundingRectCalculator;
136136
nodes.Enumerate ([&] (const NE::NodeId& nodeId) {
137137
Rect nodeRect = rectGetter.GetNodeRect (nodeId);
138138
boundingRectCalculator.AddRect (nodeRect);

0 commit comments

Comments
 (0)