<commit_before>
#pragma once

#include "ksp_plugin/part.hpp"

#include <list>
#include <string>

#include "base/array.hpp"
#include "base/hexadecimal.hpp"
#include "base/not_null.hpp"

namespace principia {
namespace ksp_plugin {
namespace internal_part {

using base::Array;
using base::HexadecimalEncode;
using base::make_not_null_unique;
using base::UniqueBytes;

Part::Part(
    PartId const part_id,
    std::string const& name,
    Mass const& mass,
    DegreesOfFreedom<Barycentric> const& degrees_of_freedom,
    std::function<void()> deletion_callback)
    : part_id_(part_id),
      name_(name),
      mass_(mass),
      degrees_of_freedom_(degrees_of_freedom),
      prehistory_(make_not_null_unique<DiscreteTrajectory<Barycentric>>()),
      subset_node_(make_not_null_unique<Subset<Part>::Node>()),
      deletion_callback_(std::move(deletion_callback)) {
  CHECK_GT(mass_, Mass{}) << ShortDebugString();
  prehistory_->Append(astronomy::InfinitePast,
                      {Barycentric::origin, Velocity<Barycentric>()});
  history_ = prehistory_->NewForkAtLast();
}

Part::~Part() {
  LOG(INFO) << "Destroying part " << ShortDebugString();
  CHECK(!is_piled_up());
  if (deletion_callback_ != nullptr) {
    deletion_callback_();
  }
}

PartId Part::part_id() const {
  return part_id_;
}

void Part::set_mass(Mass const& mass) {
  CHECK_GT(mass, Mass{}) << ShortDebugString();
  mass_ = mass;
}

Mass const& Part::mass() const {
  return mass_;
}

void Part::clear_intrinsic_force() {
  intrinsic_force_ = Vector<Force, Barycentric>{};
}

void Part::increment_intrinsic_force(
    Vector<Force, Barycentric> const& intrinsic_force) {
  intrinsic_force_ += intrinsic_force;
}

Vector<Force, Barycentric> const& Part::intrinsic_force() const {
  return intrinsic_force_;
}

void Part::set_degrees_of_freedom(
    DegreesOfFreedom<Barycentric> const& degrees_of_freedom) {
  degrees_of_freedom_ = degrees_of_freedom;
}

DegreesOfFreedom<Barycentric> const&
Part::degrees_of_freedom() const {
  return degrees_of_freedom_;
}

DiscreteTrajectory<Barycentric>::Iterator Part::history_begin() {
  // Make sure that we skip the point of the prehistory.
  auto it = history_->Fork();
  return ++it;
}

DiscreteTrajectory<Barycentric>::Iterator Part::history_end() {
  return history_->End();
}

DiscreteTrajectory<Barycentric>::Iterator Part::psychohistory_begin() {
  if (psychohistory_ == nullptr) {
    psychohistory_ = history_->NewForkAtLast();
  }
  // Make sure that we skip the fork, which may be the point of the prehistory.
  auto it = psychohistory_->Fork();
  return ++it;
}

DiscreteTrajectory<Barycentric>::Iterator Part::psychohistory_end() {
  if (psychohistory_ == nullptr) {
    psychohistory_ = history_->NewForkAtLast();
  }
  return psychohistory_->End();
}

void Part::AppendToHistory(
    Instant const& time,
    DegreesOfFreedom<Barycentric> const& degrees_of_freedom) {
  if (psychohistory_ != nullptr) {
    history_->DeleteFork(psychohistory_);
  }
  history_->Append(time, degrees_of_freedom);
}

void Part::AppendToPsychohistory(
    Instant const& time,
    DegreesOfFreedom<Barycentric> const& degrees_of_freedom) {
  if (psychohistory_ == nullptr) {
    psychohistory_ = history_->NewForkAtLast();
  }
  psychohistory_->Append(time, degrees_of_freedom);
}

void Part::ClearHistory() {
  if (psychohistory_ != nullptr) {
    history_->DeleteFork(psychohistory_);
  }
  prehistory_->DeleteFork(history_);
  history_ = prehistory_->NewForkAtLast();
}

void Part::set_containing_pile_up(IteratorOn<std::list<PileUp>> const pile_up) {
  CHECK(!is_piled_up());
  LOG(INFO) << "Adding part " << ShortDebugString() << " to the pile up at "
            << &*pile_up.iterator();
  containing_pile_up_ = pile_up;
}

std::experimental::optional<IteratorOn<std::list<PileUp>>>
Part::containing_pile_up() const {
  return containing_pile_up_;
}

bool Part::is_piled_up() const {
  // TODO(egg): |has_value()| once we have a standard |optional|.
  return static_cast<bool>(containing_pile_up_);
}

void Part::clear_pile_up() {
  if (is_piled_up()) {
    IteratorOn<std::list<PileUp>> pile_up = *containing_pile_up_;
    for (not_null<Part*> const part : pile_up.iterator()->parts()) {
      LOG(INFO) << "Removing part " << part->ShortDebugString()
                << " from its pile up at " << &*pile_up.iterator();
      part->containing_pile_up_ = std::experimental::nullopt;
    }
    CHECK(!is_piled_up());
    pile_up.Erase();
  }
}

void Part::WriteToMessage(not_null<serialization::Part*> const message) const {
  message->set_part_id(part_id_);
  message->set_name(name_);
  mass_.WriteToMessage(message->mutable_mass());
  intrinsic_force_.WriteToMessage(message->mutable_intrinsic_force());
  if (containing_pile_up_) {
    message->set_containing_pile_up(containing_pile_up_->distance_from_begin());
  }
  degrees_of_freedom_.WriteToMessage(message->mutable_degrees_of_freedom());
  prehistory_->WriteToMessage(message->mutable_prehistory(),
                              /*forks=*/{history_, psychohistory_});
}

not_null<std::unique_ptr<Part>> Part::ReadFromMessage(
    serialization::Part const& message,
    std::function<void()> deletion_callback) {
  bool const is_pre_cesàro = message.has_tail_is_authoritative();
  not_null<std::unique_ptr<Part>> part =
      make_not_null_unique<Part>(message.part_id(),
                                 message.name(),
                                 Mass::ReadFromMessage(message.mass()),
                                 DegreesOfFreedom<Barycentric>::ReadFromMessage(
                                     message.degrees_of_freedom()),
                                 std::move(deletion_callback));
  part->increment_intrinsic_force(
      Vector<Force, Barycentric>::ReadFromMessage(message.intrinsic_force()));
  if (is_pre_cesàro) {
    auto tail = DiscreteTrajectory<Barycentric>::ReadFromMessage(
        message.prehistory(),
        /*forks=*/{});
    // The |prehistory_| and |history_| have been created by the constructor
    // above.  Construct the various trajectories from the |tail|.
    for (auto it = tail->Begin(); it != tail->End(); ++it) {
      if (it == tail->last() && !message.tail_is_authoritative()) {
        part->AppendToPsychohistory(it.time(), it.degrees_of_freedom());
      } else {
        part->AppendToHistory(it.time(), it.degrees_of_freedom());
      }
    }
  } else {
    part->history_ = nullptr;
    part->prehistory_ = DiscreteTrajectory<Barycentric>::ReadFromMessage(
        message.prehistory(),
        /*forks=*/{&part->history_, &part->psychohistory_});
  }
  return part;
}

void Part::FillContainingPileUpFromMessage(
    serialization::Part const& message,
    not_null<std::list<PileUp>*> const pile_ups) {
  if (message.has_containing_pile_up()) {
    auto it = pile_ups->begin();
    std::advance(it, message.containing_pile_up());
    containing_pile_up_ = IteratorOn<std::list<PileUp>>(pile_ups, it);
  }
}

std::string Part::ShortDebugString() const {
  UniqueBytes hex_id(sizeof(part_id_) * 2 + 1);
  Array<std::uint8_t const> id_bytes(
      reinterpret_cast<std::uint8_t const*>(&part_id_), sizeof(part_id_));
  HexadecimalEncode(id_bytes, hex_id.get());
  hex_id.data[sizeof(part_id_) * 2] = '\0';
  return name_ + " (" + reinterpret_cast<char const*>(hex_id.data.get()) + ")";
}

std::ostream& operator<<(std::ostream& out, Part const& part) {
  return out << "{"
             << part.part_id() << ", "
             << part.mass() << "}";
}

}  // namespace internal_part
}  // namespace ksp_plugin
}  // namespace principia
<commit_msg>Turn part.cpp loop var copies to refs<commit_after>
#pragma once

#include "ksp_plugin/part.hpp"

#include <list>
#include <string>

#include "base/array.hpp"
#include "base/hexadecimal.hpp"
#include "base/not_null.hpp"

