Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ "_t" : "BH.oM.Data.Library.Dataset", "SourceInformation" : { "_t" : "BH.oM.Data.Library.Source", "SourceLink" : "", "Title" : "RoundToCeilingAwayFromZero", "Author" : "Christopher Short", "ItemReference" : "", "Version" : "", "Publisher" : "", "Schema" : "", "Language" : "", "Location" : "", "Copyright" : "", "Contributors" : "", "Confidence" : "High", "BHoM_Guid" : "ff23d365-89f2-4a63-b068-6b04d524ef2d", "Name" : "" }, "TimeOfCreation" : { "$date" : 1788275279991 }, "Data" : [{ "_t" : "BH.oM.Test.UnitTests.UnitTest", "Method" : { "_t" : "System.Reflection.MethodBase", "TypeName" : "{ \"_t\" : \"System.Type\", \"Name\" : \"BH.Engine.Base.Query, BHoM_Engine, Version=9.0.0.0, Culture=neutral, PublicKeyToken=null\", \"_bhomVersion\" : \"9.3\" }", "MethodName" : "RoundToCeilingAwayFromZero", "Parameters" : ["{ \"_t\" : \"System.Type\", \"Name\" : \"System.Double, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089\", \"_bhomVersion\" : \"9.3\" }", "{ \"_t\" : \"System.Type\", \"Name\" : \"System.Double, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089\", \"_bhomVersion\" : \"9.3\" }"], "_bhomVersion" : "9.3" }, "Data" : [{ "_t" : "BH.oM.Test.UnitTests.TestData", "Inputs" : [12.0, 20.0], "Outputs" : [20.0], "BHoM_Guid" : "e2eb89b3-838e-4a30-a81b-6276ae1f075d", "Name" : "" }, { "_t" : "BH.oM.Test.UnitTests.TestData", "Inputs" : [121.0, 2.0], "Outputs" : [122.0], "BHoM_Guid" : "0cb975c7-7f03-4740-b7fe-b8a6ead2f793", "Name" : "" }, { "_t" : "BH.oM.Test.UnitTests.TestData", "Inputs" : [1.2344999999999999, 1.1000000000000001], "Outputs" : [2.2000000000000002], "BHoM_Guid" : "03cf27f5-bdfb-4776-8ea3-a2a5bef886f9", "Name" : "" }, { "_t" : "BH.oM.Test.UnitTests.TestData", "Inputs" : [0.014, 0.01], "Outputs" : [0.02], "BHoM_Guid" : "38293d95-2cf0-4df6-9632-ba9691ff08a7", "Name" : "" }, { "_t" : "BH.oM.Test.UnitTests.TestData", "Inputs" : [-0.014, 0.01], "Outputs" : [-0.02], "BHoM_Guid" : "56e8b7d8-ad07-4f66-80c0-431790fac8f0", "Name" : "" }, { "_t" : "BH.oM.Test.UnitTests.TestData", "Inputs" : [0.014999999999999999, 0.01], "Outputs" : [0.02], "BHoM_Guid" : "361bb62f-0a4c-42cb-9321-c33cefb3de67", "Name" : "" }, { "_t" : "BH.oM.Test.UnitTests.TestData", "Inputs" : [0.014, 0.02], "Outputs" : [0.02], "BHoM_Guid" : "913fb4f0-4c54-4f2d-ab2a-9d1307a16244", "Name" : "" }, { "_t" : "BH.oM.Test.UnitTests.TestData", "Inputs" : [-35.0, 20.0], "Outputs" : [-40.0], "BHoM_Guid" : "6868503b-10ef-4656-a1d7-aed2c9100d69", "Name" : "" }, { "_t" : "BH.oM.Test.UnitTests.TestData", "Inputs" : [456.0, 50.0], "Outputs" : [500.0], "BHoM_Guid" : "8d36e799-1c0b-4f81-996c-39d592bea3ef", "Name" : "" }, { "_t" : "BH.oM.Test.UnitTests.TestData", "Inputs" : [-0.5, 0.10000000000000001], "Outputs" : [-0.5], "BHoM_Guid" : "8cb81b2c-3325-48c6-b7e4-9ce93c9000a3", "Name" : "" }], "BHoM_Guid" : "879ac8c3-1a75-4bbf-93a9-50fb0c740fab", "Name" : "" }, { "_t" : "BH.oM.Test.UnitTests.UnitTest", "Method" : { "_t" : "System.Reflection.MethodBase", "TypeName" : "{ \"_t\" : \"System.Type\", \"Name\" : \"BH.Engine.Base.Query, BHoM_Engine, Version=9.0.0.0, Culture=neutral, PublicKeyToken=null\", \"_bhomVersion\" : \"9.3\" }", "MethodName" : "RoundToCeilingAwayFromZero", "Parameters" : ["{ \"_t\" : \"System.Type\", \"Name\" : \"System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089\", \"_bhomVersion\" : \"9.3\" }", "{ \"_t\" : \"System.Type\", \"Name\" : \"System.Double, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089\", \"_bhomVersion\" : \"9.3\" }"], "_bhomVersion" : "9.3" }, "Data" : [{ "_t" : "BH.oM.Test.UnitTests.TestData", "Inputs" : [12, 20.0], "Outputs" : [20], "BHoM_Guid" : "6876116e-d08b-422d-9120-25b2dcb24266", "Name" : "" }, { "_t" : "BH.oM.Test.UnitTests.TestData", "Inputs" : [121, 2.0], "Outputs" : [122], "BHoM_Guid" : "44c0a66b-ec8d-462e-821f-d4a4edfb53fc", "Name" : "" }, { "_t" : "BH.oM.Test.UnitTests.TestData", "Inputs" : [35, 20.0], "Outputs" : [40], "BHoM_Guid" : "95f4621c-30da-4e6f-adc4-9303310619e5", "Name" : "" }, { "_t" : "BH.oM.Test.UnitTests.TestData", "Inputs" : [14, 10.0], "Outputs" : [20], "BHoM_Guid" : "b417eacf-6134-4374-a19c-04d9cacdfc2a", "Name" : "" }, { "_t" : "BH.oM.Test.UnitTests.TestData", "Inputs" : [-14, 10.0], "Outputs" : [-20], "BHoM_Guid" : "93d51ef0-7248-4570-89b0-c1e93b4fd4b6", "Name" : "" }, { "_t" : "BH.oM.Test.UnitTests.TestData", "Inputs" : [15, 10.0], "Outputs" : [20], "BHoM_Guid" : "60264f24-cbb8-4702-a8c7-36515c8803bd", "Name" : "" }, { "_t" : "BH.oM.Test.UnitTests.TestData", "Inputs" : [14, 20.0], "Outputs" : [20], "BHoM_Guid" : "ed3224f0-b2d4-4f5d-afd7-7d9045e5a09b", "Name" : "" }, { "_t" : "BH.oM.Test.UnitTests.TestData", "Inputs" : [-35, 20.0], "Outputs" : [-40], "BHoM_Guid" : "3ba26163-91e3-47ac-92e0-cfcec93dc8a7", "Name" : "" }, { "_t" : "BH.oM.Test.UnitTests.TestData", "Inputs" : [456, 50.0], "Outputs" : [500], "BHoM_Guid" : "745ff886-db9e-4a03-ba89-5851c79285c0", "Name" : "" }, { "_t" : "BH.oM.Test.UnitTests.TestData", "Inputs" : [-50, 10.0], "Outputs" : [-50], "BHoM_Guid" : "f471445f-292f-4cb2-b7a0-2589b5311a06", "Name" : "" }], "BHoM_Guid" : "ad7838c0-7a55-460d-8665-6a28b834094f", "Name" : "" }], "BHoM_Guid" : "6c8ec193-28da-4214-8b30-32ac9422f35c", "Name" : "RoundToCeilingAwayFromZero", "_bhomVersion" : "9.3" }

