<commit_before>// \brief Command-line utility to send email messages.
#include <iostream>
#include <cstdlib>
#include "IniFile.h"
#include "EmailSender.h"
#include "StringUtil.h"
#include "TextUtil.h"
#include "util.h"

namespace {

[[noreturn]] void Usage() {
    std::cerr << "Usage: " << ::progname << " [--sender=sender] [-reply-to=reply_to] --recipients=recipients\n"
              << "  [--cc-recipients=cc_recipients] [--bcc-recipients=bcc_recipients] [--expand-newline-escapes]\n"
              << "  --subject=subject --message-body=message_body [--priority=priority] [--format=format]\n\n"
              << "       \"priority\" has to be one of \"very_low\", \"low\", \"medium\", \"high\", or\n"
              << "       \"very_high\".  \"format\" has to be one of \"plain_text\" or \"html\"  At least one\n"
              << "       of \"sender\" or \"reply-to\" has to be specified. If \"--expand-newline-escapes\" has\n"
              << "       been specified, all occurrences of \\n in the message body will be replaced by a line feed\n"
              << "       and a double backslash by a single backslash.  The message body is assumed to be UTF-8!\n\n";
    std::exit(EXIT_FAILURE);
}

EmailSender::Priority StringToPriority(const std::string &priority_candidate) {
    if (priority_candidate == "very_low")
        return EmailSender::VERY_LOW;
    if (priority_candidate == "low")
        return EmailSender::LOW;
    if (priority_candidate == "medium")
        return EmailSender::MEDIUM;
    if (priority_candidate == "high")
        return EmailSender::HIGH;
    if (priority_candidate == "very_high")
        return EmailSender::VERY_HIGH;
    LOG_ERROR("\"" + priority_candidate + "\" is an unknown priority!");
}

EmailSender::Format StringToFormat(const std::string &format_candidate) {
    if (format_candidate == "plain_text")
        return EmailSender::PLAIN_TEXT;
    else if (format_candidate == "html")
        return EmailSender::HTML;
    LOG_ERROR("\"" + format_candidate + "\" is an unknown format!");
}

bool ExtractArg(const char * const argument, const std::string &arg_name, std::string * const arg_value) {
    if (StringUtil::StartsWith(argument, "--" + arg_name + "=")) {
        *arg_value = argument + arg_name.length() + 3 /* two dashes and one equal sign */;
        if (arg_value->empty())
            LOG_ERROR(arg_name + " is missing!");

        return true;
    }

    return false;
}

void ParseCommandLine(char **argv, std::string * const sender, std::string * const reply_to,
                      std::string * const recipients, std::string * const cc_recipients, std::string * const bcc_recipients,
                      std::string * const subject, std::string * const message_body, std::string * const priority,
                      std::string * const format, bool * const expand_newline_escapes)
{
    *expand_newline_escapes = false;
    while (*argv != nullptr) {
        if (std::strcmp(*argv, "--expand-newline-escapes") == 0) {
            *expand_newline_escapes = true;
            ++argv;
        } else if (ExtractArg(*argv, "sender", sender) or ExtractArg(*argv, "reply-to", reply_to)
            or ExtractArg(*argv, "recipients", recipients) or ExtractArg(*argv, "cc-recipients", cc_recipients)
            or ExtractArg(*argv, "bcc-recipients", bcc_recipients) or ExtractArg(*argv, "subject", subject)
            or ExtractArg(*argv, "message-body", message_body) or ExtractArg(*argv, "priority", priority)
            or ExtractArg(*argv, "format", format))
            ++argv;
        else
            LOG_ERROR("unknown argument: " + std::string(*argv));
    }

    if (recipients->empty() and cc_recipients->empty() and bcc_recipients->empty())
        LOG_ERROR("you must specify a recipient!");
    if (subject->empty())
        LOG_ERROR("you must specify a subject!");
    if (message_body->empty())
        LOG_ERROR("you must specify a message-body!");
}

std::vector<std::string> SplitRecipients(const std::string &recipients) {
    std::vector<std::string> individual_recipients;
    StringUtil::Split(recipients, ',', &individual_recipients);
    return individual_recipients;
}

// "text" is assumed to be UTF-8 encoded.
std::string ExpandNewlineEscapes(const std::string &text) {
    std::wstring escaped_string;
    if (unlikely(not TextUtil::UTF8ToWCharString(text, &escaped_string)))
        LOG_ERROR("can't convert a supposed UTF-8 string to a wide string!");

    std::wstring unescaped_string;
    bool backslash_seen(false);
    for (auto ch : escaped_string) {
        if (backslash_seen) {
            if (ch == '\\')
                unescaped_string += '\\';
            else if (ch == 'n')
                unescaped_string += '\n';
            else {
                std::string utf8_string;
                TextUtil::WCharToUTF8String(ch, &utf8_string);
                LOG_ERROR("unknown escape: \\" + utf8_string + "!");
            }
            backslash_seen = false;
        } else if (ch == '\\')
            backslash_seen = true;
        else
            unescaped_string += ch;
    }

    std::string utf8_string;
    if (unlikely(not TextUtil::WCharToUTF8String(unescaped_string, &utf8_string)))
        LOG_ERROR("can't convert a supposed wide string to a UTF-8 string!");

    return utf8_string;
}

} // unnamed namespace

int Main(int argc, char *argv[]) {
    if (argc == 1)
        Usage();

    EmailSender::Priority priority(EmailSender::DO_NOT_SET_PRIORITY);
    EmailSender::Format format(EmailSender::PLAIN_TEXT);

    std::string sender, reply_to, recipients, cc_recipients, bcc_recipients, subject, message_body, priority_as_string,
        format_as_string;
    bool expand_newline_escapes;
    ParseCommandLine(++argv, &sender, &reply_to, &recipients, &cc_recipients, &bcc_recipients, &subject, &message_body,
                     &priority_as_string, &format_as_string, &expand_newline_escapes);

    if (sender.empty() and reply_to.empty()) {
        IniFile ini_file("/usr/local/var/lib/tuelib/cronjobs/smtp_server.conf");
        sender = ini_file.getString("SMTPServer", "server_user") + "@uni-tuebingen.de";
    }

    if (not priority_as_string.empty())
        priority = StringToPriority(priority_as_string);
    if (not format_as_string.empty())
        format = StringToFormat(format_as_string);

    if (expand_newline_escapes)
        message_body = ExpandNewlineEscapes(message_body);
    if (not EmailSender::SendEmail(sender, SplitRecipients(recipients), SplitRecipients(cc_recipients),
                                   SplitRecipients(bcc_recipients), subject, message_body, priority, format, reply_to))
        LOG_ERROR("failed to send your email!");

    return EXIT_SUCCESS;
}
<commit_msg>Added a helpful message foe debugging problems.<commit_after>/** \brief Command-line utility to send email messages.
 *  \author Dr. Johannes Ruscheinski (johannes.ruscheinski@uni-tuebingen.de)
 *
 *  \copyright 2018 Universitätsbibliothek Tübingen.  All rights reserved.
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Affero General Public License as
 *  published by the Free Software Foundation, either version 3 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 Affero General Public License for more details.
 *
 *  You should have received a copy of the GNU Affero General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#include <iostream>
#include <cstdlib>
#include "IniFile.h"
#include "EmailSender.h"
#include "MiscUtil.h"
#include "StringUtil.h"
#include "TextUtil.h"
#include "util.h"

namespace {

[[noreturn]] void Usage() {
    std::cerr << "Usage: " << ::progname << " [--sender=sender] [-reply-to=reply_to] --recipients=recipients\n"
              << "  [--cc-recipients=cc_recipients] [--bcc-recipients=bcc_recipients] [--expand-newline-escapes]\n"
              << "  --subject=subject --message-body=message_body [--priority=priority] [--format=format]\n\n"
              << "       \"priority\" has to be one of \"very_low\", \"low\", \"medium\", \"high\", or\n"
              << "       \"very_high\".  \"format\" has to be one of \"plain_text\" or \"html\"  At least one\n"
              << "       of \"sender\" or \"reply-to\" has to be specified. If \"--expand-newline-escapes\" has\n"
              << "       been specified, all occurrences of \\n in the message body will be replaced by a line feed\n"
              << "       and a double backslash by a single backslash.  The message body is assumed to be UTF-8!\n\n";
    std::exit(EXIT_FAILURE);
}

EmailSender::Priority StringToPriority(const std::string &priority_candidate) {
    if (priority_candidate == "very_low")
        return EmailSender::VERY_LOW;
    if (priority_candidate == "low")
        return EmailSender::LOW;
    if (priority_candidate == "medium")
        return EmailSender::MEDIUM;
    if (priority_candidate == "high")
        return EmailSender::HIGH;
    if (priority_candidate == "very_high")
        return EmailSender::VERY_HIGH;
    LOG_ERROR("\"" + priority_candidate + "\" is an unknown priority!");
}

EmailSender::Format StringToFormat(const std::string &format_candidate) {
    if (format_candidate == "plain_text")
        return EmailSender::PLAIN_TEXT;
    else if (format_candidate == "html")
        return EmailSender::HTML;
    LOG_ERROR("\"" + format_candidate + "\" is an unknown format!");
}

bool ExtractArg(const char * const argument, const std::string &arg_name, std::string * const arg_value) {
    if (StringUtil::StartsWith(argument, "--" + arg_name + "=")) {
        *arg_value = argument + arg_name.length() + 3 /* two dashes and one equal sign */;
        if (arg_value->empty())
            LOG_ERROR(arg_name + " is missing!");

        return true;
    }

    return false;
}

void ParseCommandLine(char **argv, std::string * const sender, std::string * const reply_to,
                      std::string * const recipients, std::string * const cc_recipients, std::string * const bcc_recipients,
                      std::string * const subject, std::string * const message_body, std::string * const priority,
                      std::string * const format, bool * const expand_newline_escapes)
{
    *expand_newline_escapes = false;
    while (*argv != nullptr) {
        if (std::strcmp(*argv, "--expand-newline-escapes") == 0) {
            *expand_newline_escapes = true;
            ++argv;
        } else if (ExtractArg(*argv, "sender", sender) or ExtractArg(*argv, "reply-to", reply_to)
            or ExtractArg(*argv, "recipients", recipients) or ExtractArg(*argv, "cc-recipients", cc_recipients)
            or ExtractArg(*argv, "bcc-recipients", bcc_recipients) or ExtractArg(*argv, "subject", subject)
            or ExtractArg(*argv, "message-body", message_body) or ExtractArg(*argv, "priority", priority)
            or ExtractArg(*argv, "format", format))
            ++argv;
        else
            LOG_ERROR("unknown argument: " + std::string(*argv));
    }

    if (recipients->empty() and cc_recipients->empty() and bcc_recipients->empty())
        LOG_ERROR("you must specify a recipient!");
    if (subject->empty())
        LOG_ERROR("you must specify a subject!");
    if (message_body->empty())
        LOG_ERROR("you must specify a message-body!");
}

std::vector<std::string> SplitRecipients(const std::string &recipients) {
    std::vector<std::string> individual_recipients;
    StringUtil::Split(recipients, ',', &individual_recipients);
    return individual_recipients;
}

