Skip to content

Commit

Permalink
update header with proper license file name
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthieuDartiailh committed Mar 9, 2020
1 parent 0846189 commit b04d5d3
Show file tree
Hide file tree
Showing 37 changed files with 777 additions and 855 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Expand Up @@ -5,5 +5,5 @@
build/
dist/
kiwisolver.egg-info/

.eggs
.vscode
2 changes: 1 addition & 1 deletion LICENSE
Expand Up @@ -67,5 +67,5 @@ to indicate the copyright and license terms:
#
# Distributed under the terms of the Modified BSD License.
#
# The full license is in the file COPYING.txt, distributed with this software.
# The full license is in the file LICENSE, distributed with this software.
#------------------------------------------------------------------------------
2 changes: 1 addition & 1 deletion benchmarks/enaml_like_benchmark.py
Expand Up @@ -3,7 +3,7 @@
#
# Distributed under the terms of the Modified BSD License.
#
# The full license is in the file COPYING.txt, distributed with this software.
# The full license is in the file LICENSE, distributed with this software.
#------------------------------------------------------------------------------
"""Time updating an EditVariable in a set of constraints typical of enaml use.
Expand Down
173 changes: 84 additions & 89 deletions kiwi/constraint.h
Expand Up @@ -3,7 +3,7 @@
|
| Distributed under the terms of the Modified BSD License.
|
| The full license is in the file COPYING.txt, distributed with this software.
| The full license is in the file LICENSE, distributed with this software.
|----------------------------------------------------------------------------*/
#pragma once
#include <map>
Expand All @@ -14,111 +14,106 @@
#include "term.h"
#include "variable.h"


namespace kiwi
{

enum RelationalOperator { OP_LE, OP_GE, OP_EQ };

enum RelationalOperator
{
OP_LE,
OP_GE,
OP_EQ
};

class Constraint
{

public:
Constraint() : m_data(0) {}

Constraint() : m_data( 0 ) {}

Constraint( const Expression& expr,
RelationalOperator op,
double strength = strength::required ) :
m_data( new ConstraintData( expr, op, strength ) ) {}
Constraint(const Expression &expr,
RelationalOperator op,
double strength = strength::required) : m_data(new ConstraintData(expr, op, strength)) {}

Constraint( const Constraint& other, double strength ) :
m_data( new ConstraintData( other, strength ) ) {}
Constraint(const Constraint &other, double strength) : m_data(new ConstraintData(other, strength)) {}

~Constraint() {}
~Constraint() {}

const Expression& expression() const
{
return m_data->m_expression;
}
const Expression &expression() const
{
return m_data->m_expression;
}

RelationalOperator op() const
{
return m_data->m_op;
}
RelationalOperator op() const
{
return m_data->m_op;
}

double strength() const
{
return m_data->m_strength;
}
double strength() const
{
return m_data->m_strength;
}

bool operator!() const
{
return !m_data;
}
bool operator!() const
{
return !m_data;
}

private:

static Expression reduce( const Expression& expr )
{
std::map<Variable, double> vars;
typedef std::vector<Term>::const_iterator iter_t;
iter_t end = expr.terms().end();
for( iter_t it = expr.terms().begin(); it != end; ++it )
vars[ it->variable() ] += it->coefficient();
std::vector<Term> terms( vars.begin(), vars.end() );
return Expression( terms, expr.constant() );
}

class ConstraintData : public SharedData
{

public:

ConstraintData( const Expression& expr,
RelationalOperator op,
double strength ) :
SharedData(),
m_expression( reduce( expr ) ),
m_strength( strength::clip( strength ) ),
m_op( op ) {}

ConstraintData( const Constraint& other, double strength ) :
SharedData(),
m_expression( other.expression() ),
m_strength( strength::clip( strength ) ),
m_op( other.op() ) {}

~ConstraintData() {}

Expression m_expression;
double m_strength;
RelationalOperator m_op;

private:

ConstraintData( const ConstraintData& other );

ConstraintData& operator=( const ConstraintData& other );
};

SharedDataPtr<ConstraintData> m_data;

friend bool operator<( const Constraint& lhs, const Constraint& rhs )
{
return lhs.m_data < rhs.m_data;
}

friend bool operator==( const Constraint& lhs, const Constraint& rhs )
{
return lhs.m_data == rhs.m_data;
}

friend bool operator!=( const Constraint& lhs, const Constraint& rhs )
{
return lhs.m_data != rhs.m_data;
}
static Expression reduce(const Expression &expr)
{
std::map<Variable, double> vars;
typedef std::vector<Term>::const_iterator iter_t;
iter_t end = expr.terms().end();
for (iter_t it = expr.terms().begin(); it != end; ++it)
vars[it->variable()] += it->coefficient();
std::vector<Term> terms(vars.begin(), vars.end());
return Expression(terms, expr.constant());
}

class ConstraintData : public SharedData
{

public:
ConstraintData(const Expression &expr,
RelationalOperator op,
double strength) : SharedData(),
m_expression(reduce(expr)),
m_strength(strength::clip(strength)),
m_op(op) {}

ConstraintData(const Constraint &other, double strength) : SharedData(),
m_expression(other.expression()),
m_strength(strength::clip(strength)),
m_op(other.op()) {}

~ConstraintData() {}

Expression m_expression;
double m_strength;
RelationalOperator m_op;

private:
ConstraintData(const ConstraintData &other);

ConstraintData &operator=(const ConstraintData &other);
};

SharedDataPtr<ConstraintData> m_data;

friend bool operator<(const Constraint &lhs, const Constraint &rhs)
{
return lhs.m_data < rhs.m_data;
}

friend bool operator==(const Constraint &lhs, const Constraint &rhs)
{
return lhs.m_data == rhs.m_data;
}

friend bool operator!=(const Constraint &lhs, const Constraint &rhs)
{
return lhs.m_data != rhs.m_data;
}
};

} // namespace kiwi

0 comments on commit b04d5d3

Please sign in to comment.