Check notice on line 1 in .ci/Datasets/BHoM_Engine/Query/RoundToCeilingAwayFromZero.json

View check run for this annotation

BHoMBot-CI / dataset-compliance

.ci/Datasets/BHoM_Engine/Query/RoundToCeilingAwayFromZero.json#L1

Title: RoundToCeilingAwayFromZero Author: Christopher Short Confidence: High Version: Source Link: Publisher: Language: Schema: Location: Copyright: Contributors: Item Reference:
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ "_t" : "BH.oM.Data.Library.Dataset", "SourceInformation" : { "_t" : "BH.oM.Data.Library.Source", "SourceLink" : "", "Title" : "RoundToFloorTowardZero", "Author" : "Christopher Short", "ItemReference" : "", "Version" : "", "Publisher" : "", "Schema" : "", "Language" : "", "Location" : "", "Copyright" : "", "Contributors" : "", "Confidence" : "High", "BHoM_Guid" : "48f64bd1-b36e-4bfa-a663-ce0b96d0b456", "Name" : "" }, "TimeOfCreation" : { "$date" : 1788275279991 }, "Data" : [{ "_t" : "BH.oM.Test.UnitTests.UnitTest", "Method" : { "_t" : "System.Reflection.MethodBase", "TypeName" : "{ \"_t\" : \"System.Type\", \"Name\" : \"BH.Engine.Base.Query, BHoM_Engine, Version=9.0.0.0, Culture=neutral, PublicKeyToken=null\", \"_bhomVersion\" : \"9.3\" }", "MethodName" : "RoundToFloorTowardZero", "Parameters" : ["{ \"_t\" : \"System.Type\", \"Name\" : \"System.Double, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089\", \"_bhomVersion\" : \"9.3\" }", "{ \"_t\" : \"System.Type\", \"Name\" : \"System.Double, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089\", \"_bhomVersion\" : \"9.3\" }"], "_bhomVersion" : "9.3" }, "Data" : [{ "_t" : "BH.oM.Test.UnitTests.TestData", "Inputs" : [12.0, 20.0], "Outputs" : [0.0], "BHoM_Guid" : "3a5da8d4-9070-4e1f-82c8-67c3efadd2ed", "Name" : "" }, { "_t" : "BH.oM.Test.UnitTests.TestData", "Inputs" : [121.0, 2.0], "Outputs" : [120.0], "BHoM_Guid" : "9f7b3402-b229-474c-b1b6-53fa40e187d4", "Name" : "" }, { "_t" : "BH.oM.Test.UnitTests.TestData", "Inputs" : [1.2344999999999999, 1.1000000000000001], "Outputs" : [1.1000000000000001], "BHoM_Guid" : "33739830-80e0-46bb-bbb9-f6ddb785ea89", "Name" : "" }, { "_t" : "BH.oM.Test.UnitTests.TestData", "Inputs" : [0.014, 0.01], "Outputs" : [0.01], "BHoM_Guid" : "c723a51c-3674-4a95-8975-a3345ed9ac7c", "Name" : "" }, { "_t" : "BH.oM.Test.UnitTests.TestData", "Inputs" : [-0.014, 0.01], "Outputs" : [-0.01], "BHoM_Guid" : "be0af62b-08ae-4953-9bf9-e68e956ce64f", "Name" : "" }, { "_t" : "BH.oM.Test.UnitTests.TestData", "Inputs" : [0.014999999999999999, 0.01], "Outputs" : [0.01], "BHoM_Guid" : "e75441d0-d7ba-44ef-a1ad-12aaae7581ec", "Name" : "" }, { "_t" : "BH.oM.Test.UnitTests.TestData", "Inputs" : [0.014, 0.02], "Outputs" : [0.0], "BHoM_Guid" : "6163926a-e283-4bd7-b1d2-de10fe513093", "Name" : "" }, { "_t" : "BH.oM.Test.UnitTests.TestData", "Inputs" : [-35.0, 20.0], "Outputs" : [-20.0], "BHoM_Guid" : "f221411c-8151-491e-bfa3-e82df7868caa", "Name" : "" }, { "_t" : "BH.oM.Test.UnitTests.TestData", "Inputs" : [456.0, 50.0], "Outputs" : [450.0], "BHoM_Guid" : "d15464a1-9a3f-4bb3-8520-aad02f51996e", "Name" : "" }, { "_t" : "BH.oM.Test.UnitTests.TestData", "Inputs" : [-0.5, 0.10000000000000001], "Outputs" : [-0.5], "BHoM_Guid" : "db3b6cb1-8fe7-4ebf-8812-a3d863cb4b79", "Name" : "" }], "BHoM_Guid" : "6897a73d-118b-4286-9ca6-2217cb251c7d", "Name" : "" }, { "_t" : "BH.oM.Test.UnitTests.UnitTest", "Method" : { "_t" : "System.Reflection.MethodBase", "TypeName" : "{ \"_t\" : \"System.Type\", \"Name\" : \"BH.Engine.Base.Query, BHoM_Engine, Version=9.0.0.0, Culture=neutral, PublicKeyToken=null\", \"_bhomVersion\" : \"9.3\" }", "MethodName" : "RoundToFloorTowardZero", "Parameters" : ["{ \"_t\" : \"System.Type\", \"Name\" : \"System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089\", \"_bhomVersion\" : \"9.3\" }", "{ \"_t\" : \"System.Type\", \"Name\" : \"System.Double, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089\", \"_bhomVersion\" : \"9.3\" }"], "_bhomVersion" : "9.3" }, "Data" : [{ "_t" : "BH.oM.Test.UnitTests.TestData", "Inputs" : [12, 20.0], "Outputs" : [0], "BHoM_Guid" : "c16ea64a-2def-4988-85df-d61314ab0d25", "Name" : "" }, { "_t" : "BH.oM.Test.UnitTests.TestData", "Inputs" : [121, 2.0], "Outputs" : [120], "BHoM_Guid" : "d7620903-1c7c-4f33-975e-2ce6fe3e2865", "Name" : "" }, { "_t" : "BH.oM.Test.UnitTests.TestData", "Inputs" : [35, 20.0], "Outputs" : [20], "BHoM_Guid" : "cc1a194a-031e-4ed7-a569-9d298cf674a9", "Name" : "" }, { "_t" : "BH.oM.Test.UnitTests.TestData", "Inputs" : [14, 10.0], "Outputs" : [10], "BHoM_Guid" : "7f14fbb2-49fb-4e65-a72b-ea6b195cb500", "Name" : "" }, { "_t" : "BH.oM.Test.UnitTests.TestData", "Inputs" : [-14, 10.0], "Outputs" : [-10], "BHoM_Guid" : "b93993d7-3fbd-4de5-846f-55e2614cdb35", "Name" : "" }, { "_t" : "BH.oM.Test.UnitTests.TestData", "Inputs" : [15, 10.0], "Outputs" : [10], "BHoM_Guid" : "24debded-053d-4869-afc0-99ab3927e1b9", "Name" : "" }, { "_t" : "BH.oM.Test.UnitTests.TestData", "Inputs" : [14, 20.0], "Outputs" : [0], "BHoM_Guid" : "99d21928-e470-4d66-b67e-e1b71065beeb", "Name" : "" }, { "_t" : "BH.oM.Test.UnitTests.TestData", "Inputs" : [-35, 20.0], "Outputs" : [-20], "BHoM_Guid" : "a2bba558-4ecb-438b-b30a-9441eab4d054", "Name" : "" }, { "_t" : "BH.oM.Test.UnitTests.TestData", "Inputs" : [456, 50.0], "Outputs" : [450], "BHoM_Guid" : "aa48ab1a-f910-45bd-b3d3-ee89c1592dd6", "Name" : "" }, { "_t" : "BH.oM.Test.UnitTests.TestData", "Inputs" : [-50, 10.0], "Outputs" : [-50], "BHoM_Guid" : "b17025d7-d9bc-4bad-8fc1-746becd1bd17", "Name" : "" }], "BHoM_Guid" : "28a945c9-18f4-4f20-9125-f23d923990b1", "Name" : "" }], "BHoM_Guid" : "939086e5-d2e0-43da-8b48-95f405587612", "Name" : "RoundToFloorTowardZero", "_bhomVersion" : "9.3" }