namespace principia {
namespace ksp_plugin {
namespace internal_part {

using base::Array;
using base::HexadecimalEncode;
using base::make_not_null_unique;
using base::UniqueBytes;

Part::Part(
    PartId const part_id,
    std::string const& name,
    Mass const& mass,
    DegreesOfFreedom<Barycentric> const& degrees_of_freedom,
    std::function<void()> deletion_callback)
    : part_id_(part_id),
      name_(name),
      mass_(mass),
      degrees_of_freedom_(degrees_of_freedom),
      prehistory_(make_not_null_unique<DiscreteTrajectory<Barycentric>>()),
      subset_node_(make_not_null_unique<Subset<Part>::Node>()),
      deletion_callback_(std::move(deletion_callback)) {
  CHECK_GT(mass_, Mass{}) << ShortDebugString();
  prehistory_->Append(astronomy::InfinitePast,
                      {Barycentric::origin, Velocity<Barycentric>()});
  history_ = prehistory_->NewForkAtLast();
}

Part::~Part() {
  LOG(INFO) << "Destroying part " << ShortDebugString();
  CHECK(!is_piled_up());
  if (deletion_callback_ != nullptr) {
    deletion_callback_();
  }
}

PartId Part::part_id() const {
  return part_id_;
}

void Part::set_mass(Mass const& mass) {
  CHECK_GT(mass, Mass{}) << ShortDebugString();
  mass_ = mass;
}

Mass const& Part::mass() const {
  return mass_;
}

void Part::clear_intrinsic_force() {
  intrinsic_force_ = Vector<Force, Barycentric>{};
}

void Part::increment_intrinsic_force(
    Vector<Force, Barycentric> const& intrinsic_force) {
  intrinsic_force_ += intrinsic_force;
}

Vector<Force, Barycentric> const& Part::intrinsic_force() const {
  return intrinsic_force_;
}

void Part::set_degrees_of_freedom(
    DegreesOfFreedom<Barycentric> const& degrees_of_freedom) {
  degrees_of_freedom_ = degrees_of_freedom;
}

DegreesOfFreedom<Barycentric> const&
Part::degrees_of_freedom() const {
  return degrees_of_freedom_;
}

DiscreteTrajectory<Barycentric>::Iterator Part::history_begin() {
  // Make sure that we skip the point of the prehistory.
  auto it = history_->Fork();
  return ++it;
}

DiscreteTrajectory<Barycentric>::Iterator Part::history_end() {
  return history_->End();
}

DiscreteTrajectory<Barycentric>::Iterator Part::psychohistory_begin() {
  if (psychohistory_ == nullptr) {
    psychohistory_ = history_->NewForkAtLast();
  }
  // Make sure that we skip the fork, which may be the point of the prehistory.
  auto it = psychohistory_->Fork();
  return ++it;
}

DiscreteTrajectory<Barycentric>::Iterator Part::psychohistory_end() {
  if (psychohistory_ == nullptr) {
    psychohistory_ = history_->NewForkAtLast();
  }
  return psychohistory_->End();
}

void Part::AppendToHistory(
    Instant const& time,
    DegreesOfFreedom<Barycentric> const& degrees_of_freedom) {
  if (psychohistory_ != nullptr) {
    history_->DeleteFork(psychohistory_);
  }
  history_->Append(time, degrees_of_freedom);
}

void Part::AppendToPsychohistory(
    Instant const& time,
    DegreesOfFreedom<Barycentric> const& degrees_of_freedom) {
  if (psychohistory_ == nullptr) {
    psychohistory_ = history_->NewForkAtLast();
  }
  psychohistory_->Append(time, degrees_of_freedom);
}

void Part::ClearHistory() {
  if (psychohistory_ != nullptr) {
    history_->DeleteFork(psychohistory_);
  }
  prehistory_->DeleteFork(history_);
  history_ = prehistory_->NewForkAtLast();
}

void Part::set_containing_pile_up(IteratorOn<std::list<PileUp>> const pile_up) {
  CHECK(!is_piled_up());
  LOG(INFO) << "Adding part " << ShortDebugString() << " to the pile up at "
            << &*pile_up.iterator();
  containing_pile_up_ = pile_up;
}

std::experimental::optional<IteratorOn<std::list<PileUp>>>
Part::containing_pile_up() const {
  return containing_pile_up_;
}

bool Part::is_piled_up() const {
  // TODO(egg): |has_value()| once we have a standard |optional|.
  return static_cast<bool>(containing_pile_up_);
}

void Part::clear_pile_up() {
  if (is_piled_up()) {
    IteratorOn<std::list<PileUp>> pile_up = *containing_pile_up_;
    for (not_null<Part*> const& part : pile_up.iterator()->parts()) {
      LOG(INFO) << "Removing part " << part->ShortDebugString()
                << " from its pile up at " << &*pile_up.iterator();
      part->containing_pile_up_ = std::experimental::nullopt;
    }
    CHECK(!is_piled_up());
    pile_up.Erase();
  }
}

void Part::WriteToMessage(not_null<serialization::Part*> const message) const {
  message->set_part_id(part_id_);
  message->set_name(name_);
  mass_.WriteToMessage(message->mutable_mass());
  intrinsic_force_.WriteToMessage(message->mutable_intrinsic_force());
  if (containing_pile_up_) {
    message->set_containing_pile_up(containing_pile_up_->distance_from_begin());
  }
  degrees_of_freedom_.WriteToMessage(message->mutable_degrees_of_freedom());
  prehistory_->WriteToMessage(message->mutable_prehistory(),
                              /*forks=*/{history_, psychohistory_});
}

not_null<std::unique_ptr<Part>> Part::ReadFromMessage(
    serialization::Part const& message,
    std::function<void()> deletion_callback) {
  bool const is_pre_cesàro = message.has_tail_is_authoritative();
  not_null<std::unique_ptr<Part>> part =
      make_not_null_unique<Part>(message.part_id(),
                                 message.name(),
                                 Mass::ReadFromMessage(message.mass()),
                                 DegreesOfFreedom<Barycentric>::ReadFromMessage(
                                     message.degrees_of_freedom()),
                                 std::move(deletion_callback));
  part->increment_intrinsic_force(
      Vector<Force, Barycentric>::ReadFromMessage(message.intrinsic_force()));
  if (is_pre_cesàro) {
    auto tail = DiscreteTrajectory<Barycentric>::ReadFromMessage(
        message.prehistory(),
        /*forks=*/{});
    // The |prehistory_| and |history_| have been created by the constructor
    // above.  Construct the various trajectories from the |tail|.
    for (auto it = tail->Begin(); it != tail->End(); ++it) {
      if (it == tail->last() && !message.tail_is_authoritative()) {
        part->AppendToPsychohistory(it.time(), it.degrees_of_freedom());
      } else {
        part->AppendToHistory(it.time(), it.degrees_of_freedom());
      }
    }
  } else {
    part->history_ = nullptr;
    part->prehistory_ = DiscreteTrajectory<Barycentric>::ReadFromMessage(
        message.prehistory(),
        /*forks=*/{&part->history_, &part->psychohistory_});
  }
  return part;
}

void Part::FillContainingPileUpFromMessage(
    serialization::Part const& message,
    not_null<std::list<PileUp>*> const pile_ups) {
  if (message.has_containing_pile_up()) {
    auto it = pile_ups->begin();
    std::advance(it, message.containing_pile_up());
    containing_pile_up_ = IteratorOn<std::list<PileUp>>(pile_ups, it);
  }
}

std::string Part::ShortDebugString() const {
  UniqueBytes hex_id(sizeof(part_id_) * 2 + 1);
  Array<std::uint8_t const> id_bytes(
      reinterpret_cast<std::uint8_t const*>(&part_id_), sizeof(part_id_));
  HexadecimalEncode(id_bytes, hex_id.get());
  hex_id.data[sizeof(part_id_) * 2] = '\0';
  return name_ + " (" + reinterpret_cast<char const*>(hex_id.data.get()) + ")";
}

std::ostream& operator<<(std::ostream& out, Part const& part) {
  return out << "{"
             << part.part_id() << ", "
             << part.mass() << "}";
}

}  // namespace internal_part
}  // namespace ksp_plugin
}  // namespace principia
<|endoftext|>


<commit_before>/**
 * Copyright (C) 2018 Shanghai YOUWAN Science & Technology Co., Ltd.
 * All rights reserved.
 *
 * This document is the property of Shanghai YOUWAN Science & Technology Co., Ltd.
 * It is considered confidential and proprietary.
 *
 * This document may not be reproduced or transmitted in any form,
 * in whole or in part, without the express written permission of
 * Shanghai YOUWAN Science & Technology Co., Ltd.
 */
#include "Ruler.h"
PAGAMES_WINNER_POKER_BEGIN

Ruler::Ruler()
{
    _isAlwaysWithPair     = false;
    _isBombDetachable     = false;
    _isAsTrioAceBomb      = true;
    _isThreeOfHeartsFirst = true;
}

Ruler &Ruler::getInstance()
{
    static Ruler _instance;
    return _instance;
}

bool Ruler::isAlwaysWithPair()
{
    return _isAlwaysWithPair;
}

bool Ruler::isBombDetachable()
{
    return _isBombDetachable;
}

bool Ruler::isAsTrioAceBomb()
{
    return _isAsTrioAceBomb;
}

bool Ruler::isThreeOfHeartsFirst()
{
    return _isThreeOfHeartsFirst;
}

PAGAMES_WINNER_POKER_END
<commit_msg>did everything<commit_after>// /**
//  * Copyright (C) 2018 Shanghai YOUWAN Science & Technology Co., Ltd.
//  * All rights reserved.
//  *
//  * This document is the property of Shanghai YOUWAN Science & Technology Co., Ltd.
//  * It is considered confidential and proprietary.
//  *
//  * This document may not be reproduced or transmitted in any form,
//  * in whole or in part, without the express written permission of
//  * Shanghai YOUWAN Science & Technology Co., Ltd.
//  */
// #include "Ruler.h"
// PAGAMES_WINNER_POKER_BEGIN
//
// Ruler::Ruler()
// {
//     _isAlwaysWithPair     = false;
//     _isBombDetachable     = false;
//     _isAsTrioAceBomb      = true;
//     _isThreeOfHeartsFirst = true;
// }
//
// Ruler &Ruler::getInstance()
// {
//     static Ruler _instance;
//     return _instance;
// }
//
// bool Ruler::isAlwaysWithPair()
// {
//     return _isAlwaysWithPair;
// }
//
// bool Ruler::isBombDetachable()
// {
//     return _isBombDetachable;
// }
//
// bool Ruler::isAsTrioAceBomb()
// {
//     return _isAsTrioAceBomb;
// }
//
// bool Ruler::isThreeOfHeartsFirst()
// {
//     return _isThreeOfHeartsFirst;
// }
//
// PAGAMES_WINNER_POKER_END
<|endoftext|>


<commit_before>/**
 *  machina
 *
 *  Copyright (c) 2014, drmats
 *  All rights reserved.
 *
 *  https://github.com/drmats/machina
 */

#ifndef __MACHINA_CPP_
#define __MACHINA_CPP_ 1

#include "machina.hpp"

namespace machina {

/**
 *  Initialize vital application components.
 */
Machina::Machina (int argc, char **argv):
    command_line_params{argc, argv}
{
    std::cout << "Hi!" << std::endl;

    this->initialize_sdl();
    this->initialize_surface();

    this->main_loop = std::make_shared<MainLoop>(this);
}

/**
 *  Clean-up.
 */
Machina::~Machina () {
    if (this->gl_context != NULL) {
        SDL_GL_DeleteContext(this->gl_context);
        std::cout
            << "Deleted OpenGL context."
            << std::endl;
    }

    if (this->main_window != NULL) {
        SDL_DestroyWindow(this->main_window);
        std::cout
            << "Destroyed surface."
            << std::endl;
    }

    std::cout << "Bye!" << std::endl;
}

/**
 *  Obtain SDL versions, initialize SDL and get video driver name.
 */
void Machina::initialize_sdl () {
    SDL_VERSION(&this->compile_sdl_version);
    std::cout
        << "Compile-time SDL version: "
        << static_cast<int>(this->compile_sdl_version.major) << "."
        << static_cast<int>(this->compile_sdl_version.minor) << "."
        << static_cast<int>(this->compile_sdl_version.patch)
        << std::endl;

    SDL_GetVersion(&this->linked_sdl_version);
    std::cout
        << "Runtime SDL version: "
        << static_cast<int>(this->linked_sdl_version.major) << "."
        << static_cast<int>(this->linked_sdl_version.minor) << "."
        << static_cast<int>(this->linked_sdl_version.patch)
        << std::endl;

    if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS | SDL_INIT_TIMER) == 0) {
        SDL_Delay(this->init_delay);
        std::atexit(SDL_Quit);
    } else {
        std::cerr
            << "Unable to initialize SDL: "
            << SDL_GetError()
            << std::endl;
        std::exit(EXIT_FAILURE);
    }

    this->video_driver_name = SDL_GetCurrentVideoDriver();
    if (this->video_driver_name != NULL) {
        std::cout
            << "Video driver: "
            << this->video_driver_name
            << std::endl;
    } else {
        std::cerr
            << "Failed to obtain the video driver name."
            << std::endl;
    }
}

/**
 *  Initialize viewport/drawing surface.
 */
void Machina::initialize_surface () {
    // main window
    this->main_window = SDL_CreateWindow(
        PROGRAM_NAME.c_str(),
        SDL_WINDOWPOS_CENTERED,
        SDL_WINDOWPOS_CENTERED,
        this->viewport.width, this->viewport.height,
        SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE
    );
    if (this->main_window != NULL) {
        SDL_Delay(this->init_delay);
        std::cout
            << "Initialized surface: "
            << this->viewport.width << "x" << this->viewport.height
            << std::endl;
    } else {
        std::cerr
            << "Unable to initialize surface: "
            << SDL_GetError()
            << std::endl;
        std::exit(EXIT_FAILURE);
    }

    // main GL context
    this->gl_context = SDL_GL_CreateContext(this->main_window);
    if (this->gl_context != NULL) {
        SDL_Delay(this->init_delay);
        std::cout
            << "Created OpenGL context."
            << std::endl;
    } else {
        std::cerr
            << "Unable to create OpenGL context "
            << SDL_GetError()
            << std::endl;
        std::exit(EXIT_FAILURE);
    }

    // GLEW initialization
    glewExperimental = GL_TRUE;
    this->glew_status = glewInit();
    if (this->glew_status == GLEW_OK) {
        SDL_Delay(this->init_delay);
        std::cout
            << "GLEW version: "
            << glewGetString(GLEW_VERSION)
            << std::endl;
    } else {
        std::cerr
            << "Unable to initialize GLEW: "
            << glewGetErrorString(this->glew_status)
            << std::endl;
        std::exit(EXIT_FAILURE);
    }

    // GL version
    glGetIntegerv(GL_MAJOR_VERSION, &this->opengl_major_version);
    glGetIntegerv(GL_MINOR_VERSION, &this->opengl_minor_version);
    this->opengl_version_string =
        reinterpret_cast<const char *>(glGetString(GL_VERSION));
    std::cout
        << "OpenGL version: "
        << this->opengl_major_version << "."
        << this->opengl_minor_version << " "
        << "(" << this->opengl_version_string << ")"
        << std::endl
        << "OpenGL vendor: "
        << reinterpret_cast<const char *>(glGetString(GL_VENDOR))
        << std::endl
        << "OpenGL renderer: "
        << reinterpret_cast<const char *>(glGetString(GL_RENDERER))
        << std::endl
        << "GLSL version: "
        << reinterpret_cast<const char *>(glGetString(GL_SHADING_LANGUAGE_VERSION))
        << std::endl;

    // GL extensions
    glGetIntegerv(GL_NUM_EXTENSIONS, &this->opengl_num_extensions);
    std::cout
        << "OpenGL extensions available: "
        << this->opengl_num_extensions
        << std::endl;
}

/**
 *  Print known OpenGL extenstions to stdout.
 */
void Machina::list_gl_extensions () {
    for (int i = 0;  i < this->opengl_num_extensions;  i++) {
        std::cout
            << reinterpret_cast<const char *>(glGetStringi(GL_EXTENSIONS, i))
            << std::endl;
    }
}