// "text" is assumed to be UTF-8 encoded.
std::string ExpandNewlineEscapes(const std::string &text) {
    std::wstring escaped_string;
    if (unlikely(not TextUtil::UTF8ToWCharString(text, &escaped_string)))
        LOG_ERROR("can't convert a supposed UTF-8 string to a wide string!");

    std::wstring unescaped_string;
    bool backslash_seen(false);
    for (auto ch : escaped_string) {
        if (backslash_seen) {
            if (ch == '\\')
                unescaped_string += '\\';
            else if (ch == 'n')
                unescaped_string += '\n';
            else {
                std::string utf8_string;
                TextUtil::WCharToUTF8String(ch, &utf8_string);
                LOG_ERROR("unknown escape: \\" + utf8_string + "!");
            }
            backslash_seen = false;
        } else if (ch == '\\')
            backslash_seen = true;
        else
            unescaped_string += ch;
    }

    std::string utf8_string;
    if (unlikely(not TextUtil::WCharToUTF8String(unescaped_string, &utf8_string)))
        LOG_ERROR("can't convert a supposed wide string to a UTF-8 string!");

    return utf8_string;
}

} // unnamed namespace

int Main(int argc, char *argv[]) {
    if (argc == 1)
        Usage();

    EmailSender::Priority priority(EmailSender::DO_NOT_SET_PRIORITY);
    EmailSender::Format format(EmailSender::PLAIN_TEXT);

    std::string sender, reply_to, recipients, cc_recipients, bcc_recipients, subject, message_body, priority_as_string,
        format_as_string;
    bool expand_newline_escapes;
    ParseCommandLine(++argv, &sender, &reply_to, &recipients, &cc_recipients, &bcc_recipients, &subject, &message_body,
                     &priority_as_string, &format_as_string, &expand_newline_escapes);

    if (sender.empty() and reply_to.empty()) {
        IniFile ini_file("/usr/local/var/lib/tuelib/cronjobs/smtp_server.conf");
        sender = ini_file.getString("SMTPServer", "server_user") + "@uni-tuebingen.de";
    }

    if (not priority_as_string.empty())
        priority = StringToPriority(priority_as_string);
    if (not format_as_string.empty())
        format = StringToFormat(format_as_string);

    if (expand_newline_escapes)
        message_body = ExpandNewlineEscapes(message_body);
    if (not EmailSender::SendEmail(sender, SplitRecipients(recipients), SplitRecipients(cc_recipients),
                                   SplitRecipients(bcc_recipients), subject, message_body, priority, format, reply_to))
    {
        if (not MiscUtil::EnvironmentVariableExists("ENABLE_SMPT_CLIENT_PERFORM_LOGGING"))
            LOG_ERROR("failed to send your email! (You may want to set the ENABLE_SMPT_CLIENT_PERFORM_LOGGING to debug the problem.)");
        else
            LOG_ERROR("failed to send your email!");
    }

    return EXIT_SUCCESS;
}
<|endoftext|>


<commit_before>#include "iostream"
#include "stdlib.h"
#include "GL/freeglut.h"
#include "GL/gl.h"
using namespace std;

int play=0;	// game's pause and play state
int windowWidth=900,windowHeight=600;
float x=410,y=60;	// (x,y) are the mid point of square
//float xtest=0,ytest=121,speedtest=0.4;

int attach=0;	// wheather to attach user with box or not
float dx=0.0; // distance between player and inside box

float xtest[8]={0,850,20,0,13,857,100,800};
//float xtest[8]={200,200,200,200,200,200,200,200s};
float ytest[8]={121,171,221,271,327,377,427,477};
//float speedtest[8]={0.4,-0.3,0.45,0,0.42,-0.52,0.47,-0.56};
//float speedtest[8]={0.3,-0.23,.130,-0,0.33,-0.43,0.33,-0.13};
float speedtest[8]={0.5,-0.03,.130,-0,0.23,-0.29,0.33,-0.13};

//float width[8]={120,130,140,windowWidth,150,127,127,120};
float width[8]={170,170,170,windowWidth,170,177,167,160};
int attachedbox=-1;

//--------for second player---------
float x1=450,y1=60;	// 2nd player
int attach1=0;
float dx1=0.0;
int attachedbox1=-1;

void init(void)
{
   glClearColor(0.0,0.0,0.0,0.0);	// rgb color to clean with
   glMatrixMode(GL_PROJECTION);
   glLoadIdentity();
   glOrtho(0.0f,windowWidth,0.0f,windowHeight,0.0f,1.0f);
}

void display(void)
{

	glClear(GL_COLOR_BUFFER_BIT);	// clear color buffer

	glColor3f(1.0,1.0,1.0);
	// BASIC LINES --WHITE
	glBegin(GL_LINES);
	for(int a=121;a<=600;a+=50)
	{
	   glVertex3i(0,a,0);
	   glVertex3i(900,a,0);
	}
	glEnd();

	//BOXES
	//if(play)
	{
	glBegin(GL_QUADS);
	{

	for(int j=0;j<8;j++)	//All Boxes
		{
			glVertex3f(xtest[j],ytest[j]-25,0);
			glVertex3f(xtest[j]+width[j],ytest[j]-25,0);
			glVertex3f(xtest[j]+width[j],ytest[j]+25,0);
			glVertex3f(xtest[j],ytest[j]+25,0);

		}

		glColor3f(0.30,0.70,0.30);
		glVertex3f(0,101,0);	// bottom area
		glVertex3f(windowWidth,101,0);
		glVertex3f(windowWidth,0,0);
		glVertex3f(0,0,0);

		glColor3f(0.10,0.80,0.50);
		glVertex3f(0,246,0);		// middle area
		glVertex3f(windowWidth,246,0);
		glVertex3f(windowWidth,306,0);
		glVertex3f(0,306,0);

		glColor3f(0.10,0.90,0.20);
		glVertex3f(0,502,0);	// top area
		glVertex3f(windowWidth,502,0);
		glVertex3f(windowWidth,windowHeight,0);
		glVertex3f(0,windowHeight,0);

		glColor3f(1.0,1.0,1.0);

	}
	glEnd();
	}

	int xtemp=x;
	if(attach==1)
	{
		x=xtest[attachedbox]+dx;
		//cout<<"xtest "<<xtest<<" x"<<x<<"\n";
	}

	//2player
	int xtemp1=x1;
	if(attach1==1)
	{
		x1=xtest[attachedbox1]+dx1;
	}

	//PLAYER1 BOX -- ORANGE wasd
	glColor3f(0.53,0.224,0.100);	// set color
	glBegin(GL_POLYGON);
	glVertex3f(x-15,y-15,0);
	glVertex3f(x+15,y-15,0);
	glVertex3f(x+15,y+15,0);
	glVertex3f(x-15,y+15,0);
	glEnd();

	//PLAYER2 BOX -- YELLOW ijkl
	glColor3f(0,.5,1.0);	// set color
	glBegin(GL_POLYGON);
	glVertex3f(x1-15,y1-15,0);
	glVertex3f(x1+15,y1-15,0);
	glVertex3f(x1+15,y1+15,0);
	glVertex3f(x1-15,y1+15,0);
	glEnd();

	//x=xtemp;

	glFlush();					// forces drawing to complete

}

void reshape(int w, int h)
{
	windowHeight=h;
	windowWidth=w;
glViewport(0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0,(GLdouble)w,0.0,(GLdouble)h,0.0,1.0);

}

void againDisplay()
{
		for(int j=0;j<8;j++)
		{
			xtest[j]=xtest[j]+speedtest[j];
		}

		// making boxes continues ones
		for(int j=0;j<8;j++)
		{
			if(xtest[j]>900)
			{xtest[j]=0;}
			else if(xtest[j]<0)
				{xtest[j]=900;}

		}

		//Game over conditions
		if((y>121-25 &&  y<246) || (y>306 && y<502))
		{
			if(attach==0)
			{
				cout<<"Game Over Player1\n";
				x=410,y=60;
			}
		}
		if((y>=246)&&(y<=306)||(y>802))	// middle area is safe zone
		{
			attach=1;
		}

		//Game over conditions for player2
		if((y1>121-25 &&  y1<246) || (y1>306 && y1<502))
		{
			if(attach1==0)
			{
				cout<<"Game Over Player2\n";
				x1=450,y1=60;
			}
		}
		if((y1>=246)&&(y1<=306)||(y1>802))	// middle area is safe zone
		{
			attach1=1;
		}

	glutPostRedisplay();
	 }

//For keyboard, p for pause
// 112 for 'p' and 32 for 'space'
void key(unsigned char key,int xm,int ym)
{
	//cout<<"KEY.... ";

	if(key==97)
	{x=x-9;	}
	else if(key==119)
		{y=y+9;}
	else if(key==100)
		{x=x+9; }
	else if(key==115)
		{y=y-9; }
	else if(key==112) 	// Game pause and play using key 'p'
	{ 	cout<<"Game Starts";
		if(play==0)
		{play=1; glutIdleFunc(againDisplay); if(y>=560 || y1>=560 ){x=410; y=60; x1=450; y1=60;}   }
		else {play=0; glutIdleFunc(NULL);}	// In  pause also players can move
	}

	//for player2
	if(key==106)
	{x1=x1-9;	}
	else if(key==105)
		{y1=y1+9;}
	else if(key==108)
		{x1=x1+9; }
	else if(key==107)
		{y1=y1-9; }
	/*else if(key==112) 	// Game pause and play using key 'p'
	{ 	cout<<"Game Starts";
		if(play==0)
		{play=1; glutIdleFunc(againDisplay); if(x>=560){x=450; y=60;}  }
		else {play=0; glutIdleFunc(NULL);}	// In  pause also players can move
	}*/

int flag=0;

	for(int j=0;j<8;j++)
	{	// that's the best place to make this...

		if ((y>=ytest[j]-25 && y<=ytest[j]+25 )&&( xtest[j]<=x && xtest[j]+width[j]>=x))
		{
			dx=x-xtest[j];
			if(dx<0) dx=-dx;
			cout<<"attach=1\n";
			attach=1;
			flag=1;
			attachedbox=j;
			cout<<"Player1 is on "<<j<<" - box. and attachedbox is "<<attachedbox<<"\n";

			break;

		}else {cout<<"y "<<y<<" ytest "<<ytest[j]<<" j "<<j<<"\n";}

	}

	if(flag==0) {attach=0; cout<<"x: "<<x<<" y: "<<y<<" and Attach1=0\n";}

	// for player2
	int flag1=0;

	for(int j=0;j<8;j++)
	{	// that's the best place to make this...

		if ((y1>=ytest[j]-25 && y1<=ytest[j]+25 )&&( xtest[j]<=x1 && xtest[j]+width[j]>=x1))
		{
			dx1=x1-xtest[j];
			if(dx1<0) dx1=-dx1;
			cout<<"attach1=1\n";
			attach1=1;
			flag1=1;
			attachedbox1=j;
			cout<<"Player2 is on "<<j<<" - box. and attachedbox is "<<attachedbox<<"\n";

			break;

		}else {cout<<"y1 "<<y1<<" ytest "<<ytest[j]<<" j "<<j<<"\n";}

	}

	if(flag1==0) {attach1=0; cout<<"x1: "<<x1<<" y1: "<<y1<<" and Attach1=0\n";}

	//Game win condition
		if(y>=560)
		{
			cout<<"PLAYER1 WON\n"; play=0; glutIdleFunc(NULL);
		}

		if(y1>=560)
		{
			cout<<"PLAYER2 WON\n"; play=0; glutIdleFunc(NULL);
		}

}

