<commit_before>/**
 * Copyright (C) 2012 by INdT
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 */

#include "box2ddistancejointitem.h"

#include "util.h"

#include <Box2D/Box2D.h>

Box2DDistanceJointItem::Box2DDistanceJointItem(Scene *parent)
    : Box2DJointItem(parent)
{
}

Box2DDistanceJointItem::~Box2DDistanceJointItem()
{
    if (!m_world || !m_joint)
        return;

    m_joint = 0;
}

void Box2DDistanceJointItem::initialize()
{
    if (m_initialized || !m_entityA || !m_entityB || !m_world)
        return;

    if (!m_entityA->initialized())
        m_entityA->initialize();
    if (!m_entityB->initialized())
        m_entityB->initialize();

    b2DistanceJointDef jointDef;

    jointDef.collideConnected = m_collideConnected;

    jointDef.Initialize(m_entityA->body(),
                        m_entityB->body(),
                        m_anchorA.isNull() ? m_entityA->body()->GetWorldCenter() : b2Util::b2Vec(m_anchorA, m_scaleRatio),
                        m_anchorB.isNull() ? m_entityB->body()->GetWorldCenter() : b2Util::b2Vec(m_anchorB, m_scaleRatio));


    m_joint = static_cast<b2DistanceJoint *>(m_worldPtr->CreateJoint(&jointDef));

    setHeight(length());
    emit lengthChanged();

    m_initialized = true;
}

b2Vec2 Box2DDistanceJointItem::b2TransformOrigin() const
{<commit_msg>Joints: Don't initialize bodies on joint init<commit_after>/**
 * Copyright (C) 2012 by INdT
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 */

#include "box2ddistancejointitem.h"

#include "util.h"

#include <Box2D/Box2D.h>

Box2DDistanceJointItem::Box2DDistanceJointItem(Scene *parent)
    : Box2DJointItem(parent)
{
}

Box2DDistanceJointItem::~Box2DDistanceJointItem()
{
    if (!m_world || !m_joint)
        return;

    m_joint = 0;
}

void Box2DDistanceJointItem::initialize()
{
    if (m_initialized || !m_entityA || !m_entityB || !m_world)
        return;
    if (!m_entityA->initialized())
        return;
    if (!m_entityB->initialized())
        return;

    b2DistanceJointDef jointDef;

    jointDef.collideConnected = m_collideConnected;

    jointDef.Initialize(m_entityA->body(),
                        m_entityB->body(),
                        m_entityA->body()->GetWorldCenter() + b2Util::b2Vec(m_anchorA, m_scaleRatio),
                        m_entityB->body()->GetWorldCenter() + b2Util::b2Vec(m_anchorB, m_scaleRatio));

    m_joint = static_cast<b2DistanceJoint *>(m_worldPtr->CreateJoint(&jointDef));

    setHeight(length());
    emit lengthChanged();

    m_initialized = true;
}

b2Vec2 Box2DDistanceJointItem::b2TransformOrigin() const
{
{'fraction_non_alphanumeric': 0.10789602746444335, 'fraction_numerical': 0.01765571358509073, 'mean_word_length': 3.6510832383124288, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4772349', 'n_tokens_mistral': 1292, 'n_tokens_neox': 1229, 'n_words': 368}