<commit_before>/**********************************************************************
 * $Id$
 *
 * GEOS - Geometry Engine Open Source
 * http://geos.refractions.net
 *
 * Copyright (C) 2001-2002 Vivid Solutions Inc.
 *
 * This is free software; you can redistribute and/or modify it under
 * the terms of the GNU Lesser General Public Licence as published
 * by the Free Software Foundation. 
 * See the COPYING file for more information.
 *
 **********************************************************************
 * $Log$
 * Revision 1.17  2004/03/31 07:50:37  ybychkov
 * "geom" partially upgraded to JTS 1.4
 *
 * Revision 1.16  2003/11/12 17:15:05  strk
 * made sure PrecisionModel scale is never 0
 *
 * Revision 1.15  2003/11/07 01:23:42  pramsey
 * Add standard CVS headers licence notices and copyrights to all cpp and h
 * files.
 *
 * Revision 1.14  2003/10/11 01:56:08  strk
 *
 * Code base padded with 'const' keywords ;)
 *
 * Revision 1.13  2003/10/09 10:10:05  strk
 * Throw an exception if scale is 0. Added Log entry.
 *
 **********************************************************************/


#include "../headers/geom.h"
#include "../headers/util.h"
#include "stdio.h"

namespace geos {

const double maximumPreciseValue=9007199254740992.0;

map<string,PrecisionModel::Type*>* PrecisionModel::Type::nameToTypeMap=new map<string,PrecisionModel::Type*>();
PrecisionModel::Type* PrecisionModel::FIXED=new PrecisionModel::Type("FIXED");
PrecisionModel::Type* PrecisionModel::FLOATING=new PrecisionModel::Type("FLOATING");
PrecisionModel::Type* PrecisionModel::FLOATING_SINGLE=new PrecisionModel::Type("FLOATING SINGLE");
PrecisionModel::Type::Type(string newName) { 
	name=newName;
	nameToTypeMap->insert(pair<string,PrecisionModel::Type*>(name, this));
}

void* PrecisionModel::Type::readResolve() {
	return nameToTypeMap->find(name)->second;
}    

string PrecisionModel::Type::toString() {
	return name;
}

//double PrecisionModel::makePrecise(double val){
//	//return rint(val);
//	return ((val >= 0.0) ? floor(val+0.5) : - floor(-val+0.5));
//    /*
//     * Other options:
//     * - Math.floor(a + 0.5d);
//     * - Math.floor(a);
//     * -  (val >= 0.0) ? Math.floor(val) : - Math.floor(-val);
//     */
//}

/**
* Rounds an numeric value to the PrecisionModel grid.
*/
double PrecisionModel::makePrecise(double val) const {
	if (modelType==FLOATING_SINGLE) {
		float floatSingleVal = (float) val;
		return (double) floatSingleVal;
	}
	if (modelType == FIXED) {
		double v=val*scale;
		if (val>=0.0) 
			v=floor(v+0.5);
		else 
			v=-floor(-v+0.5);
		return v/scale;
	}
	// modelType == FLOATING - no rounding necessary
	return val;
}

/**
* Rounds a Coordinate to the PrecisionModel grid.
*/
void PrecisionModel::makePrecise(Coordinate *coord) const {
    // optimization for full precision
	if (modelType==FLOATING) return;
	coord->x=makePrecise(coord->x);
	coord->y=makePrecise(coord->y);
}