/**
 *  Run the app.
 */
void Machina::run () {
    this->main_loop->run();
}

} // namespace machina

#endif
<commit_msg>list_gl_extensions text 'header'.<commit_after>/**
 *  machina
 *
 *  Copyright (c) 2014, drmats
 *  All rights reserved.
 *
 *  https://github.com/drmats/machina
 */

#ifndef __MACHINA_CPP_
#define __MACHINA_CPP_ 1

#include "machina.hpp"

namespace machina {

/**
 *  Initialize vital application components.
 */
Machina::Machina (int argc, char **argv):
    command_line_params{argc, argv}
{
    std::cout << "Hi!" << std::endl;

    this->initialize_sdl();
    this->initialize_surface();

    this->main_loop = std::make_shared<MainLoop>(this);
}

/**
 *  Clean-up.
 */
Machina::~Machina () {
    if (this->gl_context != NULL) {
        SDL_GL_DeleteContext(this->gl_context);
        std::cout
            << "Deleted OpenGL context."
            << std::endl;
    }

    if (this->main_window != NULL) {
        SDL_DestroyWindow(this->main_window);
        std::cout
            << "Destroyed surface."
            << std::endl;
    }

    std::cout << "Bye!" << std::endl;
}

/**
 *  Obtain SDL versions, initialize SDL and get video driver name.
 */
void Machina::initialize_sdl () {
    SDL_VERSION(&this->compile_sdl_version);
    std::cout
        << "Compile-time SDL version: "
        << static_cast<int>(this->compile_sdl_version.major) << "."
        << static_cast<int>(this->compile_sdl_version.minor) << "."
        << static_cast<int>(this->compile_sdl_version.patch)
        << std::endl;

    SDL_GetVersion(&this->linked_sdl_version);
    std::cout
        << "Runtime SDL version: "
        << static_cast<int>(this->linked_sdl_version.major) << "."
        << static_cast<int>(this->linked_sdl_version.minor) << "."
        << static_cast<int>(this->linked_sdl_version.patch)
        << std::endl;

    if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS | SDL_INIT_TIMER) == 0) {
        SDL_Delay(this->init_delay);
        std::atexit(SDL_Quit);
    } else {
        std::cerr
            << "Unable to initialize SDL: "
            << SDL_GetError()
            << std::endl;
        std::exit(EXIT_FAILURE);
    }

    this->video_driver_name = SDL_GetCurrentVideoDriver();
    if (this->video_driver_name != NULL) {
        std::cout
            << "Video driver: "
            << this->video_driver_name
            << std::endl;
    } else {
        std::cerr
            << "Failed to obtain the video driver name."
            << std::endl;
    }
}

/**
 *  Initialize viewport/drawing surface.
 */
void Machina::initialize_surface () {
    // main window
    this->main_window = SDL_CreateWindow(
        PROGRAM_NAME.c_str(),
        SDL_WINDOWPOS_CENTERED,
        SDL_WINDOWPOS_CENTERED,
        this->viewport.width, this->viewport.height,
        SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE
    );
    if (this->main_window != NULL) {
        SDL_Delay(this->init_delay);
        std::cout
            << "Initialized surface: "
            << this->viewport.width << "x" << this->viewport.height
            << std::endl;
    } else {
        std::cerr
            << "Unable to initialize surface: "
            << SDL_GetError()
            << std::endl;
        std::exit(EXIT_FAILURE);
    }

    // main GL context
    this->gl_context = SDL_GL_CreateContext(this->main_window);
    if (this->gl_context != NULL) {
        SDL_Delay(this->init_delay);
        std::cout
            << "Created OpenGL context."
            << std::endl;
    } else {
        std::cerr
            << "Unable to create OpenGL context "
            << SDL_GetError()
            << std::endl;
        std::exit(EXIT_FAILURE);
    }

    // GLEW initialization
    glewExperimental = GL_TRUE;
    this->glew_status = glewInit();
    if (this->glew_status == GLEW_OK) {
        SDL_Delay(this->init_delay);
        std::cout
            << "GLEW version: "
            << glewGetString(GLEW_VERSION)
            << std::endl;
    } else {
        std::cerr
            << "Unable to initialize GLEW: "
            << glewGetErrorString(this->glew_status)
            << std::endl;
        std::exit(EXIT_FAILURE);
    }

    // GL version
    glGetIntegerv(GL_MAJOR_VERSION, &this->opengl_major_version);
    glGetIntegerv(GL_MINOR_VERSION, &this->opengl_minor_version);
    this->opengl_version_string =
        reinterpret_cast<const char *>(glGetString(GL_VERSION));
    std::cout
        << "OpenGL version: "
        << this->opengl_major_version << "."
        << this->opengl_minor_version << " "
        << "(" << this->opengl_version_string << ")"
        << std::endl
        << "OpenGL vendor: "
        << reinterpret_cast<const char *>(glGetString(GL_VENDOR))
        << std::endl
        << "OpenGL renderer: "
        << reinterpret_cast<const char *>(glGetString(GL_RENDERER))
        << std::endl
        << "GLSL version: "
        << reinterpret_cast<const char *>(glGetString(GL_SHADING_LANGUAGE_VERSION))
        << std::endl;

    // GL extensions
    glGetIntegerv(GL_NUM_EXTENSIONS, &this->opengl_num_extensions);
    std::cout
        << "OpenGL extensions available: "
        << this->opengl_num_extensions
        << std::endl;
}

/**
 *  Print known OpenGL extenstions to stdout.
 */
void Machina::list_gl_extensions () {
    std::cout
        << "------ available OpenGL extension names ------"
        << std::endl;
    for (int i = 0;  i < this->opengl_num_extensions;  i++) {
        std::cout
            << reinterpret_cast<const char *>(glGetStringi(GL_EXTENSIONS, i))
            << std::endl;
    }
}

/**
 *  Run the app.
 */
void Machina::run () {
    this->main_loop->run();
}

} // namespace machina

#endif
<|endoftext|>


<commit_before>#include <string>
#include "robotDynamicsJRLJapan/Joint.h"
#include "robotDynamicsJRLJapan/HumanoidDynamicMultiBody.h"
#include "robotDynamics/jrlRobotDynamicsObjectConstructor.h"
using namespace std;
using namespace dynamicsJRLJapan;

void RecursiveDisplayOfJoints(CjrlJoint *aJoint)
{
  if (aJoint==0)
    return;

  Joint *a2Joint=0;

  int NbChildren = aJoint->countChildJoints();

  a2Joint = dynamic_cast<Joint *>( aJoint);
  if (a2Joint==0)
    return;

  cout << "Name : " << a2Joint->getName() << endl;
  cout << "Number of child  :" << NbChildren << endl;
  for(int i=0;i<NbChildren;i++)
    {
      a2Joint = (Joint *)&aJoint->childJoint(i);

      cout << " Child " << i << " " <<a2Joint->getName() << endl;
    }

  cout << "Nb of degree of freedom " <<
    aJoint->numberDof() << endl;

  cout << "Initial Position " <<
    aJoint->initialPosition();

  cout << "CurrentTransformation " <<
    aJoint->currentTransformation() << endl;

  cout << " Joint from root to here:" << endl;
  std::vector<CjrlJoint*> JointsFromRootToHere = aJoint->jointsFromRootToThis();

  cout << " Nb of nodes: " << JointsFromRootToHere.size() << endl;
  for(int i=0;i<JointsFromRootToHere.size();i++)
    {
      Joint * a3Joint = dynamic_cast<Joint *>(JointsFromRootToHere[i]);
      if (a3Joint==0)
	continue;

      cout << a3Joint->getName() << endl;

    }
  CjrlRigidVelocity aRV = aJoint->jointVelocity();
  cout << " Linear Velocity " << aRV.linearVelocity() << endl;
  cout << " Angular Velocity " << aRV.rotationVelocity() << endl;
  CjrlRigidAcceleration aRA = aJoint->jointAcceleration();
  cout << " Linear Acceleration " << aRA.linearAcceleration() << endl;
  cout << " Angular Acceleration " << aRA.rotationAcceleration() << endl;

  cout << "***********************************************" << endl;
  cout << " Display Now information related to children :" << endl;
  for(int i=0;i<NbChildren;i++)
    {
      // Returns a const so we have to force the casting/
      RecursiveDisplayOfJoints((CjrlJoint *)&aJoint->childJoint(i));
    }
  cout << " End for Joint: " << a2Joint->getName() << endl;
}

void DisplayDynamicRobotInformation(CjrlDynamicRobot *aDynamicRobot)
{
  std::vector<CjrlJoint *> aVec = aDynamicRobot->jointVector();
  int r = aVec.size();
  cout << "Number of joints :" << r << endl;
  for(int i=0;i<r;i++)
    {
      Joint * aJoint = dynamic_cast<Joint *>(aVec[i]);
      cout << aJoint->getName();
    }

}

void DisplayMatrix(MAL_MATRIX(,double) &aJ)
{
  for(int i=0;i<6;i++)
    {
      for(int j=0;j<MAL_MATRIX_NB_COLS(aJ);j++)
	{
	  if (aJ(i,j)==0.0)
	    printf("0 ");
	  else
	    printf("%10.5f ",aJ(i,j));
	}
      printf("\n");
    }

}

void GoDownTree(const CjrlJoint * startJoint)
{
  std::cout << "joint ranked :" << startJoint->rankInConfiguration() << std::endl;
  std::cout << "Joint name :" << ((Joint *)startJoint)->getName() << std::endl;
  std::cout << "Force on the related Body : " << ((DynamicBody *)(startJoint->linkedBody()))->m_Force << std::endl;
  std::cout << "Torque on the related Body : " << ((DynamicBody *)(startJoint->linkedBody()))->m_Torque << std::endl;
  std::cout << "Mass of the body: " << ((DynamicBody *)(startJoint->linkedBody()))->getMasse() << std::endl;
  std::cout << "Name of the body: " << ((DynamicBody *)(startJoint->linkedBody()))->getName() << std::endl;
  std::cout << startJoint->currentTransformation() << std::endl;

  if (startJoint->countChildJoints()!=0)
    {
      const CjrlJoint * childJoint = &(startJoint->childJoint(0));
      GoDownTree(childJoint);
    }
}