int main(int argc,char** argv)
{

	glutInit(&argc,argv);
	glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
	glutInitWindowSize(windowWidth,windowHeight);
	glutInitWindowPosition(40,20);
	glutCreateWindow("CrossJump");

	init();

	cout<<"CrossJump starts\n";

	glutReshapeFunc(reshape);	// when window is resized redraw the shape with same coordinates.
	glutDisplayFunc(display);
	//glutMouseFunc(mouse);
	glutKeyboardFunc(key);

	glutMainLoop();
	return 0;
}
<commit_msg>Recolor and other small changes<commit_after>#include "iostream"
#include "stdlib.h"
#include "GL/freeglut.h"
#include "GL/gl.h"
using namespace std;

int play=0;	// game's pause and play state
int windowWidth=900,windowHeight=600;
float x=410,y=60;	// (x,y) are the mid point of square
//float xtest=0,ytest=121,speedtest=0.4;

int attach=0;	// wheather to attach user with box or not
float dx=0.0; // distance between player and inside box

float xtest[8]={0,850,20,0,13,857,100,800};
//float xtest[8]={200,200,200,200,200,200,200,200s};
float ytest[8]={121,171,221,271,327,377,427,477};
//float speedtest[8]={0.4,-0.3,0.45,0,0.42,-0.52,0.47,-0.56};
//float speedtest[8]={0.3,-0.23,.130,-0,0.33,-0.43,0.33,-0.13};
float speedtest[8]={0.45,-0.13,.630,-0,0.76,-0.29,0.83,-0.73};

//float width[8]={120,130,140,windowWidth,150,127,127,120};
float width[8]={170,170,170,windowWidth,170,177,167,160};
int attachedbox=-1;

//--------for second player---------
float x1=450,y1=60;	// 2nd player
int attach1=0;
float dx1=0.0;
int attachedbox1=-1;

void init(void)
{
   glClearColor(0.0,0.0,0.0,0.0);	// rgb color to clean with
   glMatrixMode(GL_PROJECTION);
   glLoadIdentity();
   glOrtho(0.0f,windowWidth,0.0f,windowHeight,0.0f,1.0f);
}

void display(void)
{

	glClear(GL_COLOR_BUFFER_BIT);	// clear color buffer

	glColor3f(1.0,1.0,1.0);
	// BASIC LINES --WHITE
	glBegin(GL_LINES);
	for(int a=121;a<=600;a+=50)
	{
	   glVertex3i(0,a,0);
	   glVertex3i(900,a,0);
	}
	glEnd();

	//BOXES
	//if(play)
	{
	glBegin(GL_QUADS);
	{

	for(int j=0;j<8;j++)	//All Boxes
		{
			glVertex3f(xtest[j],ytest[j]-25,0);
			glVertex3f(xtest[j]+width[j],ytest[j]-25,0);
			glVertex3f(xtest[j]+width[j],ytest[j]+25,0);
			glVertex3f(xtest[j],ytest[j]+25,0);

		}

		glColor3f(0.30,0.70,0.30);
		glVertex3f(0,101,0);	// bottom area
		glVertex3f(windowWidth,101,0);
		glVertex3f(windowWidth,0,0);
		glVertex3f(0,0,0);

		glColor3f(0.10,0.80,0.50);
		glVertex3f(0,246,0);		// middle area
		glVertex3f(windowWidth,246,0);
		glVertex3f(windowWidth,306,0);
		glVertex3f(0,306,0);

		glColor3f(0.10,0.90,0.20);
		glVertex3f(0,502,0);	// top area
		glVertex3f(windowWidth,502,0);
		glVertex3f(windowWidth,windowHeight,0);
		glVertex3f(0,windowHeight,0);

		glColor3f(1.0,1.0,1.0);

	}
	glEnd();
	}

	int xtemp=x;
	if(attach==1)
	{
		x=xtest[attachedbox]+dx;
		//cout<<"xtest "<<xtest<<" x"<<x<<"\n";
	}

	//2player
	int xtemp1=x1;
	if(attach1==1)
	{
		x1=xtest[attachedbox1]+dx1;
	}

	//PLAYER1 BOX -- ORANGE wasd
	glColor3f(0.83,0.224,0.100);	// set color
	glBegin(GL_POLYGON);
	glVertex3f(x-15,y-15,0);
	glVertex3f(x+15,y-15,0);
	glVertex3f(x+15,y+15,0);
	glVertex3f(x-15,y+15,0);
	glEnd();

	//PLAYER2 BOX -- YELLOW ijkl
	glColor3f(0.1,.324,0.9);	// set color
	glBegin(GL_POLYGON);
	glVertex3f(x1-15,y1-15,0);
	glVertex3f(x1+15,y1-15,0);
	glVertex3f(x1+15,y1+15,0);
	glVertex3f(x1-15,y1+15,0);
	glEnd();

	glColor3f(1.0,1.0,0.2);

	//glLineStipple(1, 0x3F07);
	//glEnable(GL_LINE_STIPPLE);
	glBegin(GL_LINES);
	glVertex3f(0,560,0);
	glVertex3f(windowWidth,560,0);
	glEnd();
	//x=xtemp;

	glFlush();					// forces drawing to complete

}

void reshape(int w, int h)
{
	windowHeight=h;
	windowWidth=w;
glViewport(0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0,(GLdouble)w,0.0,(GLdouble)h,0.0,1.0);

}

void againDisplay()
{
		for(int j=0;j<8;j++)
		{
			xtest[j]=xtest[j]+speedtest[j];
		}

		// making boxes continues ones
		for(int j=0;j<8;j++)
		{
			if(xtest[j]>900)
			{xtest[j]=0;}
			else if(xtest[j]<0)
				{xtest[j]=900;}

		}

		//Game over conditions
		if((y>121-25 &&  y<246) || (y>306 && y<502))
		{
			if(attach==0)
			{
				cout<<"Game Over Player1\n";
				x=410,y=60;
			}
		}
		if((y>=246)&&(y<=306)||(y>802))	// middle area is safe zone
		{
			attach=1;
		}

		//Game over conditions for player2
		if((y1>121-25 &&  y1<246) || (y1>306 && y1<502))
		{
			if(attach1==0)
			{
				cout<<"Game Over Player2\n";
				x1=450,y1=60;
			}
		}
		if((y1>=246)&&(y1<=306)||(y1>802))	// middle area is safe zone
		{
			attach1=1;
		}

	glutPostRedisplay();
	 }

//For keyboard, p for pause
// 112 for 'p' and 32 for 'space'
void key(unsigned char key,int xm,int ym)
{
	//cout<<"KEY.... ";

	if(key==97)
	{x=x-9;	}
	else if(key==119)
		{y=y+9;}
	else if(key==100)
		{x=x+9; }
	else if(key==115)
		{y=y-9; }
	else if(key==112) 	// Game pause and play using key 'p'
	{ 	cout<<"Game Starts";
		if(play==0)
		{play=1; glutIdleFunc(againDisplay); if(y>=560 || y1>=560 ){x=410; y=60; x1=450; y1=60;}   }
		else {play=0; glutIdleFunc(NULL);}	// In  pause also players can move
	}

	//for player2
	if(key==106)
	{x1=x1-9;	}
	else if(key==105)
		{y1=y1+9;}
	else if(key==108)
		{x1=x1+9; }
	else if(key==107)
		{y1=y1-9; }
	/*else if(key==112) 	// Game pause and play using key 'p'
	{ 	cout<<"Game Starts";
		if(play==0)
		{play=1; glutIdleFunc(againDisplay); if(x>=560){x=450; y=60;}  }
		else {play=0; glutIdleFunc(NULL);}	// In  pause also players can move
	}*/

int flag=0;

	for(int j=0;j<8;j++)
	{	// that's the best place to make this...

		if ((y>=ytest[j]-25 && y<=ytest[j]+25 )&&( xtest[j]<=x && xtest[j]+width[j]>=x))
		{
			dx=x-xtest[j];
			if(dx<0) dx=-dx;
			cout<<"attach=1\n";
			attach=1;
			flag=1;
			attachedbox=j;
			cout<<"Player1 is on "<<j<<" - box. and attachedbox is "<<attachedbox<<"\n";

			break;

		}else {cout<<"y "<<y<<" ytest "<<ytest[j]<<" j "<<j<<"\n";}

	}

	if(flag==0) {attach=0; cout<<"x: "<<x<<" y: "<<y<<" and Attach1=0\n";}

	// for player2
	int flag1=0;

	for(int j=0;j<8;j++)
	{	// that's the best place to make this...

		if ((y1>=ytest[j]-25 && y1<=ytest[j]+25 )&&( xtest[j]<=x1 && xtest[j]+width[j]>=x1))
		{
			dx1=x1-xtest[j];
			if(dx1<0) dx1=-dx1;
			cout<<"attach1=1\n";
			attach1=1;
			flag1=1;
			attachedbox1=j;
			cout<<"Player2 is on "<<j<<" - box. and attachedbox is "<<attachedbox<<"\n";

			break;

		}else {cout<<"y1 "<<y1<<" ytest "<<ytest[j]<<" j "<<j<<"\n";}

	}

	if(flag1==0) {attach1=0; cout<<"x1: "<<x1<<" y1: "<<y1<<" and Attach1=0\n";}

	//Game win condition
		if(y>=560)
		{
			cout<<"PLAYER1 WON\n"; play=0; glutIdleFunc(NULL);
		}

		if(y1>=560)
		{
			cout<<"PLAYER2 WON\n"; play=0; glutIdleFunc(NULL);
		}

}

int main(int argc,char** argv)
{

	glutInit(&argc,argv);
	glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
	glutInitWindowSize(windowWidth,windowHeight);
	glutInitWindowPosition(40,20);
	glutCreateWindow("CrossJump");

	init();

	cout<<"CrossJump starts\n";

	glutReshapeFunc(reshape);	// when window is resized redraw the shape with same coordinates.
	glutDisplayFunc(display);
	//glutMouseFunc(mouse);
	glutKeyboardFunc(key);

	glutMainLoop();
	return 0;
}
<|endoftext|>


