Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8320279
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T22:36:17+00:00 2026-06-08T22:36:17+00:00

I have a codebase that deals with angles quite a bit, but sometimes the

  • 0

I have a codebase that deals with angles quite a bit, but sometimes the input comes in different angle formats. That is, some formats are degrees clockwise, some are degrees counter-clockwise, some are 0 to 360, some are -180 to 180, some are radians…

So far I have succeeded in keeping them all the same internally, but it’s always a worry, and the bugs that arise can be hard to track down.

I would like to create an angle class that keeps track of the units and direction as well as the magnitude so that I can deal with them in a uniform way without so much worries.

My googling has turned up Martin Fowler’s Value Object, but i’m having trouble understanding his language without a simple example to reference. I’ve also found a Java API that seems relevant, but it doesn’t look like a simple example either…

Can anyone point me towards a simple example of a class that incorporates units?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T22:36:18+00:00Added an answer on June 8, 2026 at 10:36 pm

    I would approach this by storing values internally in a single format (say, positive radians) and provide static factory methods to construct angles from various input formats. For example:

    public class Angle {
      private final double radians;
    
      private Angle(double radians) {
        this.radians = radians;
      }
    
      // Static factory methods
    
      public static Angle radians(double rad) {
        return new Angle(rad);
      }
    
      public static Angle degrees(double deg) {
        return radians(Math.toRadians(deg));
      }
    
      public static Angle degreesCCW(double deg) {
        return degrees(360 - deg);
      }
    
      ...
    
      // Operations
    
      public Angle plus(Angle other) {
        return new Angle((this.radians + other.radians) % (2 * Math.PI));
      }
    
      ...
    }
    

    Then you could use it like this:

    Angle a1 = Angle.radians(0.5);
    Angle a2 = Angle.degreesCCW(60);
    Angle a3 = a1.plus(a2);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a code base that deals with simulation of certain data. It involves
I have checked out now a local working copy of a codebase that lives
I have inherited a DotNetNuke codebase and have come across areas that have included
I have a huge java codebase (more than 10,000 java classes) that makes extensive
I have a few related applications that I want to deploy to different computers.
I have a nice clean standards-compliant codebase that I can compile with GCC's -ansi
I have a large high quality c# framework codebase that I nevertheless want to
We have a mature c++ COM codebase that has been building, registering and running
I have a very small Java codebase that I would like to expose as
In Maven, I have a codebase that I want to build that needs to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.