int main(int argc, char *argv[])
{
  if (argc!=4)
    {
      cerr << " This program takes 3 arguments: " << endl;
      cerr << "./TestHumanoidDynamicRobot PATH_TO_VRML_FILE VRML_FILE_NAME PATH_TO_SPECIFICITIES_XML" << endl;
      exit(-1);
    }

  DynamicMultiBody * aDMB=0;
  string aSpecificitiesFileName = argv[3];
  string aPath=argv[1];
  string aName=argv[2];

#if 0
  aDMB = new DynamicMultiBody();
  aDMB->parserVRML(aPath,aName,"");
  HumanoidDynamicMultiBody *aHDMB = new HumanoidDynamicMultiBody(aDMB,aSpecificitiesFileName);
#else
  CjrlRobotDynamicsObjectConstructor<
  dynamicsJRLJapan::DynamicMultiBody,
    dynamicsJRLJapan::HumanoidDynamicMultiBody,
    dynamicsJRLJapan::JointFreeflyer,
    dynamicsJRLJapan::JointRotation,
    dynamicsJRLJapan::JointTranslation,
    dynamicsJRLJapan::Body> aRobotDynamicsObjectConstructor;

  CjrlHumanoidDynamicRobot * aHDR = aRobotDynamicsObjectConstructor.createhumanoidDynamicRobot();

  HumanoidDynamicMultiBody *aHDMB;
  aHDMB = (dynamicsJRLJapan::HumanoidDynamicMultiBody *)aHDR;

  if (aHDMB==0)
    {
      cerr<< "Dynamic cast on HDR failed " << endl;
      exit(-1);
    }
  aDMB = (DynamicMultiBody *) aHDMB->getDynamicMultiBody();
  aDMB->parserVRML(aPath,aName,"");
  aHDMB->SetHumanoidSpecificitiesFile(aSpecificitiesFileName);
#endif

  // Display tree of the joints.
  CjrlJoint* rootJoint = aHDMB->rootJoint();
  bool ok=true;

  // Test the tree.
  //RecursiveDisplayOfJoints(rootJoint);

  // Tes the computation of the jacobian.
  double dInitPos[40] = {
    0.0, 0.0, -26.0, 50.0, -24.0, 0.0, 0.0, 0.0, -26.0, 50.0, -24.0, 0.0,  // legs

    0.0, 0.0, 0.0, 0.0, // chest and head

    15.0, -10.0, 0.0, -30.0, 0.0, 0.0, 10.0, // right arm
    15.0,  10.0, 0.0, -30.0, 0.0, 0.0, 10.0, // left arm

    -20.0, 20.0, -20.0, 20.0, -20.0, // right hand
    -10.0, 10.0, -10.0, 10.0, -10.0  // left hand
  };

  int NbOfDofs = aDMB->numberDof();
  std::cout << "NbOfDofs :" << NbOfDofs <<std::endl;
  MAL_VECTOR_DIM(aCurrentConf,double,NbOfDofs);
  int lindex=0;
  for(int i=0;i<6;i++)
    aCurrentConf[lindex++] = 0.0;

  for(int i=0;i<(NbOfDofs-6 < 40 ? NbOfDofs-6 : 40) ;i++)
    aCurrentConf[lindex++] = dInitPos[i]*M_PI/180.0;
  //aCurrentConf[lindex++] = 0.0;

  aDMB->currentConfiguration(aCurrentConf);

  MAL_VECTOR_DIM(aCurrentVel,double,NbOfDofs);
  lindex=0;
  for(int i=0;i<NbOfDofs;i++)
    aCurrentVel[lindex++] = 0.0;

  aDMB->currentVelocity(aCurrentVel);

  aDMB->computeForwardKinematics();

  aHDMB->LinkBetweenJointsAndEndEffectorSemantic();

  std::vector<CjrlJoint *> aVec = aDMB->jointVector();

  Joint  * aJoint = (Joint *)aVec[22]; // Try to get the hand.

  cout << aJoint->getName() << endl;

  aJoint->computeJacobianJointWrtConfig();

  MAL_MATRIX(,double) aJ = aJoint->jacobianJointWrtConfig();

  //  DisplayMatrix(aJ);

  cout << "Root: " << ((Joint *)rootJoint)->getName() << endl;

  rootJoint->computeJacobianJointWrtConfig();

  aJ = rootJoint->jacobianJointWrtConfig();

  cout << "Rank of Root: " << rootJoint->rankInConfiguration() << endl;

  //  DisplayMatrix(aJ);

  aJoint = (Joint *)aHDMB->waist();

  cout << "Name of the WAIST joint :" << endl;
  cout << aJoint->getName() << endl;

  //  aHDMB->computeJacobianCenterOfMass();
  //  cout << "Value of the CoM's Jacobian:" << endl
  //       << aHDMB->jacobianCenterOfMass() << endl;

  GoDownTree(aDMB->rootJoint());

  cout << "Mass of the robot " << aDMB->getMasse() << endl;
  cout << "Force " << aDMB->getMasse()*9.81 << endl;
  delete aDMB;
  delete aHDMB;

}
<commit_msg>OS: Display the result of footHeight.<commit_after>#include <string>
#include "robotDynamicsJRLJapan/Joint.h"
#include "robotDynamicsJRLJapan/HumanoidDynamicMultiBody.h"
#include "robotDynamics/jrlRobotDynamicsObjectConstructor.h"
using namespace std;
using namespace dynamicsJRLJapan;

void RecursiveDisplayOfJoints(CjrlJoint *aJoint)
{
  if (aJoint==0)
    return;

  Joint *a2Joint=0;

  int NbChildren = aJoint->countChildJoints();

  a2Joint = dynamic_cast<Joint *>( aJoint);
  if (a2Joint==0)
    return;

  cout << a2Joint->getName() << " rank : " << a2Joint->rankInConfiguration() << endl;

#if 0
  cout << "Number of child  :" << NbChildren << endl;
  for(int i=0;i<NbChildren;i++)
    {
      a2Joint = (Joint *)&aJoint->childJoint(i);

      cout << " Child " << i << " " <<a2Joint->getName() << endl;
    }

  cout << "Nb of degree of freedom " <<
    aJoint->numberDof() << endl;

  cout << "Initial Position " <<
    aJoint->initialPosition();

  cout << "CurrentTransformation " <<
    aJoint->currentTransformation() << endl;

  cout << " Joint from root to here:" << endl;
  std::vector<CjrlJoint*> JointsFromRootToHere = aJoint->jointsFromRootToThis();

  cout << " Nb of nodes: " << JointsFromRootToHere.size() << endl;
  for(int i=0;i<JointsFromRootToHere.size();i++)
    {
      Joint * a3Joint = dynamic_cast<Joint *>(JointsFromRootToHere[i]);
      if (a3Joint==0)
	continue;

      cout << a3Joint->getName() << endl;

    }
  CjrlRigidVelocity aRV = aJoint->jointVelocity();
  cout << " Linear Velocity " << aRV.linearVelocity() << endl;
  cout << " Angular Velocity " << aRV.rotationVelocity() << endl;
  CjrlRigidAcceleration aRA = aJoint->jointAcceleration();
  cout << " Linear Acceleration " << aRA.linearAcceleration() << endl;
  cout << " Angular Acceleration " << aRA.rotationAcceleration() << endl;

  cout << "***********************************************" << endl;
  cout << " Display Now information related to children :" << endl;
#endif
  for(int i=0;i<NbChildren;i++)
    {
      // Returns a const so we have to force the casting/
      RecursiveDisplayOfJoints((CjrlJoint *)&aJoint->childJoint(i));
    }
  //cout << " End for Joint: " << a2Joint->getName() << endl;
}

void DisplayDynamicRobotInformation(CjrlDynamicRobot *aDynamicRobot)
{
  std::vector<CjrlJoint *> aVec = aDynamicRobot->jointVector();
  int r = aVec.size();
  cout << "Number of joints :" << r << endl;
  for(int i=0;i<r;i++)
    {
      Joint * aJoint = dynamic_cast<Joint *>(aVec[i]);
      cout << aJoint->getName();
    }

}

void DisplayMatrix(MAL_MATRIX(,double) &aJ)
{
  for(int i=0;i<6;i++)
    {
      for(int j=0;j<MAL_MATRIX_NB_COLS(aJ);j++)
	{
	  if (aJ(i,j)==0.0)
	    printf("0 ");
	  else
	    printf("%10.5f ",aJ(i,j));
	}
      printf("\n");
    }

}

void GoDownTree(const CjrlJoint * startJoint)
{
  std::cout << "joint ranked :" << startJoint->rankInConfiguration() << std::endl;
  std::cout << "Joint name :" << ((Joint *)startJoint)->getName() << std::endl;
  std::cout << "Force on the related Body : " << ((DynamicBody *)(startJoint->linkedBody()))->m_Force << std::endl;
  std::cout << "Torque on the related Body : " << ((DynamicBody *)(startJoint->linkedBody()))->m_Torque << std::endl;
  std::cout << "Mass of the body: " << ((DynamicBody *)(startJoint->linkedBody()))->getMasse() << std::endl;
  std::cout << "Name of the body: " << ((DynamicBody *)(startJoint->linkedBody()))->getName() << std::endl;

  std::cout << startJoint->currentTransformation() << std::endl;

  if (startJoint->countChildJoints()!=0)
    {
      const CjrlJoint * childJoint = &(startJoint->childJoint(0));
      GoDownTree(childJoint);
    }
}

int main(int argc, char *argv[])
{
  if (argc!=4)
    {
      cerr << " This program takes 3 arguments: " << endl;
      cerr << "./TestHumanoidDynamicRobot PATH_TO_VRML_FILE VRML_FILE_NAME PATH_TO_SPECIFICITIES_XML" << endl;
      exit(-1);
    }

  DynamicMultiBody * aDMB=0;
  string aSpecificitiesFileName = argv[3];
  string aPath=argv[1];
  string aName=argv[2];

#if 0
  aDMB = new DynamicMultiBody();
  aDMB->parserVRML(aPath,aName,"");
  HumanoidDynamicMultiBody *aHDMB = new HumanoidDynamicMultiBody(aDMB,aSpecificitiesFileName);
#else
  CjrlRobotDynamicsObjectConstructor<
  dynamicsJRLJapan::DynamicMultiBody,
    dynamicsJRLJapan::HumanoidDynamicMultiBody,
    dynamicsJRLJapan::JointFreeflyer,
    dynamicsJRLJapan::JointRotation,
    dynamicsJRLJapan::JointTranslation,
    dynamicsJRLJapan::Body> aRobotDynamicsObjectConstructor;

  CjrlHumanoidDynamicRobot * aHDR = aRobotDynamicsObjectConstructor.createhumanoidDynamicRobot();

  HumanoidDynamicMultiBody *aHDMB;
  aHDMB = (dynamicsJRLJapan::HumanoidDynamicMultiBody *)aHDR;

  if (aHDMB==0)
    {
      cerr<< "Dynamic cast on HDR failed " << endl;
      exit(-1);
    }
  aDMB = (DynamicMultiBody *) aHDMB->getDynamicMultiBody();
  aDMB->parserVRML(aPath,aName,
		   "/home/stasse/src/OpenHRP/JRL/src/PatternGeneratorJRL/src/data/HRP2LinkJointRank.xml");
  cout << "Here in between" << endl;
  aHDMB->SetHumanoidSpecificitiesFile(aSpecificitiesFileName);
  cout << " Finished the initialization"<< endl;
#endif

  // Display tree of the joints.
  CjrlJoint* rootJoint = aHDMB->rootJoint();
  bool ok=true;

  // Test the tree.
  RecursiveDisplayOfJoints(rootJoint);

  // Tes the computation of the jacobian.
  double dInitPos[40] = {
    0.0, 0.0, -26.0, 50.0, -24.0, 0.0, 0.0, 0.0, -26.0, 50.0, -24.0, 0.0,  // legs

    0.0, 0.0, 0.0, 0.0, // chest and head

    15.0, -10.0, 0.0, -30.0, 0.0, 0.0, 10.0, // right arm
    15.0,  10.0, 0.0, -30.0, 0.0, 0.0, 10.0, // left arm

    -20.0, 20.0, -20.0, 20.0, -20.0, // right hand
    -10.0, 10.0, -10.0, 10.0, -10.0  // left hand
  };

  int NbOfDofs = aDMB->numberDof();
  std::cout << "NbOfDofs :" << NbOfDofs << std::endl;
  MAL_VECTOR_DIM(aCurrentConf,double,NbOfDofs);
  int lindex=0;
  for(int i=0;i<6;i++)
    aCurrentConf[lindex++] = 0.0;

  for(int i=0;i<(NbOfDofs-6 < 40 ? NbOfDofs-6 : 40) ;i++)
    aCurrentConf[lindex++] = dInitPos[i]*M_PI/180.0;
  //aCurrentConf[lindex++] = 0.0;

  aDMB->currentConfiguration(aCurrentConf);

  MAL_VECTOR_DIM(aCurrentVel,double,NbOfDofs);
  lindex=0;
  for(int i=0;i<NbOfDofs;i++)
    aCurrentVel[lindex++] = 0.0;

  aDMB->currentVelocity(aCurrentVel);
  aDMB->computeForwardKinematics();

  aHDMB->LinkBetweenJointsAndEndEffectorSemantic();

  std::vector<CjrlJoint *> aVec = aDMB->jointVector();

  Joint  * aJoint = (Joint *)aVec[22]; // Try to get the hand.
  cout << aJoint->getName() << endl;
  aJoint->computeJacobianJointWrtConfig();

  MAL_MATRIX(,double) aJ = aJoint->jacobianJointWrtConfig();

  //  DisplayMatrix(aJ);
  cout << "****************************" << endl;
  cout << "Root: " << ((Joint *)rootJoint)->getName() << endl;
  rootJoint->computeJacobianJointWrtConfig();
  aJ = rootJoint->jacobianJointWrtConfig();
  cout << "Rank of Root: " << rootJoint->rankInConfiguration() << endl;

  //  DisplayMatrix(aJ);

  aJoint = (Joint *)aHDMB->waist();
  cout << "Name of the WAIST joint :" << endl;
  cout << aJoint->getName() << endl;
  cout << "****************************" << endl;
  aHDMB->computeJacobianCenterOfMass();
  cout << "Value of the CoM's Jacobian:" << endl
       << aHDMB->jacobianCenterOfMass() << endl;
  cout << "****************************" << endl;
  GoDownTree(aDMB->rootJoint());

  cout << "Mass of the robot " << aDMB->getMasse() << endl;
  cout << "Force " << aDMB->getMasse()*9.81 << endl;

  cout << "****************************" << endl;
  // Test rank of the left hand.
  cout << "Rank of the left hand "<< endl;
  cout << aHDMB->leftHand()->rankInConfiguration() << endl;
  cout << ((Joint *)aHDMB->leftHand())->getName() << endl;
  cout << ((Joint *)aHDMB->leftHand())->getIDinVRML() << endl;

  // Height of the foot.
  cout << "Height foot: "<< aHDMB->footHeight() << endl;
  delete aDMB;
  delete aHDMB;

}
<|endoftext|>


