Switch to template types for vectors
This commit is contained in:
parent
9f036d6438
commit
8192ef78e8
105 changed files with 1614 additions and 1424 deletions
|
@ -11,5 +11,5 @@ public:
|
|||
|
||||
virtual ~CircuitElementNode();
|
||||
|
||||
virtual Point getConnectionLocation(Wire* wire) const = 0;
|
||||
virtual Point2 getConnectionLocation(Wire* wire) const = 0;
|
||||
};
|
|
@ -18,7 +18,7 @@ LogicGateNode::~LogicGateNode()
|
|||
|
||||
}
|
||||
|
||||
Point LogicGateNode::getConnectionLocation(Wire* wire) const
|
||||
Point2 LogicGateNode::getConnectionLocation(Wire* wire) const
|
||||
{
|
||||
bool is_input{ false };
|
||||
std::size_t connection_id{ 0 };
|
||||
|
@ -42,7 +42,7 @@ Point LogicGateNode::getConnectionLocation(Wire* wire) const
|
|||
}
|
||||
}
|
||||
|
||||
Point loc;
|
||||
Point2 loc;
|
||||
if (mContent->getGateType() == LogicGate::GateType::AND)
|
||||
{
|
||||
loc = LogicGatePrimitiveShapes::getAndGateConnectionLocation(is_input, connection_id);
|
||||
|
@ -52,7 +52,7 @@ Point LogicGateNode::getConnectionLocation(Wire* wire) const
|
|||
loc = LogicGatePrimitiveShapes::getOrGateConnectionLocation(is_input, connection_id);
|
||||
}
|
||||
|
||||
loc.move(mTransform.getLocation().getX(), mTransform.getLocation().getY());
|
||||
loc.moveBy(mTransform.getLocation().getX(), mTransform.getLocation().getY());
|
||||
return loc;
|
||||
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ public:
|
|||
|
||||
virtual ~LogicGateNode();
|
||||
|
||||
Point getConnectionLocation(Wire* wire) const override;
|
||||
Point2 getConnectionLocation(Wire* wire) const override;
|
||||
|
||||
void setContent(LogicGate* content);
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ std::string LogicGatePrimitiveShapes::getAndGateShape()
|
|||
return "M4 8 h24 a16 16 0 0 1 0 32 h-24Z";
|
||||
}
|
||||
|
||||
Point LogicGatePrimitiveShapes::getAndGateConnectionLocation(bool isInput, std::size_t idx)
|
||||
Point2 LogicGatePrimitiveShapes::getAndGateConnectionLocation(bool isInput, std::size_t idx)
|
||||
{
|
||||
if (isInput)
|
||||
{
|
||||
|
@ -29,7 +29,7 @@ std::string LogicGatePrimitiveShapes::getOrGateShape()
|
|||
return "M4 8 h16 q16 2 24 16 q-12 16 -24 16 h-16 q12 -16 0 -32Z";
|
||||
}
|
||||
|
||||
Point LogicGatePrimitiveShapes::getOrGateConnectionLocation(bool isInput, std::size_t idx)
|
||||
Point2 LogicGatePrimitiveShapes::getOrGateConnectionLocation(bool isInput, std::size_t idx)
|
||||
{
|
||||
if (isInput)
|
||||
{
|
||||
|
|
|
@ -7,11 +7,11 @@
|
|||
class LogicGatePrimitiveShapes
|
||||
{
|
||||
public:
|
||||
static Point getAndGateConnectionLocation(bool isInput, std::size_t idx);
|
||||
static Point2 getAndGateConnectionLocation(bool isInput, std::size_t idx);
|
||||
|
||||
static std::string getAndGateShape();
|
||||
|
||||
static Point getOrGateConnectionLocation(bool isInput, std::size_t idx);
|
||||
static Point2 getOrGateConnectionLocation(bool isInput, std::size_t idx);
|
||||
|
||||
static std::string getOrGateShape();
|
||||
};
|
|
@ -34,7 +34,7 @@ void TerminalNode::update(SceneInfo* sceneInfo)
|
|||
}
|
||||
}
|
||||
|
||||
Point TerminalNode::getConnectionLocation(Wire*) const
|
||||
Point2 TerminalNode::getConnectionLocation(Wire*) const
|
||||
{
|
||||
return mTransform.getLocation();
|
||||
return { mTransform.getLocation().getX(), mTransform.getLocation().getY() };
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ class TerminalNode : public CircuitElementNode
|
|||
public:
|
||||
TerminalNode(const Transform& transform);
|
||||
|
||||
Point getConnectionLocation(Wire* wire) const override;
|
||||
Point2 getConnectionLocation(Wire* wire) const override;
|
||||
|
||||
void setContent(Terminal* terminal);
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ void WireNode::setContent(Wire* wire)
|
|||
mContentDirty = true;
|
||||
}
|
||||
|
||||
void WireNode::setInputLocation(const Point& point)
|
||||
void WireNode::setInputLocation(const Point2& point)
|
||||
{
|
||||
if (mInputLocation != point)
|
||||
{
|
||||
|
@ -23,7 +23,7 @@ void WireNode::setInputLocation(const Point& point)
|
|||
}
|
||||
}
|
||||
|
||||
void WireNode::setOutputLocation(const Point& point)
|
||||
void WireNode::setOutputLocation(const Point2& point)
|
||||
{
|
||||
if (mOutputLocation != point)
|
||||
{
|
||||
|
@ -46,9 +46,9 @@ void WireNode::createOrUpdateGeometry(SceneInfo*)
|
|||
if (!mLine)
|
||||
{
|
||||
auto loc = mOutputLocation;
|
||||
loc.move(-mInputLocation.getX(), -mInputLocation.getY(), -mInputLocation.getZ());
|
||||
loc.moveBy(-mInputLocation.getX(), -mInputLocation.getY(), -mInputLocation.getZ());
|
||||
|
||||
std::vector<Point> points;
|
||||
std::vector<Point2> points;
|
||||
|
||||
if (loc.getY() == 0.0)
|
||||
{
|
||||
|
@ -56,8 +56,8 @@ void WireNode::createOrUpdateGeometry(SceneInfo*)
|
|||
}
|
||||
else
|
||||
{
|
||||
auto join0 = Point(loc.getX() * 3.0 / 4.0, 0.0);
|
||||
auto join1 = Point(loc.getX() * 3.0 / 4.0, loc.getY());
|
||||
auto join0 = Point2(loc.getX() * 3.0 / 4.0, 0.0);
|
||||
auto join1 = Point2(loc.getX() * 3.0 / 4.0, loc.getY());
|
||||
points = { join0, join1 , loc};
|
||||
}
|
||||
|
||||
|
|
|
@ -13,9 +13,9 @@ public:
|
|||
|
||||
void setContent(Wire* wire);
|
||||
|
||||
void setInputLocation(const Point& point);
|
||||
void setInputLocation(const Point2& point);
|
||||
|
||||
void setOutputLocation(const Point& point);
|
||||
void setOutputLocation(const Point2& point);
|
||||
|
||||
void update(SceneInfo* sceneInfo);
|
||||
private:
|
||||
|
@ -23,8 +23,8 @@ private:
|
|||
Wire* mContent{ nullptr };
|
||||
bool mContentDirty{ true };
|
||||
|
||||
Point mInputLocation;
|
||||
Point mOutputLocation;
|
||||
Point2 mInputLocation;
|
||||
Point2 mOutputLocation;
|
||||
|
||||
std::unique_ptr<LineNode> mLine;
|
||||
};
|
|
@ -3,8 +3,8 @@
|
|||
#include "CircleNode.h"
|
||||
#include "LineNode.h"
|
||||
|
||||
BlochSphereNode::BlochSphereNode(const Point& location)
|
||||
: AbstractVisualNode(location, "BlochSphereNode")
|
||||
BlochSphereNode::BlochSphereNode(const Point2& location)
|
||||
: AbstractVisualNode(Transform(location))
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -40,8 +40,8 @@ void BlochSphereNode::update(SceneInfo*)
|
|||
|
||||
mOuterCircle = std::make_unique<CircleNode>(loc, mSize/2.0);
|
||||
|
||||
const auto end_point_x = Point(loc.getX() + 1.2 * mSize / 2.0, loc.getY());
|
||||
const std::vector<Point> points{end_point_x };
|
||||
const auto end_point_x = Point2(loc.getX() + 1.2 * mSize / 2.0, loc.getY());
|
||||
const std::vector<Point2> points{end_point_x };
|
||||
mXAxis = std::make_unique<LineNode>(loc, points);
|
||||
|
||||
mCentreCircle = std::make_unique<CircleNode>(loc, mSize / 50.0);
|
||||
|
|
|
@ -11,7 +11,7 @@ class LineNode;
|
|||
class BlochSphereNode : public AbstractVisualNode
|
||||
{
|
||||
public:
|
||||
BlochSphereNode(const Point& location);
|
||||
BlochSphereNode(const Point2& location);
|
||||
|
||||
void setContent(BlochSphere* content);
|
||||
|
||||
|
|
|
@ -11,5 +11,5 @@ public:
|
|||
|
||||
virtual ~QuantumCircuitElementNode();
|
||||
|
||||
virtual Point getConnectionLocation(AbstractQuantumWire* wire) const = 0;
|
||||
virtual Point2 getConnectionLocation(AbstractQuantumWire* wire) const = 0;
|
||||
};
|
|
@ -123,7 +123,7 @@ void QuantumCircuitNode::createOrUpdateGeometry(SceneInfo*)
|
|||
wire_node->setInputLocation(start_loc);
|
||||
|
||||
auto end_loc = end_node->getConnectionLocation(wire);
|
||||
auto straight_end_loc = Point(end_loc.getX(), start_loc.getY());
|
||||
auto straight_end_loc = Point2(end_loc.getX(), start_loc.getY());
|
||||
wire_node->setOutputLocation(straight_end_loc);
|
||||
|
||||
addChild(wire_node.get());
|
||||
|
|
|
@ -72,7 +72,7 @@ void QuantumGateNode::createOrUpdateGeometry(SceneInfo*)
|
|||
}
|
||||
}
|
||||
|
||||
Point QuantumGateNode::getConnectionLocation(AbstractQuantumWire* wire) const
|
||||
Point2 QuantumGateNode::getConnectionLocation(AbstractQuantumWire* wire) const
|
||||
{
|
||||
bool is_input{ false };
|
||||
//std::size_t connection_id{ 0 };
|
||||
|
@ -96,16 +96,16 @@ Point QuantumGateNode::getConnectionLocation(AbstractQuantumWire* wire) const
|
|||
}
|
||||
}
|
||||
|
||||
Point loc;
|
||||
Point2 loc;
|
||||
if (is_input)
|
||||
{
|
||||
loc = Point(0.0, mBodyHeight/2.0);
|
||||
loc = Point2(0.0, mBodyHeight/2.0);
|
||||
}
|
||||
else
|
||||
{
|
||||
loc = Point(mBodyWidth, mBodyHeight / 2.0);
|
||||
loc = Point2(mBodyWidth, mBodyHeight / 2.0);
|
||||
}
|
||||
|
||||
loc.move(mTransform.getLocation().getX(), mTransform.getLocation().getY());
|
||||
loc.moveBy(mTransform.getLocation().getX(), mTransform.getLocation().getY());
|
||||
return loc;
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ public:
|
|||
|
||||
virtual ~QuantumGateNode();
|
||||
|
||||
Point getConnectionLocation(AbstractQuantumWire* wire) const override;
|
||||
Point2 getConnectionLocation(AbstractQuantumWire* wire) const override;
|
||||
|
||||
void setContent(QuantumGate* gate);
|
||||
|
||||
|
|
|
@ -52,9 +52,9 @@ void QuantumTerminalNode::createOrUpdateGeometry(SceneInfo*)
|
|||
}
|
||||
}
|
||||
|
||||
Point QuantumTerminalNode::getConnectionLocation(AbstractQuantumWire*) const
|
||||
Point2 QuantumTerminalNode::getConnectionLocation(AbstractQuantumWire*) const
|
||||
{
|
||||
auto left = mTransform.getLocation();
|
||||
left.move(mWidth, mHeight/2.0);
|
||||
return left;
|
||||
left.moveBy(mWidth, mHeight/2.0);
|
||||
return { left.getX(), left.getY() };
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ class QuantumTerminalNode : public QuantumCircuitElementNode
|
|||
public:
|
||||
QuantumTerminalNode(const Transform& transform);
|
||||
|
||||
Point getConnectionLocation(AbstractQuantumWire* wire) const override;
|
||||
Point2 getConnectionLocation(AbstractQuantumWire* wire) const override;
|
||||
|
||||
void setContent(QuantumTerminal* terminal);
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ void QuantumWireNode::setContent(QuantumWire* content)
|
|||
mContentDirty = true;
|
||||
}
|
||||
|
||||
void QuantumWireNode::setInputLocation(const Point& point)
|
||||
void QuantumWireNode::setInputLocation(const Point2& point)
|
||||
{
|
||||
if (mInputLocation != point)
|
||||
{
|
||||
|
@ -29,7 +29,7 @@ void QuantumWireNode::setInputLocation(const Point& point)
|
|||
}
|
||||
}
|
||||
|
||||
void QuantumWireNode::setOutputLocation(const Point& point)
|
||||
void QuantumWireNode::setOutputLocation(const Point2& point)
|
||||
{
|
||||
if (mOutputLocation != point)
|
||||
{
|
||||
|
@ -52,9 +52,9 @@ void QuantumWireNode::createOrUpdateGeometry(SceneInfo*)
|
|||
if (!mLine)
|
||||
{
|
||||
auto loc = mOutputLocation;
|
||||
loc.move(-mInputLocation.getX(), -mInputLocation.getY(), -mInputLocation.getZ());
|
||||
loc.moveBy(-mInputLocation.getX(), -mInputLocation.getY(), -mInputLocation.getZ());
|
||||
|
||||
std::vector<Point> points;
|
||||
std::vector<Point2> points;
|
||||
|
||||
if (loc.getY() == 0.0)
|
||||
{
|
||||
|
@ -62,8 +62,8 @@ void QuantumWireNode::createOrUpdateGeometry(SceneInfo*)
|
|||
}
|
||||
else
|
||||
{
|
||||
auto join0 = Point(loc.getX() * 3.0 / 4.0, 0.0);
|
||||
auto join1 = Point(loc.getX() * 3.0 / 4.0, loc.getY());
|
||||
auto join0 = Point2(loc.getX() * 3.0 / 4.0, 0.0);
|
||||
auto join1 = Point2(loc.getX() * 3.0 / 4.0, loc.getY());
|
||||
points = { join0, join1 , loc };
|
||||
}
|
||||
|
||||
|
|
|
@ -12,9 +12,9 @@ public:
|
|||
|
||||
virtual ~QuantumWireNode();
|
||||
|
||||
void setInputLocation(const Point& point);
|
||||
void setInputLocation(const Point2& point);
|
||||
|
||||
void setOutputLocation(const Point& point);
|
||||
void setOutputLocation(const Point2& point);
|
||||
|
||||
void setContent(QuantumWire* content);
|
||||
|
||||
|
@ -26,8 +26,8 @@ private:
|
|||
QuantumWire* mContent{ nullptr };
|
||||
bool mContentDirty{ true };
|
||||
|
||||
Point mInputLocation;
|
||||
Point mOutputLocation;
|
||||
Point2 mInputLocation;
|
||||
Point2 mOutputLocation;
|
||||
|
||||
std::unique_ptr<LineNode> mLine;
|
||||
};
|
|
@ -11,7 +11,7 @@ TEST_CASE(TestBlochSphereNode, "quantum_computing")
|
|||
{
|
||||
TestRenderer renderer(100, 100);
|
||||
|
||||
auto node = std::make_unique<BlochSphereNode>(Point(0.5, 0.5));
|
||||
auto node = std::make_unique<BlochSphereNode>(Point2(0.5, 0.5));
|
||||
|
||||
Qubit state({ 1.0, 0.0 }, { 0.0, 0.0 });
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue