Skip to content

Commit

Permalink
Code coverage (#264)
Browse files Browse the repository at this point in the history
Many fixes and QoL improvements
Code coverage now ~22%
  • Loading branch information
i-make-robots authored Jan 19, 2024
2 parents 651e894 + 28732d8 commit 822287c
Show file tree
Hide file tree
Showing 81 changed files with 1,092 additions and 847 deletions.
2 changes: 1 addition & 1 deletion .github/badges/branches.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion .github/badges/jacoco.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.marginallyclever</groupId>
<artifactId>RobotOverlord</artifactId>
<version>2.109.1</version>
<version>2.109.2</version>
<name>Robot Overlord</name>
<description>A friendly 3D user interface for controlling robots.</description>
<url>https://www.marginallyclever.com/</url>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.marginallyclever.communications.session.SessionLayer;
import com.marginallyclever.communications.session.SessionLayerEvent;
import com.marginallyclever.communications.session.SessionLayerManager;
import com.marginallyclever.convenience.log.Log;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -109,7 +108,6 @@ private void notifyListeners(ActionEvent e) {
// TEST

public static void main(String[] args) {
Log.start();
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch(Exception ignored) {}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.marginallyclever.communications.application;

import com.marginallyclever.convenience.log.Log;

import javax.swing.*;
import javax.swing.border.EtchedBorder;
import javax.swing.event.ListSelectionListener;
Expand Down Expand Up @@ -144,7 +142,6 @@ private void jumpToEnd() {
// TEST

public static void main(String[] args) {
Log.start();
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch(Exception ignored) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@
import com.marginallyclever.communications.session.SessionLayer;
import com.marginallyclever.communications.session.SessionLayerEvent;
import com.marginallyclever.communications.session.SessionLayerListener;
import com.marginallyclever.convenience.log.Log;
import com.marginallyclever.ro3.apps.App;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.Serial;
import java.util.ArrayList;

/**
Expand Down Expand Up @@ -118,11 +116,10 @@ public void removeNetworkSessionListener(SessionLayerListener a) {
// TEST

public static void main(String[] args) {
Log.start();
JFrame frame = new JFrame(TextInterfaceToSessionLayer.class.getName());
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch(Exception e) {}
} catch(Exception ignore) {}
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setPreferredSize(new Dimension(600, 400));
frame.add(new TextInterfaceToSessionLayer());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.marginallyclever.communications.application;

import com.marginallyclever.convenience.log.Log;

import javax.swing.*;
import javax.swing.border.EtchedBorder;
import java.awt.*;
Expand Down Expand Up @@ -69,8 +67,6 @@ public void setEnabled(boolean state) {
}

public static void main(String[] args) {
Log.start();

try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch(Exception ignored) {}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.marginallyclever.communications.transport.ssh;

import com.jcraft.jsch.*;
import com.marginallyclever.convenience.log.Log;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -22,7 +21,6 @@
public class SSHShell {
private static final Logger logger = LoggerFactory.getLogger(SSHShell.class);
public static void main(String[] arg) {
Log.start();
try {
JSch jsch = new JSch();

Expand Down
201 changes: 108 additions & 93 deletions src/main/java/com/marginallyclever/convenience/ColorRGB.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,100 +7,115 @@
* RGB color class. Values should be 0...255.
*/
public class ColorRGB {
public int red = 0;
public int green = 0;
public int blue = 0;

public ColorRGB(int r, int g, int b) {
red = r;
green = g;
blue = b;
}

public ColorRGB(ColorRGB x) {
set(x);
}

public ColorRGB(int pixel) {
int r = ((pixel >> 16) & 0xff);
int g = ((pixel >> 8) & 0xff);
int b = ((pixel) & 0xff);
set(r, g, b);
}

public ColorRGB(Color c) {
red = c.getRed();
green = c.getGreen();
blue = c.getBlue();
}

public int toInt() {
return ((red & 0xff) << 16) | ((green & 0xff) << 8) | (blue & 0xff);
}

public ColorRGB set(ColorRGB x) {
red = x.red;
green = x.green;
blue = x.blue;
return this;
}

public void set(int r, int g, int b) {
red = r;
green = g;
blue = b;
}

public ColorRGB sub(ColorRGB x) {
red -= x.red;
green -= x.green;
blue -= x.blue;
return this;
}

public ColorRGB add(ColorRGB x) {
red += x.red;
green += x.green;
blue += x.blue;
return this;
}

public ColorRGB mul(double f) {
red *= f;
green *= f;
blue *= f;
return this;
}

public float diff(ColorRGB o) {
int rDiff = o.red - this.red;
int gDiff = o.green - this.green;
int bDiff = o.blue - this.blue;
int distanceSquared = rDiff * rDiff + gDiff * gDiff + bDiff * bDiff;
return (float) Math.sqrt(distanceSquared);
}

@Override
public String toString() {
return "(" + red + "," + green + "," + blue + ")";
}

public int getRed() { return red; }
public int getGreen() { return green; }
public int getBlue() { return blue; }

public static ColorRGB parse(String arg0) throws NumberFormatException, InvalidParameterException {
if(arg0==null) throw new InvalidParameterException("arg0 is null");
if(arg0.startsWith("#")) arg0 = arg0.substring(1);
int size = arg0.length();
if(size>8 || size<6) throw new InvalidParameterException("arg0 must be 6 or 8 characters long in hex format.");
if(size>6) arg0.substring(0,6);

int r = (int) Long.parseLong(arg0, 16);
return new ColorRGB(r);
}
public int red;
public int green;
public int blue;

public ColorRGB() {
this(0,0,0);
}

public ColorRGB(int r, int g, int b) {
red = r;
green = g;
blue = b;
}

public ColorRGB(ColorRGB x) {
set(x);
}

public ColorRGB(int pixel) {
set(pixel);
}

public void set(int hex) {
red = ((hex >> 16) & 0xff);
green = ((hex >> 8) & 0xff);
blue = ((hex) & 0xff);
}

public ColorRGB(Color c) {
red = c.getRed();
green = c.getGreen();
blue = c.getBlue();
}

public int toInt() {
return ((red & 0xff) << 16) | ((green & 0xff) << 8) | (blue & 0xff);
}

public void set(ColorRGB x) {
red = x.red;
green = x.green;
blue = x.blue;
}

public ColorRGB set(int r, int g, int b) {
red = r;
green = g;
blue = b;
return this;
}

public ColorRGB sub(ColorRGB x) {
red -= x.red;
green -= x.green;
blue -= x.blue;
return this;
}

public ColorRGB add(ColorRGB x) {
red += x.red;
green += x.green;
blue += x.blue;
return this;
}

public ColorRGB mul(double f) {
red = (int) (red * f);
green = (int) (green * f);
blue = (int) (blue * f);
return this;
}

public float diff(ColorRGB o) {
int rDiff = o.red - this.red;
int gDiff = o.green - this.green;
int bDiff = o.blue - this.blue;
int distanceSquared = rDiff * rDiff + gDiff * gDiff + bDiff * bDiff;
return (float) Math.sqrt(distanceSquared);
}

@Override
public String toString() {
return "#" + Integer.toString(toInt(),16);
}

public int getRed() {
return red;
}

public int getGreen() {
return green;
}

public int getBlue() {
return blue;
}

public void parse(String arg0) throws NumberFormatException, InvalidParameterException {
if( arg0 == null ) throw new InvalidParameterException("arg0 is null");
if( arg0.startsWith("#") ) arg0 = arg0.substring(1);
if( arg0.startsWith("0x") ) arg0 = arg0.substring(2);
int size = arg0.length();
if( size > 8 || size < 6 ) {
throw new InvalidParameterException("arg0 must be 6 or 8 characters long in hex format.");
}
set(Integer.parseInt(arg0, 16));
}

public Color toColor() {
return new Color(red,green,blue);
return new Color(red, green, blue);
}
}
Loading

0 comments on commit 822287c

Please sign in to comment.