	/**
	* Creates a <code>PrecisionModel</code> with a default precision
	* of FLOATING.
	*/
PrecisionModel::PrecisionModel(){
	modelType=FLOATING;
	scale=1.0;
}

/**
* Creates a <code>PrecisionModel</code> that specifies
* an explicit precision model type.
* If the model type is FIXED the scale factor will default to 1.
*
* @param modelType the type of the precision model
*/
PrecisionModel::PrecisionModel(Type* nModelType){
	modelType=nModelType;
	if (modelType==FIXED){
		setScale(1.0);
	}
}


/**
*  Creates a <code>PrecisionModel</code> that specifies Fixed precision.
*  Fixed-precision coordinates are represented as precise internal coordinates,
*  which are rounded to the grid defined by the scale factor.
*
*@param  scale    amount by which to multiply a coordinate after subtracting
*      the offset, to obtain a precise coordinate
*@param  offsetX  not used.
*@param  offsetY  not used.
*
* @deprecated offsets are no longer supported, since internal representation is rounded floating point
*/
PrecisionModel::PrecisionModel(double newScale, double newOffsetX, double newOffsetY)
	//throw(IllegalArgumentException *)
{
	modelType = FIXED;
	setScale(newScale);
}

/**
*  Creates a <code>PrecisionModel</code> that specifies Fixed precision.
*  Fixed-precision coordinates are represented as precise internal coordinates,
*  which are rounded to the grid defined by the scale factor.
*
*@param  scale    amount by which to multiply a coordinate after subtracting
*      the offset, to obtain a precise coordinate
*/
PrecisionModel::PrecisionModel(double newScale)
	//throw (IllegalArgumentException *)
{
	modelType=FIXED;
	setScale(scale);
}


PrecisionModel::PrecisionModel(const PrecisionModel &pm)
{
	modelType = pm.modelType;
	scale = pm.scale;
}

/**
* Tests whether the precision model supports floating point
* @return <code>true</code> if the precision model supports floating point
*/
bool PrecisionModel::isFloating() const {
	return (modelType == FLOATING || modelType == FLOATING_SINGLE);
}
<commit_msg>PrecisionModel(double newScale) missed to set the scale<commit_after>/**********************************************************************
 * $Id$
 *
 * GEOS - Geometry Engine Open Source
 * http://geos.refractions.net
 *
 * Copyright (C) 2001-2002 Vivid Solutions Inc.
 *
 * This is free software; you can redistribute and/or modify it under
 * the terms of the GNU Lesser General Public Licence as published
 * by the Free Software Foundation. 
 * See the COPYING file for more information.
 *
 **********************************************************************
 * $Log$
 * Revision 1.18  2004/04/14 09:38:10  strk
 * PrecisionModel(double newScale) missed to set the scale
 *
 * Revision 1.17  2004/03/31 07:50:37  ybychkov
 * "geom" partially upgraded to JTS 1.4
 *
 * Revision 1.16  2003/11/12 17:15:05  strk
 * made sure PrecisionModel scale is never 0
 *
 * Revision 1.15  2003/11/07 01:23:42  pramsey
 * Add standard CVS headers licence notices and copyrights to all cpp and h
 * files.
 *
 * Revision 1.14  2003/10/11 01:56:08  strk
 *
 * Code base padded with 'const' keywords ;)
 *
 * Revision 1.13  2003/10/09 10:10:05  strk
 * Throw an exception if scale is 0. Added Log entry.
 *
 **********************************************************************/


#include "../headers/geom.h"
#include "../headers/util.h"
#include "stdio.h"

namespace geos {

const double maximumPreciseValue=9007199254740992.0;

map<string,PrecisionModel::Type*>* PrecisionModel::Type::nameToTypeMap=new map<string,PrecisionModel::Type*>();
PrecisionModel::Type* PrecisionModel::FIXED=new PrecisionModel::Type("FIXED");
PrecisionModel::Type* PrecisionModel::FLOATING=new PrecisionModel::Type("FLOATING");
PrecisionModel::Type* PrecisionModel::FLOATING_SINGLE=new PrecisionModel::Type("FLOATING SINGLE");
PrecisionModel::Type::Type(string newName) { 
	name=newName;
	nameToTypeMap->insert(pair<string,PrecisionModel::Type*>(name, this));
}

void* PrecisionModel::Type::readResolve() {
	return nameToTypeMap->find(name)->second;
}    

string PrecisionModel::Type::toString() {
	return name;
}

//double PrecisionModel::makePrecise(double val){
//	//return rint(val);
//	return ((val >= 0.0) ? floor(val+0.5) : - floor(-val+0.5));
//    /*
//     * Other options:
//     * - Math.floor(a + 0.5d);
//     * - Math.floor(a);
//     * -  (val >= 0.0) ? Math.floor(val) : - Math.floor(-val);
//     */
//}

/**
* Rounds an numeric value to the PrecisionModel grid.
*/
double PrecisionModel::makePrecise(double val) const {
	if (modelType==FLOATING_SINGLE) {
		float floatSingleVal = (float) val;
		return (double) floatSingleVal;
	}
	if (modelType == FIXED) {
		double v=val*scale;
		if (val>=0.0) 
			v=floor(v+0.5);
		else 
			v=-floor(-v+0.5);
		return v/scale;
	}
	// modelType == FLOATING - no rounding necessary
	return val;
}

/**
* Rounds a Coordinate to the PrecisionModel grid.
*/
void PrecisionModel::makePrecise(Coordinate *coord) const {
    // optimization for full precision
	if (modelType==FLOATING) return;
	coord->x=makePrecise(coord->x);
	coord->y=makePrecise(coord->y);
}


	/**
	* Creates a <code>PrecisionModel</code> with a default precision
	* of FLOATING.
	*/
PrecisionModel::PrecisionModel(){
	modelType=FLOATING;
	scale=1.0;
}

/**
* Creates a <code>PrecisionModel</code> that specifies
* an explicit precision model type.
* If the model type is FIXED the scale factor will default to 1.
*
* @param modelType the type of the precision model
*/
PrecisionModel::PrecisionModel(Type* nModelType){
	modelType=nModelType;
	if (modelType==FIXED){
		setScale(1.0);
	}
}


/**
*  Creates a <code>PrecisionModel</code> that specifies Fixed precision.
*  Fixed-precision coordinates are represented as precise internal coordinates,
*  which are rounded to the grid defined by the scale factor.
*
*@param  scale    amount by which to multiply a coordinate after subtracting
*      the offset, to obtain a precise coordinate
*@param  offsetX  not used.
*@param  offsetY  not used.
*
* @deprecated offsets are no longer supported, since internal representation is rounded floating point
*/
PrecisionModel::PrecisionModel(double newScale, double newOffsetX, double newOffsetY)
	//throw(IllegalArgumentException *)
{
	modelType = FIXED;
	setScale(newScale);
}

/**
*  Creates a <code>PrecisionModel</code> that specifies Fixed precision.
*  Fixed-precision coordinates are represented as precise internal coordinates,
*  which are rounded to the grid defined by the scale factor.
*
*@param  scale    amount by which to multiply a coordinate after subtracting
*      the offset, to obtain a precise coordinate
*/
PrecisionModel::PrecisionModel(double newScale)
	//throw (IllegalArgumentException *)
{
	modelType=FIXED;
	setScale(newScale);
}


PrecisionModel::PrecisionModel(const PrecisionModel &pm)
{
	modelType = pm.modelType;
	scale = pm.scale;
}

/**
* Tests whether the precision model supports floating point
* @return <code>true</code> if the precision model supports floating point
*/
bool PrecisionModel::isFloating() const {
	return (modelType == FLOATING || modelType == FLOATING_SINGLE);
}

{'fraction_non_alphanumeric': 0.1620761658546286, 'fraction_numerical': 0.028537337178084914, 'mean_word_length': 4.5324532453245325, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '946697', 'n_tokens_mistral': 3438, 'n_tokens_neox': 3111, 'n_words': 896}