<commit_before>// This file is part of Eigen, a lightweight C++ template library
// for linear algebra.
//
// Copyright (C) 2015 Eugene Brevdo <ebrevdo@google.com>
//                    Benoit Steiner <benoit.steiner.goog@gmail.com>
//
// This Source Code Form is subject to the terms of the Mozilla
// Public License v. 2.0. If a copy of the MPL was not distributed
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.

#include "main.h"

#include <Eigen/CXX11/Tensor>

using Eigen::Tensor;
using Eigen::array;
using Eigen::Tuple;

template <int DataLayout>
static void test_simple_index_tuples()
{
  Tensor<float, 4, DataLayout> tensor(2,3,5,7);
  tensor.setRandom();
  tensor = (tensor + tensor.constant(0.5)).log();

  Tensor<Tuple<DenseIndex, float>, 4, DataLayout> index_tuples(2,3,5,7);
  index_tuples = tensor.index_tuples();

  for (DenseIndex n = 0; n < 2*3*5*7; ++n) {
    const Tuple<DenseIndex, float>& v = index_tuples.coeff(n);
    VERIFY_IS_EQUAL(v.first, n);
    VERIFY_IS_EQUAL(v.second, tensor.coeff(n));
  }
}

template <int DataLayout>
static void test_index_tuples_dim()
{
  Tensor<float, 4, DataLayout> tensor(2,3,5,7);
  tensor.setRandom();
  tensor = (tensor + tensor.constant(0.5)).log();

  Tensor<Tuple<DenseIndex, float>, 4, DataLayout> index_tuples(2,3,5,7);

  index_tuples = tensor.index_tuples();

  for (Eigen::DenseIndex n = 0; n < tensor.size(); ++n) {
    const Tuple<DenseIndex, float>& v = index_tuples(n); //(i, j, k, l);
    VERIFY_IS_EQUAL(v.first, n);
    VERIFY_IS_EQUAL(v.second, tensor(n));
  }
}

template <int DataLayout>
static void test_argmax_tuple_reducer()
{
  Tensor<float, 4, DataLayout> tensor(2,3,5,7);
  tensor.setRandom();
  tensor = (tensor + tensor.constant(0.5)).log();

  Tensor<Tuple<DenseIndex, float>, 4, DataLayout> index_tuples(2,3,5,7);
  index_tuples = tensor.index_tuples();

  Tensor<Tuple<DenseIndex, float>, 1, DataLayout> reduced(1);
  DimensionList<DenseIndex, 4> dims;
  reduced = index_tuples.reduce(
      dims, internal::ArgMaxTupleReducer<Tuple<DenseIndex, float>>());

  Tensor<float, 1, DataLayout> maxi = tensor.maximum();

  VERIFY_IS_EQUAL(maxi(0), reduced(0).second);

  array<DenseIndex, 3> reduce_dims;
  for (int d = 0; d < 3; ++d) reduce_dims[d] = d;
  Tensor<Tuple<DenseIndex, float>, 1, DataLayout> reduced_by_dims(7);
  reduced_by_dims = index_tuples.reduce(
      reduce_dims, internal::ArgMaxTupleReducer<Tuple<DenseIndex, float>>());

  Tensor<float, 1, DataLayout> max_by_dims = tensor.maximum(reduce_dims);

  for (int l = 0; l < 7; ++l) {
    VERIFY_IS_EQUAL(max_by_dims(l), reduced_by_dims(l).second);
  }
}

template <int DataLayout>
static void test_argmin_tuple_reducer()
{
  Tensor<float, 4, DataLayout> tensor(2,3,5,7);
  tensor.setRandom();
  tensor = (tensor + tensor.constant(0.5)).log();

  Tensor<Tuple<DenseIndex, float>, 4, DataLayout> index_tuples(2,3,5,7);
  index_tuples = tensor.index_tuples();

  Tensor<Tuple<DenseIndex, float>, 1, DataLayout> reduced(1);
  DimensionList<DenseIndex, 4> dims;
  reduced = index_tuples.reduce(
      dims, internal::ArgMinTupleReducer<Tuple<DenseIndex, float>>());

  Tensor<float, 1, DataLayout> mini = tensor.minimum();

  VERIFY_IS_EQUAL(mini(0), reduced(0).second);

  array<DenseIndex, 3> reduce_dims;
  for (int d = 0; d < 3; ++d) reduce_dims[d] = d;
  Tensor<Tuple<DenseIndex, float>, 1, DataLayout> reduced_by_dims(7);
  reduced_by_dims = index_tuples.reduce(
      reduce_dims, internal::ArgMinTupleReducer<Tuple<DenseIndex, float>>());

  Tensor<float, 1, DataLayout> min_by_dims = tensor.minimum(reduce_dims);

  for (int l = 0; l < 7; ++l) {
    VERIFY_IS_EQUAL(min_by_dims(l), reduced_by_dims(l).second);
  }
}

template <int DataLayout>
static void test_simple_argmax()
{
  Tensor<float, 4, DataLayout> tensor(2,3,5,7);
  tensor.setRandom();
  tensor = (tensor + tensor.constant(0.5)).log();
  tensor(0,0,0,0) = 10.0;

  Tensor<DenseIndex, 1, DataLayout> tensor_argmax(1);

  tensor_argmax = tensor.argmax();

  VERIFY_IS_EQUAL(tensor_argmax(0), 0);

  tensor(1,2,4,6) = 20.0;

  tensor_argmax = tensor.argmax();

  VERIFY_IS_EQUAL(tensor_argmax(0), 2*3*5*7 - 1);
}

template <int DataLayout>
static void test_simple_argmin()
{
  Tensor<float, 4, DataLayout> tensor(2,3,5,7);
  tensor.setRandom();
  tensor = (tensor + tensor.constant(0.5)).log();
  tensor(0,0,0,0) = -10.0;

  Tensor<DenseIndex, 1, DataLayout> tensor_argmin(1);

  tensor_argmin = tensor.argmin();

  VERIFY_IS_EQUAL(tensor_argmin(0), 0);

  tensor(1,2,4,6) = -20.0;

  tensor_argmin = tensor.argmin();

  VERIFY_IS_EQUAL(tensor_argmin(0), 2*3*5*7 - 1);
}

template <int DataLayout>
static void test_argmax_dim()
{
  Tensor<float, 4, DataLayout> tensor(2,3,5,7);
  std::vector<int> dims {2, 3, 5, 7};

  for (int dim = 0; dim < 4; ++dim) {
    tensor.setRandom();
    tensor = (tensor + tensor.constant(0.5)).log();

    Tensor<DenseIndex, 3, DataLayout> tensor_argmax;
    array<DenseIndex, 4> ix;
    for (int i = 0; i < 2; ++i) {
      for (int j = 0; j < 3; ++j) {
        for (int k = 0; k < 5; ++k) {
          for (int l = 0; l < 7; ++l) {
            ix[0] = i; ix[1] = j; ix[2] = k; ix[3] = l;
            if (ix[dim] != 0) continue;
            // suppose dim == 1, then for all i, k, l, set tensor(i, 0, k, l) = 10.0
            tensor(ix) = 10.0;
          }
        }
      }
    }

    tensor_argmax = tensor.argmax(dim);

    VERIFY_IS_EQUAL(tensor_argmax.dimensions().TotalSize(),
                    size_t(2*3*5*7 / tensor.dimension(dim)));
    for (ptrdiff_t n = 0; n < tensor_argmax.size(); ++n) {
      // Expect max to be in the first index of the reduced dimension
      VERIFY_IS_EQUAL(tensor_argmax.data()[n], 0);
    }

    for (int i = 0; i < 2; ++i) {
      for (int j = 0; j < 3; ++j) {
        for (int k = 0; k < 5; ++k) {
          for (int l = 0; l < 7; ++l) {
            ix[0] = i; ix[1] = j; ix[2] = k; ix[3] = l;
            if (ix[dim] != tensor.dimension(dim) - 1) continue;
            // suppose dim == 1, then for all i, k, l, set tensor(i, 2, k, l) = 20.0
            tensor(ix) = 20.0;
          }
        }
      }
    }

    tensor_argmax = tensor.argmax(dim);

    VERIFY_IS_EQUAL(tensor_argmax.size(),
                    ptrdiff_t(2*3*5*7 / tensor.dimension(dim)));
    for (size_t n = 0; n < tensor_argmax.dimensions().TotalSize(); ++n) {
      // Expect max to be in the last index of the reduced dimension
      VERIFY_IS_EQUAL(tensor_argmax.data()[n], tensor.dimension(dim) - 1);
    }
  }
}

template <int DataLayout>
static void test_argmin_dim()
{
  Tensor<float, 4, DataLayout> tensor(2,3,5,7);
  std::vector<int> dims {2, 3, 5, 7};

  for (int dim = 0; dim < 4; ++dim) {
    tensor.setRandom();
    tensor = (tensor + tensor.constant(0.5)).log();

    Tensor<DenseIndex, 3, DataLayout> tensor_argmin;
    array<DenseIndex, 4> ix;
    for (int i = 0; i < 2; ++i) {
      for (int j = 0; j < 3; ++j) {
        for (int k = 0; k < 5; ++k) {
          for (int l = 0; l < 7; ++l) {
            ix[0] = i; ix[1] = j; ix[2] = k; ix[3] = l;
            if (ix[dim] != 0) continue;
            // suppose dim == 1, then for all i, k, l, set tensor(i, 0, k, l) = -10.0
            tensor(ix) = -10.0;
          }
        }
      }
    }

    tensor_argmin = tensor.argmin(dim);

    VERIFY_IS_EQUAL(tensor_argmin.dimensions().TotalSize(),
                    size_t(2*3*5*7 / tensor.dimension(dim)));
    for (ptrdiff_t n = 0; n < tensor_argmin.size(); ++n) {
      // Expect min to be in the first index of the reduced dimension
      VERIFY_IS_EQUAL(tensor_argmin.data()[n], 0);
    }

    for (int i = 0; i < 2; ++i) {
      for (int j = 0; j < 3; ++j) {
        for (int k = 0; k < 5; ++k) {
          for (int l = 0; l < 7; ++l) {
            ix[0] = i; ix[1] = j; ix[2] = k; ix[3] = l;
            if (ix[dim] != tensor.dimension(dim) - 1) continue;
            // suppose dim == 1, then for all i, k, l, set tensor(i, 2, k, l) = -20.0
            tensor(ix) = -20.0;
          }
        }
      }
    }

    tensor_argmin = tensor.argmin(dim);

    VERIFY_IS_EQUAL(tensor_argmin.size(),
                    ptrdiff_t(2*3*5*7 / tensor.dimension(dim)));
    for (size_t n = 0; n < tensor_argmin.dimensions().TotalSize(); ++n) {
      // Expect min to be in the last index of the reduced dimension
      VERIFY_IS_EQUAL(tensor_argmin.data()[n], tensor.dimension(dim) - 1);
    }
  }
}

void test_cxx11_tensor_argmax()
{
  CALL_SUBTEST(test_simple_index_tuples<RowMajor>());
  CALL_SUBTEST(test_simple_index_tuples<ColMajor>());
  CALL_SUBTEST(test_index_tuples_dim<RowMajor>());
  CALL_SUBTEST(test_index_tuples_dim<ColMajor>());
  CALL_SUBTEST(test_argmax_tuple_reducer<RowMajor>());
  CALL_SUBTEST(test_argmax_tuple_reducer<ColMajor>());
  CALL_SUBTEST(test_argmin_tuple_reducer<RowMajor>());
  CALL_SUBTEST(test_argmin_tuple_reducer<ColMajor>());
  CALL_SUBTEST(test_simple_argmax<RowMajor>());
  CALL_SUBTEST(test_simple_argmax<ColMajor>());
  CALL_SUBTEST(test_simple_argmin<RowMajor>());
  CALL_SUBTEST(test_simple_argmin<ColMajor>());
  CALL_SUBTEST(test_argmax_dim<RowMajor>());
  CALL_SUBTEST(test_argmax_dim<ColMajor>());
  CALL_SUBTEST(test_argmin_dim<RowMajor>());
  CALL_SUBTEST(test_argmin_dim<ColMajor>());
}
<commit_msg>Fixed compilation warning<commit_after>// This file is part of Eigen, a lightweight C++ template library
// for linear algebra.
//
// Copyright (C) 2015 Eugene Brevdo <ebrevdo@google.com>
//                    Benoit Steiner <benoit.steiner.goog@gmail.com>
//
// This Source Code Form is subject to the terms of the Mozilla
// Public License v. 2.0. If a copy of the MPL was not distributed
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.