Check notice on line 1 in .ci/Datasets/BHoM_Engine/Query/RoundToFloorTowardZero.json

View check run for this annotation

BHoMBot-CI / dataset-compliance

.ci/Datasets/BHoM_Engine/Query/RoundToFloorTowardZero.json#L1

Title: RoundToFloorTowardZero Author: Christopher Short Confidence: High Version: Source Link: Publisher: Language: Schema: Location: Copyright: Contributors: Item Reference:
103 changes: 103 additions & 0 deletions BHoM_Engine/Query/RoundToCeilingAwayFromZero.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/*
* This file is part of the Buildings and Habitats object Model (BHoM)
* Copyright (c) 2015 - 2026, the respective contributors. All rights reserved.
*
* Each contributor holds copyright over their respective contributions.
* The project versioning (Git) records all such contribution source information.
*
*
* The BHoM is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3.0 of the License, or
* (at your option) any later version.
*
* The BHoM 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this code. If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
*/

using BH.oM.Base.Attributes;
using System;
using System.ComponentModel;

namespace BH.Engine.Base
{
public static partial class Query
{
/***************************************************/
/**** Public Methods ****/
/***************************************************/

[Description("Rounds a number using the given tolerance, always rounding the magnitude of the number away " +
"from zero to the next tolerance multiple, regardless of sign. Supports any fractional, integer, " +
"positive or negative numbers. Complements RoundFloorTowardZero()." +
"\nSome examples:" +
"\n\t RoundToCeilingAwayFromZero(12, 20) ==> 20" +
"\n\t RoundToCeilingAwayFromZero(121, 2) ==> 122" +
"\n\t RoundToCeilingAwayFromZero(1.2345, 1.1) ==> 2.2" +
"\n\t RoundToCeilingAwayFromZero(0.014, 0.01) ==> 0.02" +
"\n\t RoundToCeilingAwayFromZero(-0.014, 0.01) ==> -0.02" +
"\n\t RoundToCeilingAwayFromZero(0.015, 0.01) ==> 0.02" +
"\n\t RoundToCeilingAwayFromZero(0.014, 0.02) ==> 0.02" +
"\nand so on.")]
[Input("number", "Number to be rounded.")]
[Input("tolerance", "Tolerance to use for rounding.")]
[Output("roundedNumber", "The rounded number.")]
public static double RoundToCeilingAwayFromZero(this double number, double tolerance)
{
if (tolerance < 0)
{
BH.Engine.Base.Compute.RecordError("Tolerance cannot be less than 0.");
return default(double);
}

// If the tolerance is the smallest possible double, or if the inputs are invalid, just return.
if (number == 0 || tolerance == 0 || Double.IsNaN(tolerance) || Double.IsNaN(number) || Double.IsInfinity(number) || Double.IsInfinity(tolerance))
return number;

double sign = number < 0 ? -1.0 : 1.0;
return sign * tolerance * Math.Ceiling(Math.Abs(number) / tolerance);
}

/***************************************************/

[Description("Rounds an integer number using the given tolerance, rounding the magnitude away from zero to the nearest tolerance multiplier." +
"\nSome examples:" +
"\n\t RoundToCeilingAwayFromZero(12, 20) ==> 20" +
"\n\t RoundToCeilingAwayFromZero(121, 2) ==> 122" +
"\n\t RoundToCeilingAwayFromZero(-35, 20) ==> -40" +
"\nand so on.")]
[Input("number", "Number to be rounded.")]
[Input("tolerance", "Tolerance to use for rounding.")]
[Output("roundedNumber", "The rounded number.")]
public static int RoundToCeilingAwayFromZero(this int number, double tolerance)
{
if (tolerance < 0)
{
BH.Engine.Base.Compute.RecordError("Tolerance cannot be less than 0.");
return 0;
}

// If the tolerance is the smallest possible double, or if the inputs are invalid, just return.
if (number == 0 || tolerance == double.MinValue || tolerance == 0 || Double.IsNaN(tolerance) || number == int.MinValue || number == int.MaxValue || Double.IsInfinity(tolerance))
return number;

if ((int)tolerance != tolerance)
{
BH.Engine.Base.Compute.RecordError("Tolerance needs to be an integer value.");
return 0;
}

int sign = number < 0 ? -1 : 1;
return sign * (int)(Math.Ceiling(Math.Abs(number) / tolerance) * tolerance);
}

/***************************************************/
}
}


Loading