1 /* === S Y N F I G ========================================================= */
2 /*! \file valuenode_dotproduct.cpp
3 ** \brief Implementation of the "DotProduct" valuenode conversion.
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 ** Copyright (c) 2008 Chris Moore
11 ** This package is free software; you can redistribute it and/or
12 ** modify it under the terms of the GNU General Public License as
13 ** published by the Free Software Foundation; either version 2 of
14 ** the License, or (at your option) any later version.
16 ** This package is distributed in the hope that it will be useful,
17 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 ** General Public License for more details.
22 /* ========================================================================= */
24 /* === H E A D E R S ======================================================= */
33 #include "valuenode_dotproduct.h"
34 #include "valuenode_const.h"
39 /* === U S I N G =========================================================== */
43 using namespace synfig;
45 /* === M A C R O S ========================================================= */
47 /* === G L O B A L S ======================================================= */
49 /* === P R O C E D U R E S ================================================= */
51 /* === M E T H O D S ======================================================= */
53 ValueNode_DotProduct::ValueNode_DotProduct(const ValueBase &value):
54 LinkableValueNode(value.get_type())
56 switch(value.get_type())
58 case ValueBase::TYPE_REAL:
59 set_link("lhs",ValueNode_Const::create(Vector(value.get(Real()),0)));
60 set_link("rhs",ValueNode_Const::create(Vector(1,0)));
62 case ValueBase::TYPE_ANGLE:
63 set_link("lhs",ValueNode_Const::create(Vector(Angle::cos(value.get(Angle())).get(), Angle::sin(value.get(Angle())).get())));
64 set_link("rhs",ValueNode_Const::create(Vector(1,0)));
67 throw Exception::BadType(ValueBase::type_local_name(value.get_type()));
74 ValueNode_DotProduct::create_new()const
76 return new ValueNode_DotProduct(get_type());
80 ValueNode_DotProduct::create(const ValueBase &x)
82 return new ValueNode_DotProduct(x);
85 ValueNode_DotProduct::~ValueNode_DotProduct()
91 ValueNode_DotProduct::operator()(Time t)const
93 Vector lhs((*lhs_)(t).get(Vector()));
94 Vector rhs((*rhs_)(t).get(Vector()));
98 case ValueBase::TYPE_ANGLE:
99 return Angle::cos(lhs * rhs / lhs.mag() / rhs.mag()).mod();
100 case ValueBase::TYPE_REAL:
111 ValueNode_DotProduct::get_name()const
117 ValueNode_DotProduct::get_local_name()const
119 return _("Dot Product");
123 ValueNode_DotProduct::set_link_vfunc(int i,ValueNode::Handle value)
125 assert(i>=0 && i<link_count());
129 case 0: CHECK_TYPE_AND_SET_VALUE(lhs_, ValueBase::TYPE_VECTOR);
130 case 1: CHECK_TYPE_AND_SET_VALUE(rhs_, ValueBase::TYPE_VECTOR);
135 ValueNode::LooseHandle
136 ValueNode_DotProduct::get_link_vfunc(int i)const
138 assert(i>=0 && i<link_count());
150 ValueNode_DotProduct::link_count()const
156 ValueNode_DotProduct::link_name(int i)const
158 assert(i>=0 && i<link_count());
162 case 0: return "lhs";
163 case 1: return "rhs";
169 ValueNode_DotProduct::link_local_name(int i)const
171 assert(i>=0 && i<link_count());
175 case 0: return _("LHS");
176 case 1: return _("RHS");
182 ValueNode_DotProduct::get_link_index_from_name(const String &name)const
184 if (name=="lhs") return 0;
185 if (name=="rhs") return 1;
187 throw Exception::BadLinkName(name);
191 ValueNode_DotProduct::check_type(ValueBase::Type type)
194 type==ValueBase::TYPE_ANGLE ||
195 type==ValueBase::TYPE_REAL;