#include "main.h"

#include <Eigen/CXX11/Tensor>

using Eigen::Tensor;
using Eigen::array;
using Eigen::Tuple;

template <int DataLayout>
static void test_simple_index_tuples()
{
  Tensor<float, 4, DataLayout> tensor(2,3,5,7);
  tensor.setRandom();
  tensor = (tensor + tensor.constant(0.5)).log();

  Tensor<Tuple<DenseIndex, float>, 4, DataLayout> index_tuples(2,3,5,7);
  index_tuples = tensor.index_tuples();

  for (DenseIndex n = 0; n < 2*3*5*7; ++n) {
    const Tuple<DenseIndex, float>& v = index_tuples.coeff(n);
    VERIFY_IS_EQUAL(v.first, n);
    VERIFY_IS_EQUAL(v.second, tensor.coeff(n));
  }
}

template <int DataLayout>
static void test_index_tuples_dim()
{
  Tensor<float, 4, DataLayout> tensor(2,3,5,7);
  tensor.setRandom();
  tensor = (tensor + tensor.constant(0.5)).log();

  Tensor<Tuple<DenseIndex, float>, 4, DataLayout> index_tuples(2,3,5,7);

  index_tuples = tensor.index_tuples();

  for (Eigen::DenseIndex n = 0; n < tensor.size(); ++n) {
    const Tuple<DenseIndex, float>& v = index_tuples(n); //(i, j, k, l);
    VERIFY_IS_EQUAL(v.first, n);
    VERIFY_IS_EQUAL(v.second, tensor(n));
  }
}

template <int DataLayout>
static void test_argmax_tuple_reducer()
{
  Tensor<float, 4, DataLayout> tensor(2,3,5,7);
  tensor.setRandom();
  tensor = (tensor + tensor.constant(0.5)).log();

  Tensor<Tuple<DenseIndex, float>, 4, DataLayout> index_tuples(2,3,5,7);
  index_tuples = tensor.index_tuples();

  Tensor<Tuple<DenseIndex, float>, 1, DataLayout> reduced(1);
  DimensionList<DenseIndex, 4> dims;
  reduced = index_tuples.reduce(
      dims, internal::ArgMaxTupleReducer<Tuple<DenseIndex, float>>());

  Tensor<float, 1, DataLayout> maxi = tensor.maximum();

  VERIFY_IS_EQUAL(maxi(0), reduced(0).second);

  array<DenseIndex, 3> reduce_dims;
  for (int d = 0; d < 3; ++d) reduce_dims[d] = d;
  Tensor<Tuple<DenseIndex, float>, 1, DataLayout> reduced_by_dims(7);
  reduced_by_dims = index_tuples.reduce(
      reduce_dims, internal::ArgMaxTupleReducer<Tuple<DenseIndex, float>>());

  Tensor<float, 1, DataLayout> max_by_dims = tensor.maximum(reduce_dims);

  for (int l = 0; l < 7; ++l) {
    VERIFY_IS_EQUAL(max_by_dims(l), reduced_by_dims(l).second);
  }
}

template <int DataLayout>
static void test_argmin_tuple_reducer()
{
  Tensor<float, 4, DataLayout> tensor(2,3,5,7);
  tensor.setRandom();
  tensor = (tensor + tensor.constant(0.5)).log();

  Tensor<Tuple<DenseIndex, float>, 4, DataLayout> index_tuples(2,3,5,7);
  index_tuples = tensor.index_tuples();

  Tensor<Tuple<DenseIndex, float>, 1, DataLayout> reduced(1);
  DimensionList<DenseIndex, 4> dims;
  reduced = index_tuples.reduce(
      dims, internal::ArgMinTupleReducer<Tuple<DenseIndex, float>>());

  Tensor<float, 1, DataLayout> mini = tensor.minimum();

  VERIFY_IS_EQUAL(mini(0), reduced(0).second);

  array<DenseIndex, 3> reduce_dims;
  for (int d = 0; d < 3; ++d) reduce_dims[d] = d;
  Tensor<Tuple<DenseIndex, float>, 1, DataLayout> reduced_by_dims(7);
  reduced_by_dims = index_tuples.reduce(
      reduce_dims, internal::ArgMinTupleReducer<Tuple<DenseIndex, float>>());

  Tensor<float, 1, DataLayout> min_by_dims = tensor.minimum(reduce_dims);

  for (int l = 0; l < 7; ++l) {
    VERIFY_IS_EQUAL(min_by_dims(l), reduced_by_dims(l).second);
  }
}

template <int DataLayout>
static void test_simple_argmax()
{
  Tensor<float, 4, DataLayout> tensor(2,3,5,7);
  tensor.setRandom();
  tensor = (tensor + tensor.constant(0.5)).log();
  tensor(0,0,0,0) = 10.0;

  Tensor<DenseIndex, 1, DataLayout> tensor_argmax(1);

  tensor_argmax = tensor.argmax();

  VERIFY_IS_EQUAL(tensor_argmax(0), 0);

  tensor(1,2,4,6) = 20.0;

  tensor_argmax = tensor.argmax();

  VERIFY_IS_EQUAL(tensor_argmax(0), 2*3*5*7 - 1);
}

template <int DataLayout>
static void test_simple_argmin()
{
  Tensor<float, 4, DataLayout> tensor(2,3,5,7);
  tensor.setRandom();
  tensor = (tensor + tensor.constant(0.5)).log();
  tensor(0,0,0,0) = -10.0;

  Tensor<DenseIndex, 1, DataLayout> tensor_argmin(1);

  tensor_argmin = tensor.argmin();

  VERIFY_IS_EQUAL(tensor_argmin(0), 0);

  tensor(1,2,4,6) = -20.0;

  tensor_argmin = tensor.argmin();

  VERIFY_IS_EQUAL(tensor_argmin(0), 2*3*5*7 - 1);
}

template <int DataLayout>
static void test_argmax_dim()
{
  Tensor<float, 4, DataLayout> tensor(2,3,5,7);
  std::vector<int> dims {2, 3, 5, 7};

  for (int dim = 0; dim < 4; ++dim) {
    tensor.setRandom();
    tensor = (tensor + tensor.constant(0.5)).log();

    Tensor<DenseIndex, 3, DataLayout> tensor_argmax;
    array<DenseIndex, 4> ix;
    for (int i = 0; i < 2; ++i) {
      for (int j = 0; j < 3; ++j) {
        for (int k = 0; k < 5; ++k) {
          for (int l = 0; l < 7; ++l) {
            ix[0] = i; ix[1] = j; ix[2] = k; ix[3] = l;
            if (ix[dim] != 0) continue;
            // suppose dim == 1, then for all i, k, l, set tensor(i, 0, k, l) = 10.0
            tensor(ix) = 10.0;
          }
        }
      }
    }

    tensor_argmax = tensor.argmax(dim);

    VERIFY_IS_EQUAL(tensor_argmax.dimensions().TotalSize(),
                    size_t(2*3*5*7 / tensor.dimension(dim)));
    for (ptrdiff_t n = 0; n < tensor_argmax.size(); ++n) {
      // Expect max to be in the first index of the reduced dimension
      VERIFY_IS_EQUAL(tensor_argmax.data()[n], 0);
    }

    for (int i = 0; i < 2; ++i) {
      for (int j = 0; j < 3; ++j) {
        for (int k = 0; k < 5; ++k) {
          for (int l = 0; l < 7; ++l) {
            ix[0] = i; ix[1] = j; ix[2] = k; ix[3] = l;
            if (ix[dim] != tensor.dimension(dim) - 1) continue;
            // suppose dim == 1, then for all i, k, l, set tensor(i, 2, k, l) = 20.0
            tensor(ix) = 20.0;
          }
        }
      }
    }

    tensor_argmax = tensor.argmax(dim);

    VERIFY_IS_EQUAL(tensor_argmax.size(),
                    ptrdiff_t(2*3*5*7 / tensor.dimension(dim)));
    for (ptrdiff_t n = 0; n < tensor_argmax.dimensions().TotalSize(); ++n) {
      // Expect max to be in the last index of the reduced dimension
      VERIFY_IS_EQUAL(tensor_argmax.data()[n], tensor.dimension(dim) - 1);
    }
  }
}

template <int DataLayout>
static void test_argmin_dim()
{
  Tensor<float, 4, DataLayout> tensor(2,3,5,7);
  std::vector<int> dims {2, 3, 5, 7};

  for (int dim = 0; dim < 4; ++dim) {
    tensor.setRandom();
    tensor = (tensor + tensor.constant(0.5)).log();

    Tensor<DenseIndex, 3, DataLayout> tensor_argmin;
    array<DenseIndex, 4> ix;
    for (int i = 0; i < 2; ++i) {
      for (int j = 0; j < 3; ++j) {
        for (int k = 0; k < 5; ++k) {
          for (int l = 0; l < 7; ++l) {
            ix[0] = i; ix[1] = j; ix[2] = k; ix[3] = l;
            if (ix[dim] != 0) continue;
            // suppose dim == 1, then for all i, k, l, set tensor(i, 0, k, l) = -10.0
            tensor(ix) = -10.0;
          }
        }
      }
    }

    tensor_argmin = tensor.argmin(dim);

    VERIFY_IS_EQUAL(tensor_argmin.dimensions().TotalSize(),
                    size_t(2*3*5*7 / tensor.dimension(dim)));
    for (ptrdiff_t n = 0; n < tensor_argmin.size(); ++n) {
      // Expect min to be in the first index of the reduced dimension
      VERIFY_IS_EQUAL(tensor_argmin.data()[n], 0);
    }

    for (int i = 0; i < 2; ++i) {
      for (int j = 0; j < 3; ++j) {
        for (int k = 0; k < 5; ++k) {
          for (int l = 0; l < 7; ++l) {
            ix[0] = i; ix[1] = j; ix[2] = k; ix[3] = l;
            if (ix[dim] != tensor.dimension(dim) - 1) continue;
            // suppose dim == 1, then for all i, k, l, set tensor(i, 2, k, l) = -20.0
            tensor(ix) = -20.0;
          }
        }
      }
    }

    tensor_argmin = tensor.argmin(dim);

    VERIFY_IS_EQUAL(tensor_argmin.size(),
                    ptrdiff_t(2*3*5*7 / tensor.dimension(dim)));
    for (ptrdiff_t n = 0; n < tensor_argmin.dimensions().TotalSize(); ++n) {
      // Expect min to be in the last index of the reduced dimension
      VERIFY_IS_EQUAL(tensor_argmin.data()[n], tensor.dimension(dim) - 1);
    }
  }
}

void test_cxx11_tensor_argmax()
{
  CALL_SUBTEST(test_simple_index_tuples<RowMajor>());
  CALL_SUBTEST(test_simple_index_tuples<ColMajor>());
  CALL_SUBTEST(test_index_tuples_dim<RowMajor>());
  CALL_SUBTEST(test_index_tuples_dim<ColMajor>());
  CALL_SUBTEST(test_argmax_tuple_reducer<RowMajor>());
  CALL_SUBTEST(test_argmax_tuple_reducer<ColMajor>());
  CALL_SUBTEST(test_argmin_tuple_reducer<RowMajor>());
  CALL_SUBTEST(test_argmin_tuple_reducer<ColMajor>());
  CALL_SUBTEST(test_simple_argmax<RowMajor>());
  CALL_SUBTEST(test_simple_argmax<ColMajor>());
  CALL_SUBTEST(test_simple_argmin<RowMajor>());
  CALL_SUBTEST(test_simple_argmin<ColMajor>());
  CALL_SUBTEST(test_argmax_dim<RowMajor>());
  CALL_SUBTEST(test_argmax_dim<ColMajor>());
  CALL_SUBTEST(test_argmin_dim<RowMajor>());
  CALL_SUBTEST(test_argmin_dim<ColMajor>());
}
<|endoftext|>


<commit_before>/*
 *  Copyright 2010-2011 Anders Wallin (anders.e.e.wallin "at" gmail.com)
 *
 *  This file is part of OpenVoronoi.
 *
 *  OpenVoronoi is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  OpenVoronoi 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 General Public License
 *  along with OpenVoronoi.  If not, see <http://www.gnu.org/licenses/>.
*/

