changeset 902:fa5b945f8db8 am-dev

Merge
author Alain Mazy <alain@mazy.be>
date Wed, 17 Jul 2019 09:53:51 +0200
parents f9ae731fdc25 (current diff) 240359ab1651 (diff)
children ef6e425dc79f
files
diffstat 4 files changed, 100 insertions(+), 61 deletions(-) [+]
line wrap: on
line diff
--- a/Framework/Scene2D/ScenePoint2D.h	Tue Jul 16 12:42:31 2019 +0200
+++ b/Framework/Scene2D/ScenePoint2D.h	Wed Jul 17 09:53:51 2019 +0200
@@ -91,17 +91,51 @@
       return v;
     }
 
+    const ScenePoint2D operator/(double a) const
+    {
+      ScenePoint2D v;
+      v.x_ = x_ / a;
+      v.y_ = y_ / a;
+
+      return v;
+    }
+
+    static void MidPoint(ScenePoint2D& result, const ScenePoint2D& a, const ScenePoint2D& b)
+    {
+      result.x_ = 0.5 * (a.x_ + b.x_);
+      result.y_ = 0.5 * (a.y_ + b.y_);
+    }
+
     static double Dot(const ScenePoint2D& a, const ScenePoint2D& b)
     {
       return a.x_ * b.x_ + a.y_ * b.y_;
     }
 
+    static double SquaredMagnitude(const ScenePoint2D& v)
+    {
+      return v.x_ * v.x_ + v.y_ * v.y_;
+    }
+
+    static double Magnitude(const ScenePoint2D& v)
+    {
+      double squaredMagnitude = SquaredMagnitude(v);
+      if (LinearAlgebra::IsCloseToZero(squaredMagnitude))
+        return 0.0;
+      return sqrt(squaredMagnitude);
+    }
+
     static double SquaredDistancePtPt(const ScenePoint2D& a, const ScenePoint2D& b)
     {
       ScenePoint2D n = b - a;
       return Dot(n, n);
     }
 
