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 6670925
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:19:34+00:00 2026-05-26T03:19:34+00:00

I am having some serious troubles implementing a draw in the scala language. my

  • 0

I am having some serious troubles implementing a draw in the scala language. my current code looks like:

package edu.luc.cs.laufer.cs473.shapealgebra

import java.awt.Graphics2D

class Draw {
  def draw(g: Graphics2D)(s: Shape): Unit = s match {
    case Ellipse(hw, hh) => g.drawArc(-hw, -hh, 2 * hw, 2 * hh, 0, 360)
    case Rectangle(w, h) => g.drawRect(0, 0, w, h)
    case Location(x: Int, y: Int, shape: Shape) => {
      g.translate(x, y)
      draw(g)(shape)
      g.translate(0,0)
    }
    case Group(shapes @ _*) => {
      shapes foreach(draw(g)(_))
    }
  }
 }

 object Draw extends Draw {
  def apply(g: Graphics2D) = draw(g)(_)
}

The problem here is with my group case. It does not draw a group of shapes properly. The two test cases uses the following shapes:

val simpleLocation = Location(70, 30, Rectangle(80, 120))
val complexGroup = Location(50, 100,
    Group(
     Ellipse(20, 20),
     Location(150, 50,
        Group(
          Rectangle(50, 30),
          Rectangle(300, 60),
          Location(100, 200,
          Ellipse(50, 50)
         )
       )
     ),
     Rectangle(100, 200)
   )
  )

The complex continues to fail and I can’t figure out why.

package edu.luc.cs.laufer.cs473.shapealgebra

import org.junit.runner.RunWith
import org.scalatest.junit.JUnitRunner
import org.scalatest.FunSuite

import java.awt.image.BufferedImage

import TestFixtures._

@RunWith(classOf[JUnitRunner])
class TestDraw extends FunSuite with BufferedImageEquality {
  test("simple") {
    val s = simpleLocation
    val i = new BufferedImage(500, 500, BufferedImage.TYPE_INT_RGB)
    Draw(i.createGraphics())(s)
    val j = new BufferedImage(500, 500, BufferedImage.TYPE_INT_RGB)
    val g = j.createGraphics()
    g.translate(70, 30)
    g.drawRect(0, 0, 80, 120)
    assertEquals(i, j)
  }
  test("complex") {
    val s = complexGroup
    val i = new BufferedImage(500, 500, BufferedImage.TYPE_INT_RGB)
    Draw(i.createGraphics())(s)
    val j = new BufferedImage(500, 500, BufferedImage.TYPE_INT_RGB)
    val g = j.createGraphics()
    paintComplexGroup(g)
        assertEquals(i, j)
  }
}

The test case is shown above. I get a “0 did not equal 255” from the result of the unit test.

  • 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-05-26T03:19:35+00:00Added an answer on May 26, 2026 at 3:19 am

    If you look at what translate does, the Javadoc says

    “Translates the origin of the Graphics2D context to the point (x, y)
    in the current coordinate system.”

    So

      g.translate(0,0)
    

    does nothing. Try

      g.translate(-x, -y)
    

    Although, if it were me, I wouldn’t mess with the Graphics object’s origin. I’d modify the drawRect and drawArc statements to take a location, and pass the location co-ordiates as an argument to the method.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having some serious issues using Zend_Lucene and foreign characters like åäö. These issues
I'm having some serious troubles getting communication from one thread to another working between
I'm having some serious trouble understanding the view matrix in XNA. I've come pretty
I am having some serious trouble creating a WPF TreeView with an Object databinding.
I am having some serious issues trying to tweak my layout in a table.
I just started learning C++ (coming from Java ) and am having some serious
I've some pocket pc app and i'm having a serious problem with it described
I'm having some serious performance issues with a multi-million row table that I feel
I'm having some serious issues with a WinForm application that I'm working on. Currently,
I am having some serious pathing issues with a website that I am creating.

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.