#include "numeric.hpp"

#include <qd/qd_real.h>
#include <cmath>
#include <cassert>

namespace ovd {

namespace numeric {

    /*
    double chop8(double a) {
        double eps = 1e-8;
        if (fabs(a) < eps)
            return 0.0;
        else
            return a;
    }*/
    double chop(double val, double tol) {
        double _epsilon = tol;
        if (fabs(val) < _epsilon)
            return 0;
        else
            return val;
    }

    double chop(double val) {
        double _epsilon = 1e-10;
        if (fabs(val) < _epsilon)
            return 0;
        else
            return val;
    }
    qd_real chop(qd_real val) {
        qd_real _epsilon = 1e-10;
        if (fabs(val) < _epsilon)
            return qd_real(0);
        else
            return val;
    }

    double diangle(double x, double y) {
        if (y >= 0)
            return (x >= 0 ? y/(x+y) : 1-x/(-x+y));
        else
            return (x < 0 ? 2-y/(-x-y) : 3+x/(x-y));
    }
    double diangle_x(double a) {
        return (a < 2 ? 1-a : a-3);
    }
    double diangle_y(double a) {
        return (a < 3 ? ((a > 1) ? 2-a : a) : a-4);
    }

    std::pair<double,double> diangle_xy(double a) {
        double x = diangle_x(a);
        double y = diangle_y(a);
        double norm = sqrt(x*x+y*y);
        return std::make_pair(x/norm,y/norm);
    }
    // return true if a lies in [less,more]
    bool diangle_bracket(double less, double a, double more) {
        if (less==more) {
            return false;
        }else if (less<=more) { // normal case..
            if ( (less<=a) && (a<more) )
                return true;
        } else if (less>more) { // we cross zero
            if ( ((less<=a) && (a<=4)) || ((0<=a) && (a<more)) )
                return true;
        } else {
            assert(0);
            return false;
        }

        return false;
    }
    // return average of input angles
    double diangle_mid(double alfa1, double alfa2) {
        if (alfa1<=alfa2)
            return (alfa1+alfa2)/2;
        else {
            double opposite_mid = alfa2 + (alfa1-alfa2)/2;
            double mid = opposite_mid + 2;
            if (mid>4)
                mid=mid-4;
            assert( (0<=mid) && (mid<=4) );
            return mid;
        }
    }
} // numeric
} // ovd

<commit_msg>Decrease epsilon in quad-float chop method.<commit_after>/*
 *  Copyright 2010-2011 Anders Wallin (anders.e.e.wallin "at" gmail.com)
 *
 *  This file is part of OpenVoronoi.
 *
 *  OpenVoronoi is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  OpenVoronoi 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 General Public License
 *  along with OpenVoronoi.  If not, see <http://www.gnu.org/licenses/>.
*/

#include "numeric.hpp"

#include <qd/qd_real.h>
#include <cmath>
#include <cassert>

namespace ovd {

namespace numeric {

    /*
    double chop8(double a) {
        double eps = 1e-8;
        if (fabs(a) < eps)
            return 0.0;
        else
            return a;
    }*/
    double chop(double val, double tol) {
        double _epsilon = tol;
        if (fabs(val) < _epsilon)
            return 0;
        else
            return val;
    }

    double chop(double val) {
        double _epsilon = 1e-10;
        if (fabs(val) < _epsilon)
            return 0;
        else
            return val;
    }
    qd_real chop(qd_real val) {
        qd_real _epsilon = 1e-20; // should leave 47bits of precision
        if (fabs(val) < _epsilon)
            return qd_real(0);
        else
            return val;
    }

    double diangle(double x, double y) {
        if (y >= 0)
            return (x >= 0 ? y/(x+y) : 1-x/(-x+y));
        else
            return (x < 0 ? 2-y/(-x-y) : 3+x/(x-y));
    }
    double diangle_x(double a) {
        return (a < 2 ? 1-a : a-3);
    }
    double diangle_y(double a) {
        return (a < 3 ? ((a > 1) ? 2-a : a) : a-4);
    }

    std::pair<double,double> diangle_xy(double a) {
        double x = diangle_x(a);
        double y = diangle_y(a);
        double norm = sqrt(x*x+y*y);
        return std::make_pair(x/norm,y/norm);
    }
    // return true if a lies in [less,more]
    bool diangle_bracket(double less, double a, double more) {
        if (less==more) {
            return false;
        }else if (less<=more) { // normal case..
            if ( (less<=a) && (a<more) )
                return true;
        } else if (less>more) { // we cross zero
            if ( ((less<=a) && (a<=4)) || ((0<=a) && (a<more)) )
                return true;
        } else {
            assert(0);
            return false;
        }

        return false;
    }
    // return average of input angles
    double diangle_mid(double alfa1, double alfa2) {
        if (alfa1<=alfa2)
            return (alfa1+alfa2)/2;
        else {
            double opposite_mid = alfa2 + (alfa1-alfa2)/2;
            double mid = opposite_mid + 2;
            if (mid>4)
                mid=mid-4;
            assert( (0<=mid) && (mid<=4) );
            return mid;
        }
    }
} // numeric
} // ovd

<|endoftext|>


<commit_before>#include "fisx_simpleini.h"
#include <iostream>
#include <fstream>
#include <stdexcept>
#include <stdlib.h>

SimpleIni::SimpleIni()
{
    this->fileName = "";
    this->sections.clear();
    this->sectionPositions.clear();
}

SimpleIni::SimpleIni(std::string fileName)
{
    this->readFileName(fileName);
}

void SimpleIni::readFileName(std::string fileName)
{
    std::string mainKey;
    std::string key;
    std::string line;
    std::string trimmedLine;
    std::string tmpString;
    std::string content;
    std::string::size_type i;
    // I should use streampos instead of size_type
    std::string::size_type p0, p1, length;
    int nQuotes;
    int nItems;
    int equalPosition;
    long numberOfLines;
    std::streampos position;
    std::ifstream fileInstance(fileName.c_str(), std::ios::in | std::ios::binary);
    std::string msg;

    this->sections.clear();
    this->sectionPositions.clear();
    position = 0;
    numberOfLines = -1;
    while (std::getline(fileInstance, line))
    {
        // std::cout << " INPUT <" << line << ">" << std::endl;
        ++numberOfLines;

        trimmedLine = "";
        if((line.size() > 0))
        {
            // trim leading and trailing spaces
            p1 = line.find_last_not_of(" \n\r\t");
            if (p1 != line.npos)
            {
                trimmedLine = line.substr(0, p1 + 1);
                p0 = trimmedLine.find_first_not_of(" \n\r\t");
                trimmedLine = trimmedLine.substr(p0);
            }
        }
        if (trimmedLine.size() > 0)
        {
            if (trimmedLine[0] == '[')
            {
                if (p0 != 0)
                {
                    msg = "Main key not as first line character";
                    std::cout << "WARNING: " << msg;
                    std::cout << " line = <" << line << ">" << std::endl;
                }
                mainKey = "";
                p0 = 0;
                p1 = 0;
                nItems = 1;
                for (i = 1; i < trimmedLine.size(); i++)
                {
                    if (trimmedLine[i] == '[')
                    {
                        msg = "Invalid line: <" + line + ">";
                        throw std::invalid_argument(msg);
                    }
                    else
                    {
                        if (trimmedLine[i] == ']')
                        {
                            nItems++;
                            p1 = i;
                        }
                    }
                }
                length = p1 - p0 - 1;
                if ((nItems != 2) || (length < 1))
                {
                    msg = "Invalid line: <" + line + ">";
                    throw std::invalid_argument(msg);
                }
                mainKey = trimmedLine.substr(p0 + 1, length);
                this->sections.push_back(mainKey);
                this->sectionPositions[mainKey] = numberOfLines;
                continue;
            }

            tmpString = "";
            nQuotes = 0;
            equalPosition = 0;
            for(i=0; i < trimmedLine.size(); i++)
            {
                if (trimmedLine[i] == '"')
                {
                    nQuotes++;
                    tmpString += trimmedLine[i];
                    continue;
                }
                if (nQuotes && (nQuotes % 2))
                {
                    // in between quotes
                    tmpString += trimmedLine[i];
                    continue;
                }
                else
                {
                    if ((trimmedLine[i] == '#') || (trimmedLine[i] == ';'))
                    {
                        i = trimmedLine.size();
                    }
                    if (equalPosition == 0)
                    {
                        if (!isspace(trimmedLine[i]))
                        {
                            tmpString += trimmedLine[i];
                        }
                    }
                    else
                    {
                        tmpString += trimmedLine[i];
                    }
                    if(trimmedLine[i] == '=')
                    {
                        if (equalPosition == 0)
                        {
                            equalPosition = tmpString.size() - 1;
                        }
                    }
                }
            }
            if (nQuotes % 2)
            {
                msg = "Unmatched double quotes in line: <" + line + ">";
                throw std::invalid_argument(msg);
            }
            // std::cout << " tmpString <" << tmpString << ">" << std::endl;

            if (tmpString.size() < 1)
            {
                // empty line
                key = "";
                continue;
            }
            if(equalPosition > 0)
            {
                // we have a key
                key = "";
                p0 = 0;
                p1 = equalPosition;
                length = p1 - p0;
                if (length < 1)
                {
                    msg = "Invalid line: <" + line + ">";
                    throw std::invalid_argument(msg);
                }
                key = tmpString.substr(p0, length);
                content = tmpString.substr(p1 + 1, tmpString.size() - p1 - 1);
                this->sectionContents[mainKey][key] = content;
            }
            else
            {
                // continuation line
                if ((key.size() > 0) && (mainKey.size() > 0))
                {
                    this->sectionContents[mainKey][key] += tmpString;
                }
                else
                {
                    std::cout << "Ignored line: <" + line + ">";
                }
            }
        }
    }
    fileInstance.clear();
    if (fileInstance.is_open())
    {
        fileInstance.close();
    }
    this->fileName = fileName;
}

const std::vector<std::string> & SimpleIni::getSections()
{
    return this->sections;
}

void SimpleIni::getSubsections(const std::string & parent, \
                               std::vector<std::string> & destination, \
                               const bool & caseSensitive)
{
    std::string targetString;
    std::string instanceString;
    std::locale loc;
    std::vector<std::string>::size_type i;
    std::string::size_type j;

    destination.clear();
    if (parent.size() == 0)
    {
        destination.resize(this->sections.size());
        for (i = 0; i < this->sections.size(); i++)
        {
            destination[i] = this->sections[i];
        }
        return;
    }
    if (caseSensitive)
    {
        targetString = parent + ".";
        for (i = 0; i < this->sections.size(); i++)
        {
            if (this->sections[i].size() == targetString.size())
            {
                if (this->sections[i].substr(0, targetString.size()) == targetString)
                {
                    destination.push_back(this->sections[i]);
                }
            }
        }
    }
    else
    {
        targetString = parent + ".";
        this->toUpper(targetString, loc);
        for (i = 0; i < this->sections.size(); i++)
        {
            instanceString = this->sections[i];
            if (instanceString.size() == targetString.size())
            {
                this->toUpper(instanceString, loc);
                if (instanceString == targetString)
                {
                    destination.push_back(this->sections[i]);
                }
            }
        }
    }
}

const std::map<std::string, std::string > & SimpleIni::readSection(const std::string & key, \
                                                                   const bool & caseSensitive)
{
    std::string inputKey;
    std::string tmpKey;
    std::locale loc;
    std::vector<std::string>::size_type i, j;

    if (this->sectionContents.find(key) == this->sectionContents.end())
    {
        if (!caseSensitive)
        {
            inputKey = key;
            for (i = 0; i < key.size(); i++)
            {
                inputKey[i] = std::toupper(inputKey[i], loc);
            }
            for (i = 0; i < this->sections.size(); i++)
            {
                tmpKey = this->sections[i];
                if (tmpKey.size() == inputKey.size())
                {
                    j = 0;
                    while (std::toupper(tmpKey[j], loc) == inputKey[j])
                    {
                        j++;
                        if (j == inputKey.size())
                        {
                            break;
                        }
                    }
                    if (j < inputKey.size())
                    {
                        return this->sectionContents[tmpKey];
                    }
                }
            }
        }
        this->defaultContent.clear();
        return this->defaultContent;
    }
    return this->sectionContents[key];
}
<commit_msg>Correct bug reading subsections.<commit_after>#include "fisx_simpleini.h"
#include <iostream>
#include <fstream>
#include <stdexcept>
#include <stdlib.h>