<commit_before>/*
 *    Copyright (c) <2002-2006> <Jean-Philippe Barrette-LaPierre>
 *
 *    Permission is hereby granted, free of charge, to any person obtaining
 *    a copy of this software and associated documentation files
 *    (cURLpp), to deal in the Software without restriction,
 *    including without limitation the rights to use, copy, modify, merge,
 *    publish, distribute, sublicense, and/or sell copies of the Software,
 *    and to permit persons to whom the Software is furnished to do so,
 *    subject to the following conditions:
 *
 *    The above copyright notice and this permission notice shall be included
 *    in all copies or substantial portions of the Software.
 *
 *    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 *    OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 *    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 *    IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 *    CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 *    TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 *    SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

#ifndef CURLPP_HPP
#define CURLPP_HPP

#define LIBCURLPP_VERSION "0.7.0-pre1"
#define LIBCURLPP_VERSION_NUM 0x000700

#include <string>
#include <curl/curl.h>

#include "dllfct.h"

namespace cURLpp
{
   /**
    * This function takes care of initializing cURLpp ( also libcURL). If you want
    * to cleanup cURL before your application quits just call cURLpp::terminate().
    * This function should only be called once (no matter how many threads or
    * libcurl sessions that'll be used) by every application that uses libcurl,
    * it will throw a logic_error if you call it twice.
    *
    * The flags option is a bit pattern that tells  libcurl  exact what  features
    * to init, as described below. Set the desired bits by ORing the values together.
    *
    *  CURL_GLOBAL_ALL
    *  Initialize  everything  possible.  This  sets all known bits.
    *
    *  CURL_GLOBAL_SSL
    *  Initialize SSL
    *
    *  CURL_GLOBAL_WIN32
    *  Initialize  the  Win32  socket  libraries.
    *
    *  CURL_GLOBAL_NOTHING
    *  Initialise nothing extra. This sets no bit.
    *
    * NOTE: you cannot call this function twice without first terminating it first.
    * it will throw a logic_error if you do this.
    */
  void CURLPPAPI initialize(long flags = CURL_GLOBAL_ALL);

  /**
   * This function takes care of cleaning up cURLpp ( also libcURL). See
   * cURLpp::initialize( long flags ) for momre documentation.
   *
   * NOTE: you cannot call this function if cURLpp is not loaded. it will throw a
   * logic_error if you do this.
   */
  void CURLPPAPI terminate();

  /**
   * This class takes care of initialization and cleaning up cURLpp ( also libcURL )
   * (it will call cURLpp:terminate() in his destructor). If you want to be sure that
   * cURLpp is cleanup after you reached the end of scope of a specific function using
   * cURLpp, instatiate this class. This function call cURLpp::initialize() in his
   * constructor, so you don't have to call it by yourself, when you have decided to
   * use it.
   *
   * See cURLpp::initialize( long flags ) and cURLpp:terminate() for more documentation.
   */
  class CURLPPAPI Cleanup
  {
  public:
    Cleanup();
    ~Cleanup();
  };

  /**
   * This  function  will  convert  the given input string to an URL encoded
   * string and return that as a new allocated string. All input  characters
   * that  are  not a-z, A-Z or 0-9 will be converted to their "URL escaped"
   * version (%NN where NN is a two-digit hexadecimal number).
   */
  std::string CURLPPAPI escape( const std::string& url );

  /**
   * This  function  will  convert  the  given  URL encoded input string to a
   * "plain string" and return that as a new allocated string. All input
   * characters that are URL encoded (%XX) where XX is a two-digit
   * hexadecimal number, or +) will be converted to their plain text versions
   * (up to a ? letter, no + letters to the right of a ? letter will be
   * converted).
   */
  std::string CURLPPAPI unescape( const std::string &url );

  /**
   * this is  a portable wrapper for the getenv() function, meant to emulate
   * its behaviour and provide an identical interface for all operating
   * systems libcurl builds on (including win32). Under unix operating
   * systems, there isn't any point in returning an allocated memory,
   * although other systems won't work  properly if this isn't done. The unix
   * implementation thus have to suffer slightly from the drawbacks of other
   * systems.
   */
  std::string CURLPPAPI getenv( const std::string &name );

  /**
   * Returns  a  human readable string with the version number of libcurl and
   * some of its important components  (like  OpenSSL version).
   *
   * Note:  this  returns  the  actual running lib's version, you might have
   * installed a newer lib's include files in your system  which may turn
   * your LIBCURL_VERSION #define value to differ from this result.
   */
  std::string CURLPPAPI libcurlVersion();

  /**
   * This function returns the number of  seconds  since  January 1st  1970,
   * for the date and time that the datestring parameter specifies. The now
   * parameter is there  and  should  hold the current time to allow the
   * datestring to specify relative dates/times. Read further in the date
   * string parser  section below.
   *
   * PARSING DATES AND TIMES
   * A  "date" is a string, possibly empty, containing many items separated
   * by whitespace.  The whitespace may be omitted when no  ambiguity
   * arises.  The empty string means the beginning of today (i.e., midnight).
   * Order of the  items  is  immaterial.  A date string may contain many
   * flavors of items:
   *
   * calendar date items
   * This can be specified in a number of different ways. Including
   * 1970-09-17, 70-9-17, 70-09-17, 9/17/72, 24 September 1972, 24 Sept 72,
   * 24 Sep 72, Sep 24, 1972, 24-sep-72, 24sep72.  The year can also  be
   * omitted, for example: 9/17 or "sep 17".
   *
   * time of the day items
   * This  string specifies the time on a given day. Syntax  supported
   * includes:  18:19:0,  18:19,  6:19pm, 18:19-0500 (for specifying the time
   * zone as well).
   *
   * time zone items
   * Specifies  international  time zone. There are a few acronyms
   * supported,  but  in  general  you   should instead  use  the specific
   * realtive time compared to UTC. Supported formats include: -1200, MST,
   * +0100.
   *
   * day of the week items
   * Specifies a day of the week. If  this  is  mentioned alone it means that
   * day of the week in the future. Days  of  the week may be spelled out in
   * full: `Sunday', `Monday', etc or they may  be  abbreviated  to their
   * first three letters, optionally followed by a period.  The special
   * abbreviations `Tues' for `Tuesday', `Wednes' for `Wednesday' and `Thur'
   * or `Thurs' for `Thursday' are also allowed. A number may precede a day
   * of the week item to  move forward  supplementary  weeks.   It  is best
   * used in expression like `third monday'.   In  this  context, `last  DAY'
   * or  `next DAY' is also acceptable; they move one week before or after
   * the day  that  DAY  by itself would represent.
   *
   * relative items
   * A  relative item adjusts a date (or the current date if  none)  forward
   * or  backward.   Example   syntax includes:  "1  year",  "1  year  ago",
   * "2 days", "4 weeks". The string `tomorrow' is worth one day in the
   * future (equivalent  to  `day'),  the  string `yesterday' is worth one
   * day in the past (equivalent to `day ago').
   *
   * pure numbers
   * If the decimal number is of the form YYYYMMDD and no other calendar date
   * item appears before  it  in  the date  string,  then  YYYY is read as
   * the year, MM as the month number and DD as the day of the month, for the
   * specified calendar date.
   */
  time_t CURLPPAPI getdate( const std::string&date, time_t *now = 0 );

}

#endif
<commit_msg>Started the 0.7.1 development<commit_after>/*
 *    Copyright (c) <2002-2006> <Jean-Philippe Barrette-LaPierre>
 *
 *    Permission is hereby granted, free of charge, to any person obtaining
 *    a copy of this software and associated documentation files
 *    (cURLpp), to deal in the Software without restriction,
 *    including without limitation the rights to use, copy, modify, merge,
 *    publish, distribute, sublicense, and/or sell copies of the Software,
 *    and to permit persons to whom the Software is furnished to do so,
 *    subject to the following conditions:
 *
 *    The above copyright notice and this permission notice shall be included
 *    in all copies or substantial portions of the Software.
 *
 *    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 *    OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 *    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 *    IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 *    CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 *    TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 *    SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

#ifndef CURLPP_HPP
#define CURLPP_HPP

#define LIBCURLPP_VERSION "0.7.1-devel"
#define LIBCURLPP_VERSION_NUM 0x000700

#include <string>
#include <curl/curl.h>

#include "dllfct.h"

namespace cURLpp
{
   /**
    * This function takes care of initializing cURLpp ( also libcURL). If you want
    * to cleanup cURL before your application quits just call cURLpp::terminate().
    * This function should only be called once (no matter how many threads or
    * libcurl sessions that'll be used) by every application that uses libcurl,
    * it will throw a logic_error if you call it twice.
    *
    * The flags option is a bit pattern that tells  libcurl  exact what  features
    * to init, as described below. Set the desired bits by ORing the values together.
    *
    *  CURL_GLOBAL_ALL
    *  Initialize  everything  possible.  This  sets all known bits.
    *
    *  CURL_GLOBAL_SSL
    *  Initialize SSL
    *
    *  CURL_GLOBAL_WIN32
    *  Initialize  the  Win32  socket  libraries.
    *
    *  CURL_GLOBAL_NOTHING
    *  Initialise nothing extra. This sets no bit.
    *
    * NOTE: you cannot call this function twice without first terminating it first.
    * it will throw a logic_error if you do this.
    */
  void CURLPPAPI initialize(long flags = CURL_GLOBAL_ALL);

  /**
   * This function takes care of cleaning up cURLpp ( also libcURL). See
   * cURLpp::initialize( long flags ) for momre documentation.
   *
   * NOTE: you cannot call this function if cURLpp is not loaded. it will throw a
   * logic_error if you do this.
   */
  void CURLPPAPI terminate();

  /**
   * This class takes care of initialization and cleaning up cURLpp ( also libcURL )
   * (it will call cURLpp:terminate() in his destructor). If you want to be sure that
   * cURLpp is cleanup after you reached the end of scope of a specific function using
   * cURLpp, instatiate this class. This function call cURLpp::initialize() in his
   * constructor, so you don't have to call it by yourself, when you have decided to
   * use it.
   *
   * See cURLpp::initialize( long flags ) and cURLpp:terminate() for more documentation.
   */
  class CURLPPAPI Cleanup
  {
  public:
    Cleanup();
    ~Cleanup();
  };

  /**
   * This  function  will  convert  the given input string to an URL encoded
   * string and return that as a new allocated string. All input  characters
   * that  are  not a-z, A-Z or 0-9 will be converted to their "URL escaped"
   * version (%NN where NN is a two-digit hexadecimal number).
   */
  std::string CURLPPAPI escape( const std::string& url );

  /**
   * This  function  will  convert  the  given  URL encoded input string to a
   * "plain string" and return that as a new allocated string. All input
   * characters that are URL encoded (%XX) where XX is a two-digit
   * hexadecimal number, or +) will be converted to their plain text versions
   * (up to a ? letter, no + letters to the right of a ? letter will be
   * converted).
   */
  std::string CURLPPAPI unescape( const std::string &url );

  /**
   * this is  a portable wrapper for the getenv() function, meant to emulate
   * its behaviour and provide an identical interface for all operating
   * systems libcurl builds on (including win32). Under unix operating
   * systems, there isn't any point in returning an allocated memory,
   * although other systems won't work  properly if this isn't done. The unix
   * implementation thus have to suffer slightly from the drawbacks of other
   * systems.
   */
  std::string CURLPPAPI getenv( const std::string &name );

  /**
   * Returns  a  human readable string with the version number of libcurl and
   * some of its important components  (like  OpenSSL version).
   *
   * Note:  this  returns  the  actual running lib's version, you might have
   * installed a newer lib's include files in your system  which may turn
   * your LIBCURL_VERSION #define value to differ from this result.
   */
  std::string CURLPPAPI libcurlVersion();

  /**
   * This function returns the number of  seconds  since  January 1st  1970,
   * for the date and time that the datestring parameter specifies. The now
   * parameter is there  and  should  hold the current time to allow the
   * datestring to specify relative dates/times. Read further in the date
   * string parser  section below.
   *
   * PARSING DATES AND TIMES
   * A  "date" is a string, possibly empty, containing many items separated
   * by whitespace.  The whitespace may be omitted when no  ambiguity
   * arises.  The empty string means the beginning of today (i.e., midnight).
   * Order of the  items  is  immaterial.  A date string may contain many
   * flavors of items:
   *
   * calendar date items
   * This can be specified in a number of different ways. Including
   * 1970-09-17, 70-9-17, 70-09-17, 9/17/72, 24 September 1972, 24 Sept 72,
   * 24 Sep 72, Sep 24, 1972, 24-sep-72, 24sep72.  The year can also  be
   * omitted, for example: 9/17 or "sep 17".
   *
   * time of the day items
   * This  string specifies the time on a given day. Syntax  supported
   * includes:  18:19:0,  18:19,  6:19pm, 18:19-0500 (for specifying the time
   * zone as well).
   *
   * time zone items
   * Specifies  international  time zone. There are a few acronyms
   * supported,  but  in  general  you   should instead  use  the specific
   * realtive time compared to UTC. Supported formats include: -1200, MST,
   * +0100.
   *
   * day of the week items
   * Specifies a day of the week. If  this  is  mentioned alone it means that
   * day of the week in the future. Days  of  the week may be spelled out in
   * full: `Sunday', `Monday', etc or they may  be  abbreviated  to their
   * first three letters, optionally followed by a period.  The special
   * abbreviations `Tues' for `Tuesday', `Wednes' for `Wednesday' and `Thur'
   * or `Thurs' for `Thursday' are also allowed. A number may precede a day
   * of the week item to  move forward  supplementary  weeks.   It  is best
   * used in expression like `third monday'.   In  this  context, `last  DAY'
   * or  `next DAY' is also acceptable; they move one week before or after
   * the day  that  DAY  by itself would represent.
   *
   * relative items
   * A  relative item adjusts a date (or the current date if  none)  forward
   * or  backward.   Example   syntax includes:  "1  year",  "1  year  ago",
   * "2 days", "4 weeks". The string `tomorrow' is worth one day in the
   * future (equivalent  to  `day'),  the  string `yesterday' is worth one
   * day in the past (equivalent to `day ago').
   *
   * pure numbers
   * If the decimal number is of the form YYYYMMDD and no other calendar date
   * item appears before  it  in  the date  string,  then  YYYY is read as
   * the year, MM as the month number and DD as the day of the month, for the
   * specified calendar date.
   */
  time_t CURLPPAPI getdate( const std::string&date, time_t *now = 0 );

}