+    static double DistancePtPt(const ScenePoint2D& a, const ScenePoint2D& b)
+    {
+      double squaredDist = SquaredDistancePtPt(a, b);
+      return sqrt(squaredDist);
+    }
+
     /**
     Distance from point p to [a,b] segment
 
--- a/Framework/Scene2DViewport/AngleMeasureTool.cpp	Tue Jul 16 12:42:31 2019 +0200
+++ b/Framework/Scene2DViewport/AngleMeasureTool.cpp	Wed Jul 17 09:53:51 2019 +0200
@@ -46,7 +46,7 @@
     , layerHolder_(boost::make_shared<LayerHolder>(controllerW,1,5))
     , angleHighlightArea_(AngleHighlightArea_None)
   {
-
+    RefreshScene();
   }
 
   AngleMeasureTool::~AngleMeasureTool()
--- a/Framework/Scene2DViewport/MeasureToolsToolbox.cpp	Tue Jul 16 12:42:31 2019 +0200
+++ b/Framework/Scene2DViewport/MeasureToolsToolbox.cpp	Wed Jul 17 09:53:51 2019 +0200
@@ -35,23 +35,23 @@
 
 namespace OrthancStone
 {
-    void GetPositionOnBisectingLine(
-      ScenePoint2D& result
-      , const ScenePoint2D& p1
-      , const ScenePoint2D& c
-      , const ScenePoint2D& p2
-      , const double d)
-    {
-      // TODO: fix correct half-plane
-      double p1cAngle = atan2(p1.GetY() - c.GetY(), p1.GetX() - c.GetX());
-      double p2cAngle = atan2(p2.GetY() - c.GetY(), p2.GetX() - c.GetX());
-      double angle = 0.5 * (p1cAngle + p2cAngle);
-      double unitVectorX = cos(angle);
-      double unitVectorY = sin(angle);
-      double posX = c.GetX() + d * unitVectorX;
-      double posY = c.GetX() + d * unitVectorY;
-      result = ScenePoint2D(posX, posY);
-    }
+  void GetPositionOnBisectingLine(
+    ScenePoint2D& result
+    , const ScenePoint2D& p1
+    , const ScenePoint2D& c
+    , const ScenePoint2D& p2
+    , const double d)
+  {
+    // TODO: fix correct half-plane
+    double p1cAngle = atan2(p1.GetY() - c.GetY(), p1.GetX() - c.GetX());
+    double p2cAngle = atan2(p2.GetY() - c.GetY(), p2.GetX() - c.GetX());
+    double angle = 0.5 * (p1cAngle + p2cAngle);
+    double unitVectorX = cos(angle);
+    double unitVectorY = sin(angle);
+    double posX = c.GetX() + d * unitVectorX;
+    double posY = c.GetX() + d * unitVectorY;
+    result = ScenePoint2D(posX, posY);
+  }
 
   double RadiansToDegrees(double angleRad)
   {
@@ -60,12 +60,12 @@
   }
 
   void AddSquare(PolylineSceneLayer::Chain& chain,
-    const Scene2D&      scene,
+    const Scene2D& scene,
     const ScenePoint2D& centerS,
-    const double&       sideLengthS)
+    const double& sideLengthS)
   {
     // get the scaling factor 
-    const double sceneToCanvas = 
+    const double sceneToCanvas =
       scene.GetSceneToCanvasTransform().ComputeZoom();
 
     chain.clear();
@@ -93,29 +93,29 @@
   }
 #if 0
   void AddArc(
-      PolylineSceneLayer::Chain& chain
-    , const Scene2D&      scene
-    , const ScenePoint2D& p1
-    , const ScenePoint2D& c
-    , const ScenePoint2D& p2
-    , const double&       radiusS
+    PolylineSceneLayer::Chain & chain
+    , const Scene2D & scene
+    , const ScenePoint2D & p1
+    , const ScenePoint2D & c
+    , const ScenePoint2D & p2
+    , const double& radiusS
     , const bool          clockwise
     , const int           subdivisionsCount)
   {
     double p1cAngle = atan2(p1.GetY() - c.GetY(), p1.GetX() - c.GetX());
     double p2cAngle = atan2(p2.GetY() - c.GetY(), p2.GetX() - c.GetX());
     AddArc(
-      chain, scene, c, radiusS, p1cAngle, p2cAngle, 
+      chain, scene, c, radiusS, p1cAngle, p2cAngle,
       clockwise, subdivisionsCount);
   }
 #endif
 
   void AddShortestArc(
-      PolylineSceneLayer::Chain& chain
-    , const ScenePoint2D&        p1
-    , const ScenePoint2D&        c
-    , const ScenePoint2D&        p2
-    , const double&              radiusS
+    PolylineSceneLayer::Chain& chain
+    , const ScenePoint2D& p1
+    , const ScenePoint2D& c
+    , const ScenePoint2D& p2
+    , const double& radiusS
     , const int                  subdivisionsCount)
   {
     double p1cAngle = atan2(p1.GetY() - c.GetY(), p1.GetX() - c.GetX());
@@ -125,9 +125,9 @@
   }
 
   void AddShortestArc(
-      PolylineSceneLayer::Chain&  chain
-    , const ScenePoint2D&         centerS
-    , const double&               radiusS
+    PolylineSceneLayer::Chain& chain
+    , const ScenePoint2D& centerS
+    , const double& radiusS
     , const double                startAngleRad
     , const double                endAngleRad
     , const int                   subdivisionsCount)
@@ -135,12 +135,12 @@
     // this gives a signed difference between angle which
     // is the smallest difference (in magnitude) between 
     // the angles
-    double delta = NormalizeAngle(endAngleRad-startAngleRad);
+    double delta = NormalizeAngle(endAngleRad - startAngleRad);
 
     chain.clear();
     chain.reserve(subdivisionsCount + 1);
 
-    double angleIncr = delta/static_cast<double>(subdivisionsCount);
+    double angleIncr = delta / static_cast<double>(subdivisionsCount);
 
     double theta = startAngleRad;
     for (int i = 0; i < subdivisionsCount + 1; ++i)
@@ -156,10 +156,10 @@
 
 #if 0
   void AddArc(
-      PolylineSceneLayer::Chain& chain
-    , const Scene2D&      scene
-    , const ScenePoint2D& centerS
-    , const double&       radiusS
+    PolylineSceneLayer::Chain & chain
+    , const Scene2D & scene
+    , const ScenePoint2D & centerS
+    , const double& radiusS
     , const double        startAngleRad
     , const double        endAngleRad
     , const bool          clockwise
@@ -204,7 +204,7 @@
 
   void AddCircle(PolylineSceneLayer::Chain& chain,
     const ScenePoint2D& centerS,
-    const double&       radiusS,
+    const double& radiusS,
     const int           numSubdivisions)
   {
     //ScenePoint2D centerC = centerS.Apply(scene.GetSceneToCanvasTransform());
@@ -234,7 +234,7 @@
   double NormalizeAngle(double angle)
   {
     double retAngle = angle;
-    while (retAngle < -1.0*g_pi)
+    while (retAngle < -1.0 * g_pi)
       retAngle += 2 * g_pi;
     while (retAngle >= g_pi)
       retAngle -= 2 * g_pi;
@@ -251,11 +251,11 @@
 
 
 #if 0
-  void AddEllipse(PolylineSceneLayer::Chain& chain,
-    const Scene2D&      scene,
-    const ScenePoint2D& centerS,
-    const double&       halfHAxis,
-    const double&       halfVAxis)
+  void AddEllipse(PolylineSceneLayer::Chain & chain,
+    const Scene2D & scene,
+    const ScenePoint2D & centerS,
+    const double& halfHAxis,
+    const double& halfVAxis)
   {
     chain.clear();
     chain.reserve(4);
@@ -279,7 +279,7 @@
     chain.push_back(startRT);
     chain.push_back(startRB);
     chain.push_back(startLB);
-}
+  }
 #endif
 
   /**
@@ -288,8 +288,11 @@
   for the actual text
   */
   void SetTextLayerOutlineProperties(
-    Scene2D& scene, boost::shared_ptr<LayerHolder> layerHolder, 
-    const char* text, ScenePoint2D p)
+    Scene2D& scene
+    , boost::shared_ptr<LayerHolder> layerHolder
+    , const char* text
+    , ScenePoint2D p
+    , int startingLayerIndex) 
   {
     double xoffsets[5] = { 2, 0, -2, 0, 0 };
     double yoffsets[5] = { 0, -2, 0, 2, 0 };
@@ -298,22 +301,23 @@
     const double pixelToScene =
       scene.GetCanvasToSceneTransform().ComputeZoom();
 
-    for (int i = 0; i < 5; ++i)
+    for (int i = startingLayerIndex; i < startingLayerIndex + 5; ++i)
     {
       TextSceneLayer* textLayer = layerHolder->GetTextLayer(i);
+      ORTHANC_ASSERT(textLayer != NULL);
       textLayer->SetText(text);
 
       if (i == 4)
       {
         textLayer->SetColor(TEXT_COLOR_RED,
-                            TEXT_COLOR_GREEN,
-                            TEXT_COLOR_BLUE);
+          TEXT_COLOR_GREEN,
+          TEXT_COLOR_BLUE);
       }
       else
       {
         textLayer->SetColor(TEXT_OUTLINE_COLOR_RED,
-                            TEXT_OUTLINE_COLOR_GREEN,
-                            TEXT_OUTLINE_COLOR_BLUE);
+          TEXT_OUTLINE_COLOR_GREEN,
+          TEXT_OUTLINE_COLOR_BLUE);
       }
 
       ScenePoint2D textAnchor;
--- a/Framework/Scene2DViewport/MeasureToolsToolbox.h	Tue Jul 16 12:42:31 2019 +0200
+++ b/Framework/Scene2DViewport/MeasureToolsToolbox.h	Wed Jul 17 09:53:51 2019 +0200
@@ -180,10 +180,11 @@
   from layerIndex, up to (and not including) layerIndex+5.
   */
   void SetTextLayerOutlineProperties(
-    Scene2D& scene,
-    boost::shared_ptr<LayerHolder> layerHolder,
-    const char* text,
-    ScenePoint2D p);
+      Scene2D& scene
+    , boost::shared_ptr<LayerHolder> layerHolder
+    , const char* text
+    , ScenePoint2D p
+    , int startingLayerIndex = 0);
 
   std::ostream& operator<<(std::ostream& os, const ScenePoint2D& p);
 }