SimpleIni::SimpleIni()
{
    this->fileName = "";
    this->sections.clear();
    this->sectionPositions.clear();
}

SimpleIni::SimpleIni(std::string fileName)
{
    this->readFileName(fileName);
}

void SimpleIni::readFileName(std::string fileName)
{
    std::string mainKey;
    std::string key;
    std::string line;
    std::string trimmedLine;
    std::string tmpString;
    std::string content;
    std::string::size_type i;
    // I should use streampos instead of size_type
    std::string::size_type p0, p1, length;
    int nQuotes;
    int nItems;
    int equalPosition;
    long numberOfLines;
    std::streampos position;
    std::ifstream fileInstance(fileName.c_str(), std::ios::in | std::ios::binary);
    std::string msg;

    this->sections.clear();
    this->sectionPositions.clear();
    position = 0;
    numberOfLines = -1;
    while (std::getline(fileInstance, line))
    {
        // std::cout << " INPUT <" << line << ">" << std::endl;
        ++numberOfLines;

        trimmedLine = "";
        if((line.size() > 0))
        {
            // trim leading and trailing spaces
            p1 = line.find_last_not_of(" \n\r\t");
            if (p1 != line.npos)
            {
                trimmedLine = line.substr(0, p1 + 1);
                p0 = trimmedLine.find_first_not_of(" \n\r\t");
                trimmedLine = trimmedLine.substr(p0);
            }
        }
        if (trimmedLine.size() > 0)
        {
            if (trimmedLine[0] == '[')
            {
                if (p0 != 0)
                {
                    msg = "Main key not as first line character";
                    std::cout << "WARNING: " << msg;
                    std::cout << " line = <" << line << ">" << std::endl;
                }
                mainKey = "";
                p0 = 0;
                p1 = 0;
                nItems = 1;
                for (i = 1; i < trimmedLine.size(); i++)
                {
                    if (trimmedLine[i] == '[')
                    {
                        msg = "Invalid line: <" + line + ">";
                        throw std::invalid_argument(msg);
                    }
                    else
                    {
                        if (trimmedLine[i] == ']')
                        {
                            nItems++;
                            p1 = i;
                        }
                    }
                }
                length = p1 - p0 - 1;
                if ((nItems != 2) || (length < 1))
                {
                    msg = "Invalid line: <" + line + ">";
                    throw std::invalid_argument(msg);
                }
                mainKey = trimmedLine.substr(p0 + 1, length);
                this->sections.push_back(mainKey);
                this->sectionPositions[mainKey] = numberOfLines;
                continue;
            }

            tmpString = "";
            nQuotes = 0;
            equalPosition = 0;
            for(i=0; i < trimmedLine.size(); i++)
            {
                if (trimmedLine[i] == '"')
                {
                    nQuotes++;
                    tmpString += trimmedLine[i];
                    continue;
                }
                if (nQuotes && (nQuotes % 2))
                {
                    // in between quotes
                    tmpString += trimmedLine[i];
                    continue;
                }
                else
                {
                    if ((trimmedLine[i] == '#') || (trimmedLine[i] == ';'))
                    {
                        i = trimmedLine.size();
                    }
                    if (equalPosition == 0)
                    {
                        if (!isspace(trimmedLine[i]))
                        {
                            tmpString += trimmedLine[i];
                        }
                    }
                    else
                    {
                        tmpString += trimmedLine[i];
                    }
                    if(trimmedLine[i] == '=')
                    {
                        if (equalPosition == 0)
                        {
                            equalPosition = tmpString.size() - 1;
                        }
                    }
                }
            }
            if (nQuotes % 2)
            {
                msg = "Unmatched double quotes in line: <" + line + ">";
                throw std::invalid_argument(msg);
            }
            // std::cout << " tmpString <" << tmpString << ">" << std::endl;

            if (tmpString.size() < 1)
            {
                // empty line
                key = "";
                continue;
            }
            if(equalPosition > 0)
            {
                // we have a key
                key = "";
                p0 = 0;
                p1 = equalPosition;
                length = p1 - p0;
                if (length < 1)
                {
                    msg = "Invalid line: <" + line + ">";
                    throw std::invalid_argument(msg);
                }
                key = tmpString.substr(p0, length);
                content = tmpString.substr(p1 + 1, tmpString.size() - p1 - 1);
                this->sectionContents[mainKey][key] = content;
            }
            else
            {
                // continuation line
                if ((key.size() > 0) && (mainKey.size() > 0))
                {
                    this->sectionContents[mainKey][key] += tmpString;
                }
                else
                {
                    std::cout << "Ignored line: <" + line + ">";
                }
            }
        }
    }
    fileInstance.clear();
    if (fileInstance.is_open())
    {
        fileInstance.close();
    }
    this->fileName = fileName;
}

const std::vector<std::string> & SimpleIni::getSections()
{
    return this->sections;
}

void SimpleIni::getSubsections(const std::string & parent, \
                               std::vector<std::string> & destination, \
                               const bool & caseSensitive)
{
    std::string targetString;
    std::string instanceString;
    std::locale loc;
    std::vector<std::string>::size_type i;
    std::string::size_type j;

    destination.clear();
    if (parent.size() == 0)
    {
        destination.resize(this->sections.size());
        for (i = 0; i < this->sections.size(); i++)
        {
            destination[i] = this->sections[i];
        }
        return;
    }
    if (caseSensitive)
    {
        targetString = parent + ".";
        for (i = 0; i < this->sections.size(); i++)
        {
            if (this->sections[i].size() == targetString.size())
            {
                if (this->sections[i].substr(0, targetString.size()) == targetString)
                {
                    destination.push_back(this->sections[i]);
                }
            }
        }
    }
    else
    {
        targetString = parent + ".";
        this->toUpper(targetString, loc);
        for (i = 0; i < this->sections.size(); i++)
        {
            instanceString = this->sections[i];
            if (instanceString.size() >= targetString.size())
            {
                this->toUpper(instanceString, loc);
                if (instanceString.substr(0, targetString.size()) == targetString)
                {
                    destination.push_back(this->sections[i]);
                }
            }
        }
    }
}

const std::map<std::string, std::string > & SimpleIni::readSection(const std::string & key, \
                                                                   const bool & caseSensitive)
{
    std::string inputKey;
    std::string tmpKey;
    std::locale loc;
    std::vector<std::string>::size_type i, j;

    if (this->sectionContents.find(key) == this->sectionContents.end())
    {
        if (!caseSensitive)
        {
            inputKey = key;
            for (i = 0; i < key.size(); i++)
            {
                inputKey[i] = std::toupper(inputKey[i], loc);
            }
            for (i = 0; i < this->sections.size(); i++)
            {
                tmpKey = this->sections[i];
                if (tmpKey.size() == inputKey.size())
                {
                    j = 0;
                    while (std::toupper(tmpKey[j], loc) == inputKey[j])
                    {
                        j++;
                        if (j == inputKey.size())
                        {
                            break;
                        }
                    }
                    if (j < inputKey.size())
                    {
                        return this->sectionContents[tmpKey];
                    }
                }
            }
        }
        this->defaultContent.clear();
        return this->defaultContent;
    }
    return this->sectionContents[key];
}
<|endoftext|>


<commit_before>// matrixMultiplication.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>

int main()
{
	//###Czytanie z pliku###

	//Deklaracja plikw
	FILE *firstMatrixFile, *secondMatrixFile, *outputFile;

	//Zmienne do danych z plikw {FM - FirstMatrix | SM - SecondMatrix}
	int FMRows=0, FMColumns=0, SMRows=0, SMColumns=0;

	//Otwarcie plikw do odczytu
	if ((firstMatrixFile = fopen("firstMatrixFile.txt", "r")) == NULL) {
		printf("Nie mog otworzy pliku firstMatrixFile.txt!\n");
		exit(1);
	}
	if ((secondMatrixFile = fopen("secondMatrixFile.txt", "r")) == NULL) {
		printf("Nie mog otworzy pliku secondMatrixFile.txt!\n");
		exit(1);
	}

	//Okrelenie dugoci wierszy i kolumn
	fscanf(firstMatrixFile, "%d", &FMRows);
	fscanf(firstMatrixFile, "%d", &FMColumns);
	fscanf(secondMatrixFile, "%d", &SMRows);
	fscanf(secondMatrixFile, "%d", &SMColumns);

	//Alokacja pamici
	//First matrix
	float **firstMatrix = (float **)malloc(FMRows*sizeof(float *));
	for (int i = 0; i < FMColumns; i++)
	{
		firstMatrix[i] = (float *)malloc(FMColumns*sizeof(float));
	}

	//Second matrix
	float **secondMatrix = (float **)malloc(SMRows*sizeof(float *));
	for (int i = 0; i < SMColumns; i++)
	{
		secondMatrix[i] = (float *)malloc(SMColumns*sizeof(float));
	}

	//Czytanie po caych plikach i zapisanie danych do odpowiednich zmiennych
	//First Matrix
	for (int i = 0; i < FMRows; i++)
	{
		for (int j = 0; j < FMColumns; j++)
		{
			fscanf(firstMatrixFile, "%f", &firstMatrix[i][j]);
			printf("%f ", firstMatrix[i][j]);
		}
		printf("\n");
	}

	//Second Matrix
	for (int i = 0; i < SMRows; i++)
	{
		for (int j = 0; j < SMColumns; j++)
		{
			fscanf(secondMatrixFile, "%f", &secondMatrix[i][j]);
			printf("%f ", secondMatrix[i][j]);
		}
		printf("\n");
	}

	//fprintf(fp, "%s", tekst); /* zapisz nasz acuch w pliku */

	//Zamknicie plikw
	fclose(firstMatrixFile);
	fclose(secondMatrixFile);

	system("pause");
    return 0;
}

<commit_msg>Improved memory alocation.<commit_after>// matrixMultiplication.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>

int main()
{
	//###Czytanie z pliku###

	//Deklaracja plikw
	FILE *firstMatrixFile, *secondMatrixFile, *outputFile;

	//Zmienne do danych z plikw {FM - FirstMatrix | SM - SecondMatrix}
	int FMRows=0, FMColumns=0, SMRows=0, SMColumns=0;

	//Otwarcie plikw do odczytu
	if ((firstMatrixFile = fopen("firstMatrixFile.txt", "r")) == NULL) {
		printf("Nie mog otworzy pliku firstMatrixFile.txt!\n");
		exit(1);
	}
	if ((secondMatrixFile = fopen("secondMatrixFile.txt", "r")) == NULL) {
		printf("Nie mog otworzy pliku secondMatrixFile.txt!\n");
		exit(1);
	}

	//Okrelenie dugoci wierszy i kolumn
	fscanf(firstMatrixFile, "%d", &FMRows);
	fscanf(firstMatrixFile, "%d", &FMColumns);
	fscanf(secondMatrixFile, "%d", &SMRows);
	fscanf(secondMatrixFile, "%d", &SMColumns);

	//Alokacja pamici
	//First matrix
	float **firstMatrix = (float **)malloc(FMRows*sizeof(float *));
	for (int i = 0; i < FMRows; i++)
	{
		firstMatrix[i] = (float *)malloc(FMColumns*sizeof(float));
	}

	//Second matrix
	float **secondMatrix = (float **)malloc(SMRows*sizeof(float *));
	for (int i = 0; i < SMRows; i++)
	{
		secondMatrix[i] = (float *)malloc(SMColumns*sizeof(float));
	}

	//Czytanie po caych plikach i zapisanie danych do odpowiednich zmiennych
	//First Matrix
	for (int i = 0; i < FMRows; i++)
	{
		for (int j = 0; j < FMColumns; j++)
		{
			fscanf(firstMatrixFile, "%f", &firstMatrix[i][j]);
			printf("%f ", firstMatrix[i][j]);
		}
		printf("\n");
	}

	//Second Matrix
	for (int i = 0; i < SMRows; i++)
	{
		for (int j = 0; j < SMColumns; j++)
		{
			fscanf(secondMatrixFile, "%f", &secondMatrix[i][j]);
			printf("%f ", secondMatrix[i][j]);
		}
		printf("\n");
	}

	//fprintf(fp, "%s", tekst); /* zapisz nasz acuch w pliku */

	//Zamknicie plikw
	fclose(firstMatrixFile);
	fclose(secondMatrixFile);

	system("pause");
    return 0;
}

<|endoftext|>