#endif
<|endoftext|>


<commit_before>/*********************************************************************/
/** setvisu.cpp: initialisations de l'ecran d'affichage du composant **/
/*********************************************************************/

#include "fctsys.h"
#include "common.h"
#include "class_drawpanel.h"
#include "id.h"

#include "bitmaps.h"
#include "cvpcb.h"
#include "protos.h"
#include "cvstruct.h"

/*
 * NOTE: There is something in 3d_viewer.h that causes a compiler error in
 *       <boost/foreach.hpp> in Linux so move it after cvpcb.h where it is
 *       included to prevent the error from occuring.
 */
#include "3d_viewer.h"

/*
 * Create or Update the frame showing the current highlighted footprint
 * and (if showed) the 3D display frame
 */
void WinEDA_CvpcbFrame::CreateScreenCmp()
{
    wxString msg, FootprintName;
    bool     IsNew = FALSE;

    FootprintName = m_FootprintList->GetSelectedFootprint();

    if( DrawFrame == NULL )
    {
        DrawFrame = new WinEDA_DisplayFrame( this, _( "Module" ),
                                             wxPoint( 0, 0 ),
                                             wxSize( 600, 400 ),
                                             KICAD_DEFAULT_DRAWFRAME_STYLE |
                                             wxFRAME_FLOAT_ON_PARENT );
        IsNew = TRUE;
        DrawFrame->Show( TRUE );
    }

    if( !FootprintName.IsEmpty() )
    {
        msg = _( "Footprint: " ) + FootprintName;
        DrawFrame->SetTitle( msg );
        FOOTPRINT* Module = GetModuleDescrByName( FootprintName, m_footprints );
        msg = _( "Lib: " );

        if( Module )
            msg += Module->m_LibName;
        else
            msg += wxT( "???" );

        DrawFrame->SetStatusText( msg, 0 );

        if( DrawFrame->GetBoard()->m_Modules.GetCount() )
        {
            // there is only one module in the list
            DrawFrame->GetBoard()->m_Modules.DeleteAll();
        }

        MODULE* mod = DrawFrame->Get_Module( FootprintName );
        if( mod )
            DrawFrame->GetBoard()->m_Modules.PushBack( mod );

        DrawFrame->Zoom_Automatique( FALSE );
        DrawFrame->UpdateStatusBar();    /* Display new cursor coordinates and zoom value */
        if( DrawFrame->m_Draw3DFrame )
            DrawFrame->m_Draw3DFrame->NewDisplay();
    }
    else if( !IsNew )
    {
        DrawFrame->Refresh();
        if( DrawFrame->m_Draw3DFrame )
            DrawFrame->m_Draw3DFrame->NewDisplay();
    }
}

/*
 * Draws the current highlighted footprint.
 */
void WinEDA_DisplayFrame::RedrawActiveWindow( wxDC* DC, bool EraseBg )
{
    if( !GetBoard() )
        return;

    ActiveScreen = (PCB_SCREEN*) GetScreen();

    if( EraseBg )
        DrawPanel->EraseScreen( DC );

    DrawPanel->DrawBackGround( DC );
    GetBoard()->Draw( DrawPanel, DC, GR_COPY );

    MODULE* Module = GetBoard()->m_Modules;
    if ( Module )
        Module->DisplayInfo( this );
    DrawPanel->Trace_Curseur( DC );
}

/*
 * Redraw the BOARD items but not cursors, axis or grid.
 */
void BOARD::Draw( WinEDA_DrawPanel* aPanel, wxDC* DC,
                  int aDrawMode, const wxPoint& offset )
{
    if( m_Modules )
    {
        m_Modules->Draw( aPanel, DC, GR_COPY );
    }
}
<commit_msg>fixed: refresh problem in display footprint window<commit_after>/*********************************************************************/
/** setvisu.cpp: initialisations de l'ecran d'affichage du composant **/
/*********************************************************************/

#include "fctsys.h"
#include "common.h"
#include "class_drawpanel.h"
#include "id.h"

#include "bitmaps.h"
#include "cvpcb.h"
#include "protos.h"
#include "cvstruct.h"

/*
 * NOTE: There is something in 3d_viewer.h that causes a compiler error in
 *       <boost/foreach.hpp> in Linux so move it after cvpcb.h where it is
 *       included to prevent the error from occuring.
 */
#include "3d_viewer.h"

/*
 * Create or Update the frame showing the current highlighted footprint
 * and (if showed) the 3D display frame
 */
void WinEDA_CvpcbFrame::CreateScreenCmp()
{
    wxString msg, FootprintName;
    bool     IsNew = FALSE;

    FootprintName = m_FootprintList->GetSelectedFootprint();

    if( DrawFrame == NULL )
    {
        DrawFrame = new WinEDA_DisplayFrame( this, _( "Module" ),
                                             wxPoint( 0, 0 ),
                                             wxSize( 600, 400 ),
                                             KICAD_DEFAULT_DRAWFRAME_STYLE |
                                             wxFRAME_FLOAT_ON_PARENT );
        IsNew = TRUE;
        DrawFrame->Show( TRUE );
    }

    if( !FootprintName.IsEmpty() )
    {
        msg = _( "Footprint: " ) + FootprintName;
        DrawFrame->SetTitle( msg );
        FOOTPRINT* Module = GetModuleDescrByName( FootprintName, m_footprints );
        msg = _( "Lib: " );

        if( Module )
            msg += Module->m_LibName;
        else
            msg += wxT( "???" );

        DrawFrame->SetStatusText( msg, 0 );

        if( DrawFrame->GetBoard()->m_Modules.GetCount() )
        {
            // there is only one module in the list
            DrawFrame->GetBoard()->m_Modules.DeleteAll();
        }

        MODULE* mod = DrawFrame->Get_Module( FootprintName );
        if( mod )
            DrawFrame->GetBoard()->m_Modules.PushBack( mod );

        DrawFrame->Zoom_Automatique( FALSE );
        DrawFrame->DrawPanel->Refresh();
        DrawFrame->UpdateStatusBar();    /* Display new cursor coordinates and zoom value */
        if( DrawFrame->m_Draw3DFrame )
            DrawFrame->m_Draw3DFrame->NewDisplay();
    }
    else if( !IsNew )
    {
        DrawFrame->Refresh();
        if( DrawFrame->m_Draw3DFrame )
            DrawFrame->m_Draw3DFrame->NewDisplay();
    }
}

/*
 * Draws the current highlighted footprint.
 */
void WinEDA_DisplayFrame::RedrawActiveWindow( wxDC* DC, bool EraseBg )
{
    if( !GetBoard() )
        return;

    ActiveScreen = (PCB_SCREEN*) GetScreen();

    if( EraseBg )
        DrawPanel->EraseScreen( DC );

    DrawPanel->DrawBackGround( DC );
    GetBoard()->Draw( DrawPanel, DC, GR_COPY );

    MODULE* Module = GetBoard()->m_Modules;
    if ( Module )
        Module->DisplayInfo( this );
    DrawPanel->Trace_Curseur( DC );
}

/*
 * Redraw the BOARD items but not cursors, axis or grid.
 */
void BOARD::Draw( WinEDA_DrawPanel* aPanel, wxDC* DC,
                  int aDrawMode, const wxPoint& offset )
{
    if( m_Modules )
    {
        m_Modules->Draw( aPanel, DC, GR_COPY );
    }
}
<|endoftext|>


<commit_before><commit_msg>Fix typo<commit_after><|endoftext|>


<commit_before>/* You can use one of the both BSD 3-Clause License or GNU Lesser General Public License 3.0 for this source. */
/* BSD 3-Clause License:
 * Copyright (c) 2013 - 2021, kazunobu watatsu.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
 *
 *    Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
 *    Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation or other materials provided with the distribution.
 *    Neither the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#if !defined(_LINEAR_OPT_)

using std::cerr;
using std::flush;

template <typename T> SimpleVector<T> inner(const SimpleMatrix<T>& A, const SimpleVector<T>& bl, const SimpleVector<T>& bu) {
#if defined(_FLOAT_BITS_)
  static const auto epsilon(T(1) >> int64_t(mybits - 1));
#else
  static const auto epsilon(std::numeric_limits<T>::epsilon());
#endif
  assert(A.rows() == bl.size() && A.rows() == bu.size() &&
         0 < A.cols() && 0 < A.rows());
  // cout << A << endl << b << endl << c.transpose() << endl;
  cerr << " (" << A.rows() << ", " << A.cols() << ")";
  // bu - bb == A, bl - bb == - A <=> bu - bl == 2 A
  const auto bb(bu - (bu - bl) / T(2));
  const auto upper(bu - bb);
  SimpleMatrix<T> AA(A.rows() * 2 - 1, A.cols() + 1);
  SimpleVector<T> one(AA.rows());
  std::vector<std::pair<T, int> > fidx;
  fidx.reserve(A.rows());
  for(int i = 0; i < A.rows(); i ++) {
    for(int j = 0; j < A.cols(); j ++)
      AA(i, j) = A(i, j);
    AA(i, A.cols()) = - bb[i];
    if(upper[i] == T(0)) {
      const auto n2(AA.row(i).dot(AA.row(i)));
      if(n2 != T(0)) {
        fidx.emplace_back(std::make_pair(- T(1), i));
        AA.row(i) /= sqrt(n2);
      }
    } else {
      AA.row(i) /= upper[i];
      AA(i, A.cols()) -= T(1);
    }
    one[i] = T(1);
    assert(isfinite(AA.row(i).dot(AA.row(i))));
    if(A.rows() - 1 <= i) break;
    AA.row(i + A.rows()) = - AA.row(i);
    one[i + A.rows()] = T(1);
  }
  SimpleMatrix<T> Pt(AA.cols(), AA.rows());
  for(int i = 0; i < Pt.rows(); i ++)
    for(int j = 0; j < Pt.cols(); j ++)
      Pt(i, j) = T(0);
  std::vector<int> residue;
  for(int i = 0; i < AA.cols(); i ++) {
    const auto Atrowi(AA.col(i));
    const auto work(Atrowi - Pt.projectionPt(Atrowi));
    const auto n2(work.dot(work));
    if(n2 <= epsilon) {
      residue.emplace_back(i);
      continue;
    }
    Pt.row(i) = work / sqrt(n2);
  }
  int ii(0);
  for(int j = 0; j < Pt.cols() && ii < residue.size(); j ++) {
    SimpleVector<T> ek(Pt.cols());
    for(int k = 0; k < Pt.cols(); k ++)
      ek[k] = j == k ? T(1) : T(0);
    ek -= Pt.projectionPt(ek);
    const auto n2(ek.dot(ek));
    if(n2 <= epsilon) continue;
    Pt.row(residue[ii ++]) = ek / sqrt(n2);
  }
  assert(residue.size() <= ii);
  cerr << "Q" << flush;
  const auto R(Pt * AA);
  const auto done(R.solve(Pt * one));
  cerr << "R" << flush;
  const auto on(Pt.projectionPt(one));
  fidx.reserve(fidx.size() + on.size());
  for(int i = 0; i < on.size(); i ++)
    fidx.emplace_back(std::make_pair(abs(on[i]), i));
  std::sort(fidx.begin(), fidx.end());
  // worst case O(mn^2) over all in this function,
  // we can make this function better case it's O(n^3) but not now.
  for(int n_fixed = 0, idx = 0; n_fixed < Pt.rows() - 1 && idx < fidx.size(); n_fixed ++, idx ++) {
    const auto& iidx(fidx[idx].second);
    const auto  orth(Pt.col(iidx));
    const auto  norm2orth(orth.dot(orth));
    if(norm2orth <= epsilon) {
      n_fixed --;
      continue;
    }
#if defined(_OPENMP)
#pragma omp parallel for schedule(static, 1)
#endif
    for(int j = 0; j < Pt.cols(); j ++)
      Pt.setCol(j, Pt.col(j) - orth * Pt.col(j).dot(orth) / norm2orth);
  }
  cerr << "G" << flush;
  auto rvec(R.solve(Pt * one));
  cerr << "I" << flush;
  SimpleVector<T> rrvec(rvec.size() - 1);
  // | [A, - bb == - upper] [x t] | <= epsilon 1.
  for(int i = 0; i < rrvec.size(); i ++)
    rrvec[i] = rvec[i] * done[done.size() - 1] - done[i] * rvec[rvec.size() - 1];
  return rrvec;
}

#define _LINEAR_OPT_
#endif

<commit_msg>ok konbu.hh.<commit_after>/* You can use one of the both BSD 3-Clause License or GNU Lesser General Public License 3.0 for this source. */
/* BSD 3-Clause License:
 * Copyright (c) 2013 - 2021, kazunobu watatsu.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
 *
 *    Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
 *    Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation or other materials provided with the distribution.
 *    Neither the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#if !defined(_LINEAR_OPT_)

using std::cerr;
using std::flush;

template <typename T> SimpleVector<T> inner(const SimpleMatrix<T>& A, const SimpleVector<T>& bl, const SimpleVector<T>& bu) {
#if defined(_FLOAT_BITS_)
  static const auto epsilon(T(1) >> int64_t(mybits - 1));
#else
  static const auto epsilon(std::numeric_limits<T>::epsilon());
#endif
  assert(A.rows() == bl.size() && A.rows() == bu.size() &&
         0 < A.cols() && 0 < A.rows());
  // cout << A << endl << b << endl << c.transpose() << endl;
  cerr << " (" << A.rows() << ", " << A.cols() << ")";
  // bu - bb == A, bl - bb == - A <=> bu - bl == 2 A
  const auto bb(bu - (bu - bl) / T(2));
  const auto upper(bu - bb);
  SimpleMatrix<T> AA(A.rows() * 2 - 1, A.cols() + 1);
  SimpleVector<T> one(AA.rows());
  std::vector<std::pair<T, int> > fidx;
  fidx.reserve(A.rows());
  for(int i = 0; i < A.rows(); i ++) {
    for(int j = 0; j < A.cols(); j ++)
      AA(i, j) = A(i, j);
    AA(i, A.cols()) = - bb[i];
    if(upper[i] == T(0)) {
      const auto n2(AA.row(i).dot(AA.row(i)));
      if(n2 != T(0)) {
        fidx.emplace_back(std::make_pair(- T(1), i));
        AA.row(i) /= sqrt(n2);
      }
    } else {
      AA.row(i) /= upper[i];
      AA(i, A.cols()) -= T(1);
    }
    one[i] = T(1);
    assert(isfinite(AA.row(i).dot(AA.row(i))));
    if(A.rows() - 1 <= i) break;
    AA.row(i + A.rows()) = - AA.row(i);
    if(fidx.size() && fidx[fidx.size() - 1].second == i)
      AA(i + A.rows(), A.cols()) += T(2);
    one[i + A.rows()] = T(1);
  }
  SimpleMatrix<T> Pt(AA.cols(), AA.rows());
  for(int i = 0; i < Pt.rows(); i ++)
    for(int j = 0; j < Pt.cols(); j ++)
      Pt(i, j) = T(0);
  std::vector<int> residue;
  for(int i = 0; i < AA.cols(); i ++) {
    const auto Atrowi(AA.col(i));
    const auto work(Atrowi - Pt.projectionPt(Atrowi));
    const auto n2(work.dot(work));
    if(n2 <= epsilon) {
      residue.emplace_back(i);
      continue;
    }
    Pt.row(i) = work / sqrt(n2);
  }
  int ii(0);
  for(int j = 0; j < Pt.cols() && ii < residue.size(); j ++) {
    SimpleVector<T> ek(Pt.cols());
    for(int k = 0; k < Pt.cols(); k ++)
      ek[k] = j == k ? T(1) : T(0);
    ek -= Pt.projectionPt(ek);
    const auto n2(ek.dot(ek));
    if(n2 <= epsilon) continue;
    Pt.row(residue[ii ++]) = ek / sqrt(n2);
  }
  assert(residue.size() <= ii);
  cerr << "Q" << flush;
  const auto R(Pt * AA);
  const auto done(R.solve(Pt * one));
  cerr << "R" << flush;
  const auto on(Pt.projectionPt(one));
  fidx.reserve(fidx.size() + on.size());
  for(int i = 0; i < on.size(); i ++)
    fidx.emplace_back(std::make_pair(abs(on[i]), i));
  std::sort(fidx.begin(), fidx.end());
  // worst case O(mn^2) over all in this function,
  // we can make this function better case it's O(n^3) but not now.
  for(int n_fixed = 0, idx = 0; n_fixed < Pt.rows() - 1 && idx < fidx.size(); n_fixed ++, idx ++) {
    const auto& iidx(fidx[idx].second);
    const auto  orth(Pt.col(iidx));
    const auto  norm2orth(orth.dot(orth));
    if(norm2orth <= epsilon) {
      n_fixed --;
      continue;
    }
#if defined(_OPENMP)
#pragma omp parallel for schedule(static, 1)
#endif
    for(int j = 0; j < Pt.cols(); j ++)
      Pt.setCol(j, Pt.col(j) - orth * Pt.col(j).dot(orth) / norm2orth);
  }
  cerr << "G" << flush;
  auto rvec(R.solve(Pt * one));
  cerr << "I" << flush;
  SimpleVector<T> rrvec(rvec.size() - 1);
  // | [A, - bb == - upper] [x t] | <= epsilon 1.
  for(int i = 0; i < rrvec.size(); i ++)
    rrvec[i] = rvec[i] * done[done.size() - 1] / rvec[rvec.size() - 1] - done[i];
  return rrvec;
}

#define _LINEAR_OPT_
#endif

<|endoftext|>


<commit_before>#pragma once

namespace principia {
namespace geometry {

template<typename Scalar, typename Frame>
Multivector<Scalar, Frame, 1>::Multivector(R3Element<Scalar> const& coordinates)
    : coordinates(coordinates) {};

template<typename Scalar, typename Frame>
Multivector<Scalar, Frame, 2>::Multivector(R3Element<Scalar> const& coordinates)
    : coordinates(coordinates) {};

template<typename Scalar, typename Frame>
Multivector<Scalar, Frame, 3>::Multivector(Scalar const& coordinates)
    : coordinates(coordinates) {};

template<typename LeftScalar, typename RightScalar, typename Frame>
inline quantities::Product<LeftScalar, RightScalar> InnerProduct(
    Vector<LeftScalar, Frame> const& left,
    Vector<RightScalar, Frame> const& right) {
  return Dot(left.coordinates, right.coordinates);
}
template<typename LeftScalar, typename RightScalar, typename Frame>
inline quantities::Product<LeftScalar, RightScalar> InnerProduct(
    Bivector<LeftScalar, Frame> const& left,
    Bivector<RightScalar, Frame> const& right) {
  return Dot(left.coordinates, right.coordinates);
}
template<typename LeftScalar, typename RightScalar, typename Frame>
inline quantities::Product<LeftScalar, RightScalar> InnerProduct(
    Trivector<LeftScalar, Frame> const& left,
    Trivector<RightScalar, Frame> const& right) {
  return left.coordinates * right.coordinates;
}

template<typename LeftScalar, typename RightScalar, typename Frame>
inline Bivector<quantities::Product<LeftScalar, RightScalar>,
                Frame> Wedge(Vector<LeftScalar, Frame> const& left,
                             Vector<RightScalar, Frame> const& right) {
  return Bivector<quantities::Product<LeftScalar, RightScalar>,
                   Frame>(Cross(left.coordinates, right.coordinates));
}
template<typename LeftScalar, typename RightScalar, typename Frame>
inline Trivector<quantities::Product<LeftScalar, RightScalar>,
                 Frame> Wedge(Bivector<LeftScalar, Frame> const& left,
                              Vector<RightScalar, Frame> const& right) {
  return Trivector<quantities::Product<LeftScalar, RightScalar>,
                   Frame>(Dot(left.coordinates, right.coordinates));
}
template<typename LeftScalar, typename RightScalar, typename Frame>
inline Trivector<quantities::Product<LeftScalar, RightScalar>,
                 Frame> Wedge(Vector<LeftScalar, Frame> const& left,
                              Bivector<RightScalar, Frame> const& right) {
  return Trivector<quantities::Product<LeftScalar, RightScalar>,
                   Frame>(Dot(left.coordinates, right.coordinates));
}

// Lie bracket on V ^ V = so(V).
template<typename LeftScalar, typename RightScalar, typename Frame>
inline Bivector<quantities::Product<LeftScalar, RightScalar>,
                Frame> Commutator(Bivector<LeftScalar, Frame> const& left,
                                  Bivector<RightScalar, Frame> const& right) {
  return Bivector<quantities::Product<LeftScalar, RightScalar>,
                  Frame>(Cross(left.coordinates, right.coordinates));
}

// Left action of V ^ V = so(V) on V.
template<typename LeftScalar, typename RightScalar, typename Frame>
inline Vector<quantities::Product<LeftScalar, RightScalar>,
              Frame> operator*(Bivector<LeftScalar, Frame> const& left,
                               Vector<RightScalar, Frame> const& right) {
  return Vector<quantities::Product<LeftScalar, RightScalar>,
                Frame>(Cross(left.coordinates, right.coordinates));
}

// Right action of V ^ V = so(V) on V* = V.
template<typename LeftScalar, typename RightScalar, typename Frame>
inline Vector<quantities::Product<LeftScalar, RightScalar>,
              Frame> operator*(Vector<LeftScalar, Frame> const& left,
                               Bivector<RightScalar, Frame> const& right) {
  return Vector<quantities::Product<LeftScalar, RightScalar>,
                Frame>(Cross(left.coordinates, right.coordinates));
}

template<typename Scalar, typename Frame, unsigned int Rank>
inline Multivector<Scalar, Frame, Rank> operator+(
    Multivector<Scalar, Frame, Rank> const& right) {
  return Multivector<Scalar, Frame, Rank>(+right.coordinates);
}
template<typename Scalar, typename Frame, unsigned int Rank>
inline Multivector<Scalar, Frame, Rank> operator-(
    Multivector<Scalar, Frame, Rank> const& right) {
  return Multivector<Scalar, Frame, Rank>(-right.coordinates);
}

template<typename Scalar, typename Frame, unsigned int Rank>
inline Multivector<Scalar, Frame, Rank> operator+(
    Multivector<Scalar, Frame, Rank> const& left,
    Multivector<Scalar, Frame, Rank> const& right) {
  return Multivector<Scalar, Frame, Rank>(left.coordinates + right.coordinates);
}
template<typename Scalar, typename Frame, unsigned int Rank>
inline Multivector<Scalar, Frame, Rank> operator-(
    Multivector<Scalar, Frame, Rank> const& left,
    Multivector<Scalar, Frame, Rank> const& right) {
  return Multivector<Scalar, Frame, Rank>(left.coordinates - right.coordinates);
}

template<typename Scalar, typename Frame, unsigned int Rank>
inline Multivector<Scalar, Frame, Rank> operator*(
    quantities::Dimensionless const& left,
    Multivector<Scalar, Frame, Rank> const& right) {
  return Multivector<Scalar, Frame, Rank>(left * right.coordinates);
}

template<typename Scalar, typename Frame, unsigned int Rank>
inline Multivector<Scalar, Frame, Rank> operator*(
    Multivector<Scalar, Frame, Rank> const& left,
    quantities::Dimensionless const& right) {
  return Multivector<Scalar, Frame, Rank>(left.coordinates * right);
}

template<typename Scalar, typename Frame, unsigned int Rank>
inline Multivector<Scalar, Frame, Rank> operator/(
    Multivector<Scalar, Frame, Rank> const& left,
    quantities::Dimensionless const& right) {
  return Multivector<Scalar, Frame, Rank>(left.coordinates / right);
}

template<typename DLeft, typename RightScalar, typename Frame,
         unsigned int Rank>
inline Multivector<
    quantities::Product<quantities::Quantity<DLeft>, RightScalar>,
    Frame, Rank>
operator*(quantities::Quantity<DLeft> const& left,
          Multivector<RightScalar, Frame, Rank> const& right) {
  return Multivector<
      quantities::Product<quantities::Quantity<DLeft>, RightScalar>,
      Frame, Rank>(left * right.coordinates);
}

template<typename LeftScalar, typename DRight, typename Frame,
         unsigned int Rank>
inline Multivector<
    quantities::Product<LeftScalar, quantities::Quantity<DRight>>,
    Frame, Rank>
operator*(Multivector<LeftScalar, Frame, Rank> const& left,
          quantities::Quantity<DRight> const& right) {
  return Multivector<
      quantities::Product<LeftScalar, quantities::Quantity<DRight>>,
      Frame, Rank>(left.coordinates * right);
}

template<typename LeftScalar, typename DRight, typename Frame,
         unsigned int Rank>
inline Multivector<
    quantities::Quotient<LeftScalar, quantities::Quantity<DRight>>,
    Frame, Rank>
operator/(Multivector<LeftScalar, Frame, Rank> const& left,
          quantities::Quantity<DRight> const& right) {
  return Multivector<
      quantities::Quotient<LeftScalar, quantities::Quantity<DRight>>,
      Frame, Rank>(left.coordinates / right);
}

template<typename Scalar, typename Frame, unsigned int Rank>
inline void operator+=(Multivector<Scalar, Frame, Rank>& left,
                       Multivector<Scalar, Frame, Rank> const& right) {
  left.coordinates += right.coordinates;
}
template<typename Scalar, typename Frame, unsigned int Rank>
inline void operator-=(Multivector<Scalar, Frame, Rank>& left,
                       Multivector<Scalar, Frame, Rank> const& right) {
  left.coordinates -= right.coordinates;
}
template<typename Scalar, typename Frame, unsigned int Rank>
inline void operator*=(Multivector<Scalar, Frame, Rank>& left,
                       quantities::Dimensionless const& right) {
  left.coordinates *= right;
}
template<typename Scalar, typename Frame, unsigned int Rank>
inline void operator/=(Multivector<Scalar, Frame, Rank>& left,
                       quantities::Dimensionless const& right) {
  left.coordinates /= right;
}

}  // namespace geometry
}  // namespace principia
<commit_msg>Spacing, remove redundant comments<commit_after>#pragma once

namespace principia {
namespace geometry {

template<typename Scalar, typename Frame>
Multivector<Scalar, Frame, 1>::Multivector(R3Element<Scalar> const& coordinates)
    : coordinates(coordinates) {};

template<typename Scalar, typename Frame>
Multivector<Scalar, Frame, 2>::Multivector(R3Element<Scalar> const& coordinates)
    : coordinates(coordinates) {};

template<typename Scalar, typename Frame>
Multivector<Scalar, Frame, 3>::Multivector(Scalar const& coordinates)
    : coordinates(coordinates) {};

template<typename LeftScalar, typename RightScalar, typename Frame>
inline quantities::Product<LeftScalar, RightScalar> InnerProduct(
    Vector<LeftScalar, Frame> const& left,
    Vector<RightScalar, Frame> const& right) {
  return Dot(left.coordinates, right.coordinates);
}

template<typename LeftScalar, typename RightScalar, typename Frame>
inline quantities::Product<LeftScalar, RightScalar> InnerProduct(
    Bivector<LeftScalar, Frame> const& left,
    Bivector<RightScalar, Frame> const& right) {
  return Dot(left.coordinates, right.coordinates);
}

template<typename LeftScalar, typename RightScalar, typename Frame>
inline quantities::Product<LeftScalar, RightScalar> InnerProduct(
    Trivector<LeftScalar, Frame> const& left,
    Trivector<RightScalar, Frame> const& right) {
  return left.coordinates * right.coordinates;
}

template<typename LeftScalar, typename RightScalar, typename Frame>
inline Bivector<quantities::Product<LeftScalar, RightScalar>,
                Frame> Wedge(Vector<LeftScalar, Frame> const& left,
                             Vector<RightScalar, Frame> const& right) {
  return Bivector<quantities::Product<LeftScalar, RightScalar>,
                   Frame>(Cross(left.coordinates, right.coordinates));
}

template<typename LeftScalar, typename RightScalar, typename Frame>
inline Trivector<quantities::Product<LeftScalar, RightScalar>,
                 Frame> Wedge(Bivector<LeftScalar, Frame> const& left,
                              Vector<RightScalar, Frame> const& right) {
  return Trivector<quantities::Product<LeftScalar, RightScalar>,
                   Frame>(Dot(left.coordinates, right.coordinates));
}

template<typename LeftScalar, typename RightScalar, typename Frame>
inline Trivector<quantities::Product<LeftScalar, RightScalar>,
                 Frame> Wedge(Vector<LeftScalar, Frame> const& left,
                              Bivector<RightScalar, Frame> const& right) {
  return Trivector<quantities::Product<LeftScalar, RightScalar>,
                   Frame>(Dot(left.coordinates, right.coordinates));
}

template<typename LeftScalar, typename RightScalar, typename Frame>
inline Bivector<quantities::Product<LeftScalar, RightScalar>,
                Frame> Commutator(Bivector<LeftScalar, Frame> const& left,
                                  Bivector<RightScalar, Frame> const& right) {
  return Bivector<quantities::Product<LeftScalar, RightScalar>,
                  Frame>(Cross(left.coordinates, right.coordinates));
}

template<typename LeftScalar, typename RightScalar, typename Frame>
inline Vector<quantities::Product<LeftScalar, RightScalar>,
              Frame> operator*(Bivector<LeftScalar, Frame> const& left,
                               Vector<RightScalar, Frame> const& right) {
  return Vector<quantities::Product<LeftScalar, RightScalar>,
                Frame>(Cross(left.coordinates, right.coordinates));
}

template<typename LeftScalar, typename RightScalar, typename Frame>
inline Vector<quantities::Product<LeftScalar, RightScalar>,
              Frame> operator*(Vector<LeftScalar, Frame> const& left,
                               Bivector<RightScalar, Frame> const& right) {
  return Vector<quantities::Product<LeftScalar, RightScalar>,
                Frame>(Cross(left.coordinates, right.coordinates));
}

template<typename Scalar, typename Frame, unsigned int Rank>
inline Multivector<Scalar, Frame, Rank> operator+(
    Multivector<Scalar, Frame, Rank> const& right) {
  return Multivector<Scalar, Frame, Rank>(+right.coordinates);
}

template<typename Scalar, typename Frame, unsigned int Rank>
inline Multivector<Scalar, Frame, Rank> operator-(
    Multivector<Scalar, Frame, Rank> const& right) {
  return Multivector<Scalar, Frame, Rank>(-right.coordinates);
}

template<typename Scalar, typename Frame, unsigned int Rank>
inline Multivector<Scalar, Frame, Rank> operator+(
    Multivector<Scalar, Frame, Rank> const& left,
    Multivector<Scalar, Frame, Rank> const& right) {
  return Multivector<Scalar, Frame, Rank>(left.coordinates + right.coordinates);
}

template<typename Scalar, typename Frame, unsigned int Rank>
inline Multivector<Scalar, Frame, Rank> operator-(
    Multivector<Scalar, Frame, Rank> const& left,
    Multivector<Scalar, Frame, Rank> const& right) {
  return Multivector<Scalar, Frame, Rank>(left.coordinates - right.coordinates);
}

template<typename Scalar, typename Frame, unsigned int Rank>
inline Multivector<Scalar, Frame, Rank> operator*(
    quantities::Dimensionless const& left,
    Multivector<Scalar, Frame, Rank> const& right) {
  return Multivector<Scalar, Frame, Rank>(left * right.coordinates);
}

template<typename Scalar, typename Frame, unsigned int Rank>
inline Multivector<Scalar, Frame, Rank> operator*(
    Multivector<Scalar, Frame, Rank> const& left,
    quantities::Dimensionless const& right) {
  return Multivector<Scalar, Frame, Rank>(left.coordinates * right);
}

template<typename Scalar, typename Frame, unsigned int Rank>
inline Multivector<Scalar, Frame, Rank> operator/(
    Multivector<Scalar, Frame, Rank> const& left,
    quantities::Dimensionless const& right) {
  return Multivector<Scalar, Frame, Rank>(left.coordinates / right);
}

template<typename DLeft, typename RightScalar, typename Frame,
         unsigned int Rank>
inline Multivector<
    quantities::Product<quantities::Quantity<DLeft>, RightScalar>,
    Frame, Rank>
operator*(quantities::Quantity<DLeft> const& left,
          Multivector<RightScalar, Frame, Rank> const& right) {
  return Multivector<
      quantities::Product<quantities::Quantity<DLeft>, RightScalar>,
      Frame, Rank>(left * right.coordinates);
}

template<typename LeftScalar, typename DRight, typename Frame,
         unsigned int Rank>
inline Multivector<
    quantities::Product<LeftScalar, quantities::Quantity<DRight>>,
    Frame, Rank>
operator*(Multivector<LeftScalar, Frame, Rank> const& left,
          quantities::Quantity<DRight> const& right) {
  return Multivector<
      quantities::Product<LeftScalar, quantities::Quantity<DRight>>,
      Frame, Rank>(left.coordinates * right);
}

template<typename LeftScalar, typename DRight, typename Frame,
         unsigned int Rank>
inline Multivector<
    quantities::Quotient<LeftScalar, quantities::Quantity<DRight>>,
    Frame, Rank>
operator/(Multivector<LeftScalar, Frame, Rank> const& left,
          quantities::Quantity<DRight> const& right) {
  return Multivector<
      quantities::Quotient<LeftScalar, quantities::Quantity<DRight>>,
      Frame, Rank>(left.coordinates / right);
}

template<typename Scalar, typename Frame, unsigned int Rank>
inline void operator+=(Multivector<Scalar, Frame, Rank>& left,
                       Multivector<Scalar, Frame, Rank> const& right) {
  left.coordinates += right.coordinates;
}

template<typename Scalar, typename Frame, unsigned int Rank>
inline void operator-=(Multivector<Scalar, Frame, Rank>& left,
                       Multivector<Scalar, Frame, Rank> const& right) {
  left.coordinates -= right.coordinates;
}

template<typename Scalar, typename Frame, unsigned int Rank>
inline void operator*=(Multivector<Scalar, Frame, Rank>& left,
                       quantities::Dimensionless const& right) {
  left.coordinates *= right;
}

template<typename Scalar, typename Frame, unsigned int Rank>
inline void operator/=(Multivector<Scalar, Frame, Rank>& left,
                       quantities::Dimensionless const& right) {
  left.coordinates /= right;
}

}  // namespace geometry
}  // namespace principia
<|endoftext|>


<commit_before>#pragma once

namespace Principia {
namespace Geometry {

template<typename T, typename Frame, unsigned int Rank>
inline Multivector<T, Frame,
                   Rank> operator+(Multivector<T, Frame, Rank> const& right) {
  return Multivector<T, Frame, Rank>(+right.coordinates);
}
template<typename T, typename Frame, unsigned int Rank>
inline Multivector<T, Frame,
                   Rank> operator-(Multivector<T, Frame, Rank> const& right) {
  return Multivector<T, Frame, Rank>(-right.coordinates);
}
template<typename T, typename Frame, unsigned int Rank>

inline Multivector<T, Frame,
                   Rank> operator+(Multivector<T, Frame, Rank> const& left,
                                   Multivector<T, Frame, Rank> const& right) {
  return Multivector<T, Frame, Rank>(left.coordinates + right.coordinates);
}
template<typename T, typename Frame, unsigned int Rank>
inline Multivector<T, Frame,
                   Rank> operator-(Multivector<T, Frame, Rank> const& left,
                                   Multivector<T, Frame, Rank> const& right) {
  return Multivector<T, Frame, Rank>(left.coordinates + left.coordinates);
}

template<typename T, typename Frame, unsigned int Rank>
inline Multivector<T, Frame,
                   Rank> operator*(Quantities::Dimensionless const& left,
                                   Multivector<T, Frame, Rank> const& right) {
  return Multivector<T, Frame, Rank>(left * right.coordinates);
}
template<typename T, typename Frame, unsigned int Rank>
inline Multivector<T, Frame,
                   Rank> operator*(Multivector<T, Frame, Rank> const& left,
                                   Quantities::Dimensionless const& right) {
  return Multivector<T, Frame, Rank>(left.coordinates * right);
}
template<typename T, typename Frame, unsigned int Rank>
inline Multivector<T, Frame,
                   Rank> operator/(Multivector<T, Frame, Rank> const& left,
                                   Quantities::Dimensionless const& right) {
  return Multivector<T, Frame, Rank>(left.coordinates / right);
}

template<typename T, typename U, typename Frame, unsigned int Rank>
inline Multivector<Quantities::Product<U, T> , Frame,
                   Rank> operator*(U const& left,
                                   Multivector<T, Frame, Rank> const& right) {
  return Multivector<T, Frame, Rank>(left * right.coordinates);
}
template<typename T, typename U, typename Frame, unsigned int Rank>
inline Multivector<Quantities::Product<T, U>, Frame,
                   Rank> operator*(Multivector<T, Frame, Rank> const& left,
                                   Quantities::Dimensionless const& right) {
  return Multivector<T, Frame, Rank>(left.coordinates * right);
}
template<typename T, typename U, typename Frame, unsigned int Rank>
inline Multivector<Quantities::Quotient<T, U>, Frame,
                   Rank> operator/(Multivector<T, Frame, Rank> const& left,
                                   Quantities::Dimensionless const& right) {
  return Multivector<T, Frame, Rank>(left.coordinates / right);
}

template<typename T, typename Frame, unsigned int Rank>
inline void operator+=(Multivector<T, Frame, Rank>& left,
                       Multivector<T, Frame, Rank> const& right) {
  left.coordinates += right.coordinates;
}

template<typename T, typename Frame, unsigned int Rank>
inline void operator-=(Multivector<T, Frame, Rank>& left,
                       Multivector<T, Frame, Rank> const& right) {
  left.coordinates -= right.coordinates;
}

template<typename T, typename Frame, unsigned int Rank>
inline void operator*=(Multivector<T, Frame, Rank>& left,
                       Quantities::Dimensionless const& right) {
  left.coordinates *= right;
}

template<typename T, typename Frame, unsigned int Rank>
inline void operator/=(Multivector<T, Frame, Rank>& left,
                       Quantities::Dimensionless const& right) {
  left.coordinates /= right;
}

}
}
<commit_msg>spacing<commit_after>#pragma once

namespace Principia {
namespace Geometry {

template<typename T, typename Frame, unsigned int Rank>
inline Multivector<T, Frame,
                   Rank> operator+(Multivector<T, Frame, Rank> const& right) {
  return Multivector<T, Frame, Rank>(+right.coordinates);
}
template<typename T, typename Frame, unsigned int Rank>
inline Multivector<T, Frame,
                   Rank> operator-(Multivector<T, Frame, Rank> const& right) {
  return Multivector<T, Frame, Rank>(-right.coordinates);
}
template<typename T, typename Frame, unsigned int Rank>

inline Multivector<T, Frame,
                   Rank> operator+(Multivector<T, Frame, Rank> const& left,
                                   Multivector<T, Frame, Rank> const& right) {
  return Multivector<T, Frame, Rank>(left.coordinates + right.coordinates);
}
template<typename T, typename Frame, unsigned int Rank>
inline Multivector<T, Frame,
                   Rank> operator-(Multivector<T, Frame, Rank> const& left,
                                   Multivector<T, Frame, Rank> const& right) {
  return Multivector<T, Frame, Rank>(left.coordinates + left.coordinates);
}

template<typename T, typename Frame, unsigned int Rank>
inline Multivector<T, Frame,
                   Rank> operator*(Quantities::Dimensionless const& left,
                                   Multivector<T, Frame, Rank> const& right) {
  return Multivector<T, Frame, Rank>(left * right.coordinates);
}
template<typename T, typename Frame, unsigned int Rank>
inline Multivector<T, Frame,
                   Rank> operator*(Multivector<T, Frame, Rank> const& left,
                                   Quantities::Dimensionless const& right) {
  return Multivector<T, Frame, Rank>(left.coordinates * right);
}
template<typename T, typename Frame, unsigned int Rank>
inline Multivector<T, Frame,
                   Rank> operator/(Multivector<T, Frame, Rank> const& left,
                                   Quantities::Dimensionless const& right) {
  return Multivector<T, Frame, Rank>(left.coordinates / right);
}

template<typename T, typename U, typename Frame, unsigned int Rank>
inline Multivector<Quantities::Product<U, T> , Frame,
                   Rank> operator*(U const& left,
                                   Multivector<T, Frame, Rank> const& right) {
  return Multivector<T, Frame, Rank>(left * right.coordinates);
}
template<typename T, typename U, typename Frame, unsigned int Rank>
inline Multivector<Quantities::Product<T, U>, Frame,
                   Rank> operator*(Multivector<T, Frame, Rank> const& left,
                                   Quantities::Dimensionless const& right) {
  return Multivector<T, Frame, Rank>(left.coordinates * right);
}
template<typename T, typename U, typename Frame, unsigned int Rank>
inline Multivector<Quantities::Quotient<T, U>, Frame,
                   Rank> operator/(Multivector<T, Frame, Rank> const& left,
                                   Quantities::Dimensionless const& right) {
  return Multivector<T, Frame, Rank>(left.coordinates / right);
}

template<typename T, typename Frame, unsigned int Rank>
inline void operator+=(Multivector<T, Frame, Rank>& left,
                       Multivector<T, Frame, Rank> const& right) {
  left.coordinates += right.coordinates;
}
template<typename T, typename Frame, unsigned int Rank>
inline void operator-=(Multivector<T, Frame, Rank>& left,
                       Multivector<T, Frame, Rank> const& right) {
  left.coordinates -= right.coordinates;
}
template<typename T, typename Frame, unsigned int Rank>
inline void operator*=(Multivector<T, Frame, Rank>& left,
                       Quantities::Dimensionless const& right) {
  left.coordinates *= right;
}
template<typename T, typename Frame, unsigned int Rank>
inline void operator/=(Multivector<T, Frame, Rank>& left,
                       Quantities::Dimensionless const& right) {
  left.coordinates /= right;
}

}
}
<|endoftext|>